class 1 wyrm : warrior_aggressive_casting_ddmagic
{
handler:
	EventHandler MY_DYING(always_list,c1,code_info,i0,i9,last_attacker,lparty,member,random1_list,target)
	{
		always_list = gg::AllocCodeInfoList();
		random1_list = gg::AllocCodeInfoList();
		target = last_attacker;
		if( myself::HaveMemo(target,331) )
		{
			random1_list::SetInfo(0,target);
		}
		always_list::SetInfo(1,target);
		always_list::SetInfo(2,target);
		always_list::SetInfo(3,target);
		always_list::SetInfo(5,target);
		if( myself::HaveMemo(target,426) == 1 )
		{
			random1_list::SetInfo(4,target);
		}
		if( gg::IsNull(lparty) == 0 )
		{
			for(i9 = 0; i9 < lparty.member_count; i9 = ( i9 + 1 ))
			{
				target = myself::GetMemberOfParty(lparty,i9);
				if( myself::HaveMemo(target,426) == 1 )
				{
					random1_list::SetInfo(4,target);
				}
			}
		}
		while( gg::IsNull(code_info = always_list::Next()) == 0 )
		{
			switch(code_info.code)
			{
				case 1:
				{
					myself::SetCurrentQuestID(230);
					target = code_info::RandomSelectOne();
					if( gg::IsNull(target) == 0 && myself::DistFromMe(target) <= 1500 )
					{
						c1 = myself::GetLastAttacker();
						if( c1.master )
						{
							c1 = c1.master;
						}
						if( myself::HaveMemo(c1,230) && myself::OwnItemCount(c1,3352) == 0 && myself::OwnItemCount(c1,3351) && myself::OwnItemCount(c1,3346) < 30 )
						{
							if( gg::Rand(2) == 1 )
							{
								if( myself::OwnItemCount(c1,3346) == 29 )
								{
									myself::GiveItem1(c1,3346,1);
									myself::SoundEffect(c1,"Itemsound.quest_middle");
								}
								else
								{
									myself::GiveItem1(c1,3346,1);
									myself::SoundEffect(c1,"Itemsound.quest_itemget");
								}
							}
						}
					}
					break;
				}
				case 2:
				{
					myself::SetCurrentQuestID(218);
					target = code_info::RandomSelectOne();
					if( gg::IsNull(target) == 0 && myself::DistFromMe(target) <= 1500 )
					{
						c1 = myself::GetLastAttacker();
						if( c1.master )
						{
							c1 = c1.master;
						}
						if( myself::HaveMemo(c1,218) && myself::OwnItemCount(c1,3144) == 1 && myself::OwnItemCount(c1,3149) == 1 && myself::OwnItemCount(c1,3163) < 20 )
						{
							if( gg::Rand(100) < 50 )
							{
								c1.quest_last_reward_time = myself::GetCurrentTick();
								myself::GiveItem1(c1,3163,1);
								if( myself::OwnItemCount(c1,3163) >= 19 )
								{
									myself::SoundEffect(c1,"ItemSound.quest_middle");
									if( myself::OwnItemCount(c1,3161) >= 10 && myself::OwnItemCount(c1,3162) >= 20 )
									{
										myself::SetFlagJournal(c1,218,5);
									}
								}
								else
								{
									myself::SoundEffect(c1,"ItemSound.quest_itemget");
								}
							}
						}
					}
					break;
				}
				case 3:
				{
					myself::SetCurrentQuestID(228);
					target = code_info::RandomSelectOne();
					if( gg::IsNull(target) == 0 && myself::DistFromMe(target) <= 1500 )
					{
						c1 = myself::GetLastAttacker();
						if( c1.master )
						{
							c1 = c1.master;
						}
						if( myself::HaveMemo(c1,228) && myself::OwnItemCount(c1,2847) == 1 && myself::OwnItemCount(c1,2861) == 1 && myself::OwnItemCount(c1,2851) < 10 )
						{
							if( gg::Rand(100) < 50 )
							{
								c1.quest_last_reward_time = myself::GetCurrentTick();
								myself::GiveItem1(c1,2851,1);
								if( myself::OwnItemCount(c1,2851) >= 10 )
								{
									myself::SoundEffect(c1,"ItemSound.quest_middle");
								}
								else
								{
									myself::SoundEffect(c1,"ItemSound.quest_itemget");
								}
							}
						}
					}
					break;
				}
				case 5:
				{
					myself::SetCurrentQuestID(65);
					target = code_info::RandomSelectOne();
					if( gg::IsNull(target) == 0 && myself::DistFromMe(target) <= 1500 )
					{
						c1 = myself::GetLastAttacker();
						if( c1.master )
						{
							c1 = c1.master;
						}
						if( myself::HaveMemo(c1,65) == 1 && myself::GetMemoState(c1,65) == 15 && myself::OwnItemCount(c1,9804) != 10 )
						{
							if( gg::Rand(2) == 1 )
							{
								if( myself::OwnItemCount(c1,9804) < 9 )
								{
									myself::GiveItem1(c1,9804,1);
									myself::SoundEffect(c1,"Itemsound.quest_itemget");
								}
								else
								{
									myself::GiveItem1(c1,9804,1);
									myself::SetMemoState(c1,65,16);
									myself::SetFlagJournal(c1,65,16);
									myself::SoundEffect(c1,"Itemsound.quest_middle");
								}
							}
						}
					}
					break;
				}
			}
		}
		code_info = random1_list::RandomSelectOne();
		if( gg::IsNull(code_info) == 0 )
		{
			switch(code_info.code)
			{
				case 0:
				{
					myself::SetCurrentQuestID(331);
					target = code_info::RandomSelectOne();
					if( gg::IsNull(target) == 0 && myself::DistFromMe(target) <= 1500 )
					{
						i0 = gg::Rand(10);
						if( i0 < 5 )
						{
							myself::GiveItem1(target,1454,1);
							myself::SoundEffect(target,"ItemSound.quest_itemget");
						}
					}
					break;
				}
				case 4:
				{
					myself::SetCurrentQuestID(426);
					target = code_info::RandomSelectOne();
					if( gg::IsNull(target) == 0 && myself::DistFromMe(target) <= 1500 )
					{
						if( gg::Rand(100) < 28 )
						{
							myself::GiveItem1(target,7586,1);
							myself::SoundEffect(target,"ItemSound.quest_itemget");
						}
					}
					break;
				}
			}
		}
		super;
	}

}
