class 1 grandis : warrior_ag_casting_enchant_1of4
{
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;
		always_list::SetInfo(0,target);
		always_list::SetInfo(1,target);
		always_list::SetInfo(2,target);
		always_list::SetInfo(6,target);
		if( myself::HaveMemo(target,335) && myself::OwnItemCount(target,3735) && myself::OwnItemCount(target,3777) < 100 )
		{
			random1_list::SetInfo(3,target);
		}
		target = last_attacker;
		if( myself::HaveMemo(target,335) && myself::OwnItemCount(target,3746) && myself::OwnItemCount(target,3788) < 1 )
		{
			random1_list::SetInfo(4,target);
		}
		target = last_attacker;
		if( myself::HaveMemo(target,426) == 1 )
		{
			random1_list::SetInfo(5,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(5,target);
				}
			}
		}
		while( gg::IsNull(code_info = always_list::Next()) == 0 )
		{
			switch(code_info.code)
			{
				case 0:
				{
					myself::SetCurrentQuestID(219);
					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,219) && myself::OwnItemCount(c1,3190) && myself::OwnItemCount(c1,3192) && myself::OwnItemCount(c1,3198) == 0 && myself::OwnItemCount(c1,3193) && myself::OwnItemCount(c1,3194) < 10 )
						{
							if( myself::OwnItemCount(c1,3194) == 9 )
							{
								myself::GiveItem1(c1,3194,1);
								myself::SoundEffect(c1,"Itemsound.quest_middle");
							}
							else
							{
								myself::GiveItem1(c1,3194,1);
								myself::SoundEffect(c1,"Itemsound.quest_itemget");
							}
						}
					}
					break;
				}
				case 1:
				{
					myself::SetCurrentQuestID(222);
					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,222) && myself::OwnItemCount(c1,2778) > 0 && myself::OwnItemCount(c1,2781) < 3 && myself::GetMemoState(c1,222) == 2 )
						{
							i0 = myself::GetMemoStateEx(c1,222,1);
							myself::SetMemoStateEx(c1,222,1,( i0 + 1 ));
							c1.quest_last_reward_time = myself::GetCurrentTick();
							myself::GiveItem1(c1,2781,1);
							if( myself::OwnItemCount(c1,2781) >= 3 )
							{
								myself::SoundEffect(c1,"ItemSound.quest_middle");
								if( i0 >= 5 )
								{
									myself::SetFlagJournal(c1,222,5);
									myself::SetMemoStateEx(c1,222,1,0);
								}
							}
							else
							{
								myself::SoundEffect(c1,"ItemSound.quest_itemget");
							}
						}
					}
					break;
				}
				case 2:
				{
					myself::SetCurrentQuestID(214);
					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,214) && myself::OwnItemCount(c1,2677) == 1 && myself::OwnItemCount(c1,2691) == 1 && myself::OwnItemCount(c1,2705) == 1 && myself::OwnItemCount(c1,2708) == 0 )
						{
							if( gg::Rand(100) < 30 )
							{
								c1.quest_last_reward_time = myself::GetCurrentTick();
								myself::GiveItem1(c1,2708,1);
								myself::SoundEffect(c1,"ItemSound.quest_middle");
							}
						}
					}
					break;
				}
				case 6:
				{
					myself::SetCurrentQuestID(66);
					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,66) == 1 && myself::GetMemoState(c1,66) == 11 )
						{
							myself::GiveItem1(c1,9779,1);
							myself::SetMemoState(c1,66,12);
							myself::SetFlagJournal(c1,66,12);
							myself::SoundEffect(c1,"Itemsound.quest_itemget");
						}
						if( myself::HaveMemo(c1,66) == 1 && myself::GetMemoState(c1,66) == 12 && myself::OwnItemCount(c1,9778) != 10 )
						{
							if( gg::Rand(2) == 1 )
							{
								if( myself::OwnItemCount(c1,9778) < 9 )
								{
									myself::GiveItem1(c1,9778,1);
									myself::SoundEffect(c1,"Itemsound.quest_itemget");
								}
								else
								{
									myself::GiveItem1(c1,9778,1);
									myself::SetMemoState(c1,66,13);
									myself::SetFlagJournal(c1,66,13);
									myself::DeleteItem1(c1,9779,1);
									myself::SoundEffect(c1,"Itemsound.quest_middle");
								}
							}
						}
					}
					break;
				}
			}
		}
		code_info = random1_list::RandomSelectOne();
		if( gg::IsNull(code_info) == 0 )
		{
			switch(code_info.code)
			{
				case 3:
				{
					myself::SetCurrentQuestID(335);
					target = code_info::RandomSelectOne();
					if( gg::IsNull(target) == 0 && myself::DistFromMe(target) <= 1500 )
					{
						myself::GiveItem1(target,3777,2);
						if( myself::OwnItemCount(target,3777) >= 100 )
						{
							myself::SoundEffect(target,"ItemSound.quest_middle");
						}
						else
						{
							myself::SoundEffect(target,"ItemSound.quest_itemget");
						}
					}
					break;
				}
				case 4:
				{
					myself::SetCurrentQuestID(335);
					target = code_info::RandomSelectOne();
					if( gg::IsNull(target) == 0 && myself::DistFromMe(target) <= 1500 )
					{
						if( gg::Rand(10) == 0 )
						{
							myself::CreateOnePrivate(1027160,"grandis_chief_gok_magok",0,1);
						}
					}
					break;
				}
				case 5:
				{
					myself::SetCurrentQuestID(426);
					target = code_info::RandomSelectOne();
					if( gg::IsNull(target) == 0 && myself::DistFromMe(target) <= 1500 )
					{
						if( gg::Rand(100) < 39 )
						{
							myself::GiveItem1(target,7586,1);
							myself::SoundEffect(target,"ItemSound.quest_itemget");
						}
					}
					break;
				}
			}
		}
		super;
	}

}
