class 1 timak_orc_archer : warrior_passive_use_power_shot
{
handler:
	EventHandler MY_DYING(always_list,c1,code_info,i0,i9,last_attacker,lparty,member,random1_list,target)
	{
		always_list = gg::AllocCodeInfoList();
		target = last_attacker;
		always_list::SetInfo(0,target);
		always_list::SetInfo(1,target);
		always_list::SetInfo(2,target);
		always_list::SetInfo(3,target);
		if( myself::HaveMemo(target,66) && myself::GetMemoState(target,66) == 19 )
		{
			always_list::SetInfo(4,target);
		}
		while( gg::IsNull(code_info = always_list::Next()) == 0 )
		{
			switch(code_info.code)
			{
				case 0:
				{
					myself::SetCurrentQuestID(220);
					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,220) && myself::OwnItemCount(c1,3209) && myself::OwnItemCount(c1,3217) && myself::OwnItemCount(c1,3219) < 20 )
						{
							if( gg::Rand(10) < 6 )
							{
								if( myself::OwnItemCount(c1,3219) == 19 )
								{
									myself::GiveItem1(c1,3219,1);
									myself::SoundEffect(c1,"Itemsound.quest_middle");
									if( myself::OwnItemCount(c1,3218) >= 20 )
									{
										myself::SetFlagJournal(c1,220,7);
									}
								}
								else
								{
									myself::GiveItem1(c1,3219,1);
									myself::SoundEffect(c1,"Itemsound.quest_itemget");
								}
							}
						}
					}
					break;
				}
				case 1:
				{
					myself::SetCurrentQuestID(232);
					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,232) == 1 && myself::OwnItemCount(c1,3391) == 1 && myself::OwnItemCount(c1,3394) == 1 && myself::OwnItemCount(c1,3404) == 0 )
						{
							if( myself::OwnItemCount(c1,3403) < 10 && gg::Rand(100) <= 70 )
							{
								c1.quest_last_reward_time = myself::GetCurrentTick();
								myself::GiveItem1(c1,3403,1);
								if( myself::OwnItemCount(c1,3403) >= 10 )
								{
									myself::SoundEffect(c1,"ItemSound.quest_middle");
								}
								else
								{
									myself::SoundEffect(c1,"ItemSound.quest_itemget");
								}
							}
						}
					}
					break;
				}
				case 2:
				{
					myself::SetCurrentQuestID(336);
					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,336) && myself::GetMemoState(c1,336) == 3 && gg::Rand(10) == 0 )
						{
							c1.quest_last_reward_time = myself::GetCurrentTick();
							myself::GiveItem1(c1,3472,1);
							myself::SoundEffect(c1,"ItemSound.quest_itemget");
						}
					}
					break;
				}
				case 3:
				{
					myself::SetCurrentQuestID(350);
					target = code_info::RandomSelectOne();
					if( gg::IsNull(target) == 0 && myself::DistFromMe(target) <= 1500 )
					{
						c1 = myself::GetLastAttacker();
						if( c1.master )
						{
							c1 = c1.master;
						}
						c1.quest_last_reward_time = myself::GetCurrentTick();
						if( myself::HaveMemo(c1,350) == 1 && c1 == myself.c_quest0 && myself.i_quest0 == 2 )
						{
							if( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( myself::OwnItemCount(c1,4651) + myself::OwnItemCount(c1,4652) ) + myself::OwnItemCount(c1,4653) ) + myself::OwnItemCount(c1,4654) ) + myself::OwnItemCount(c1,4655) ) + myself::OwnItemCount(c1,4656) ) + myself::OwnItemCount(c1,4657) ) + myself::OwnItemCount(c1,4658) ) + myself::OwnItemCount(c1,4659) ) + myself::OwnItemCount(c1,4660) ) + myself::OwnItemCount(c1,4661) ) + myself::OwnItemCount(c1,5579) ) + myself::OwnItemCount(c1,5582) ) + myself::OwnItemCount(c1,5914) ) + myself::OwnItemCount(c1,4629) ) + myself::OwnItemCount(c1,4630) ) + myself::OwnItemCount(c1,4631) ) + myself::OwnItemCount(c1,4632) ) + myself::OwnItemCount(c1,4633) ) + myself::OwnItemCount(c1,4634) ) + myself::OwnItemCount(c1,4635) ) + myself::OwnItemCount(c1,4636) ) + myself::OwnItemCount(c1,4637) ) + myself::OwnItemCount(c1,4638) ) + myself::OwnItemCount(c1,4639) ) + myself::OwnItemCount(c1,5577) ) + myself::OwnItemCount(c1,5580) ) + myself::OwnItemCount(c1,5908) ) + myself::OwnItemCount(c1,4640) ) + myself::OwnItemCount(c1,4641) ) + myself::OwnItemCount(c1,4642) ) + myself::OwnItemCount(c1,4643) ) + myself::OwnItemCount(c1,4644) ) + myself::OwnItemCount(c1,4645) ) + myself::OwnItemCount(c1,4646) ) + myself::OwnItemCount(c1,4647) ) + myself::OwnItemCount(c1,4648) ) + myself::OwnItemCount(c1,4649) ) + myself::OwnItemCount(c1,4650) ) + myself::OwnItemCount(c1,5578) ) + myself::OwnItemCount(c1,5581) ) + myself::OwnItemCount(c1,5911) ) == 1 )
							{
								i0 = gg::Rand(100);
								if( i0 <= 9 )
								{
									if( myself::OwnItemCount(c1,4651) == 1 )
									{
										myself::DeleteItem1(c1,4651,1);
										myself::GiveItem1(c1,4652,1);
										myself::SoundEffect(c1,"ItemSound.quest_itemget");
										myself::ShowSystemMessage(c1,974);
									}
									else if( myself::OwnItemCount(c1,4652) == 1 )
									{
										myself::DeleteItem1(c1,4652,1);
										myself::GiveItem1(c1,4653,1);
										myself::SoundEffect(c1,"ItemSound.quest_itemget");
										myself::ShowSystemMessage(c1,974);
									}
									else if( myself::OwnItemCount(c1,4629) == 1 )
									{
										myself::DeleteItem1(c1,4629,1);
										myself::GiveItem1(c1,4630,1);
										myself::SoundEffect(c1,"ItemSound.quest_itemget");
										myself::ShowSystemMessage(c1,974);
									}
									else if( myself::OwnItemCount(c1,4630) == 1 )
									{
										myself::DeleteItem1(c1,4630,1);
										myself::GiveItem1(c1,4631,1);
										myself::SoundEffect(c1,"ItemSound.quest_itemget");
										myself::ShowSystemMessage(c1,974);
									}
									else if( myself::OwnItemCount(c1,4640) == 1 )
									{
										myself::DeleteItem1(c1,4640,1);
										myself::GiveItem1(c1,4641,1);
										myself::SoundEffect(c1,"ItemSound.quest_itemget");
										myself::ShowSystemMessage(c1,974);
									}
									else if( myself::OwnItemCount(c1,4641) == 1 )
									{
										myself::DeleteItem1(c1,4641,1);
										myself::GiveItem1(c1,4642,1);
										myself::SoundEffect(c1,"ItemSound.quest_itemget");
										myself::ShowSystemMessage(c1,974);
									}
									else
									{
										myself::ShowSystemMessage(c1,978);
									}
								}
								else if( i0 >= 98 )
								{
									if( myself::OwnItemCount(c1,4651) == 1 )
									{
										myself::DeleteItem1(c1,4651,1);
										myself::ShowSystemMessage(c1,976);
									}
									else if( myself::OwnItemCount(c1,4652) == 1 )
									{
										myself::DeleteItem1(c1,4652,1);
										myself::ShowSystemMessage(c1,976);
									}
									else if( myself::OwnItemCount(c1,4629) == 1 )
									{
										myself::DeleteItem1(c1,4629,1);
										myself::ShowSystemMessage(c1,976);
									}
									else if( myself::OwnItemCount(c1,4630) == 1 )
									{
										myself::DeleteItem1(c1,4630,1);
										myself::ShowSystemMessage(c1,976);
									}
									else if( myself::OwnItemCount(c1,4640) == 1 )
									{
										myself::DeleteItem1(c1,4640,1);
										myself::ShowSystemMessage(c1,976);
									}
									else if( myself::OwnItemCount(c1,4641) == 1 )
									{
										myself::DeleteItem1(c1,4641,1);
										myself::ShowSystemMessage(c1,976);
									}
									else
									{
										myself::ShowSystemMessage(c1,978);
									}
								}
								else
								{
									myself::ShowSystemMessage(c1,975);
								}
							}
							else
							{
								myself::ShowSystemMessage(c1,977);
							}
						}
					}
					break;
				}
				case 4:
				{
					myself::SetCurrentQuestID(66);
					target = code_info::RandomSelectOne();
					if( gg::IsNull(target) == 0 && myself::DistFromMe(target) <= 1500 )
					{
						if( myself::HaveMemo(myself.c_quest0,66) == 1 && myself::GetMemoState(target,66) == 19 && myself.i_quest0 == 1 )
						{
							if( gg::Rand(100) < 10 )
							{
								myself::CreateOnePrivate(1027336,"crimson_lady",0,1);
								myself::SoundEffect(myself.c_quest0,"Itemsound.quest_before_battle");
							}
						}
					}
					break;
				}
			}
		}
		super;
	}

	EventHandler ATTACKED(attacker,damage,skill_name_id)
	{
		myself::SetCurrentQuestID(66);
		if( myself::HaveMemo(attacker,66) )
		{
			switch(myself.i_quest0)
			{
				case 0:
				{
					myself.i_quest0 = 1;
					if( attacker.master )
					{
						myself.c_quest0 = attacker.master;
					}
					else
					{
						myself.c_quest0 = attacker;
					}
					break;
				}
				case 1:
				{
					if( attacker.master )
					{
						if( myself.c_quest0 != attacker.master )
						{
							myself.i_quest0 = 2;
						}
					}
					else if( myself.c_quest0 != attacker )
					{
						myself.i_quest0 = 2;
					}
					break;
				}
				case 2:
				{
					break;
				}
			}
		}
		myself::SetCurrentQuestID(350);
		switch(myself.i_quest0)
		{
			case 0:
			{
				myself.i_quest0 = 1;
				if( ( skill_name_id / 256 ) == ( 536577 / 256 ) && myself.sm.hp <= ( myself.sm.max_hp * 0.500000 ) )
				{
					myself.i_quest0 = 2;
					myself.c_quest0 = attacker;
				}
				break;
			}
			case 1:
			{
				if( ( skill_name_id / 256 ) == ( 536577 / 256 ) && myself.sm.hp <= ( myself.sm.max_hp * 0.500000 ) )
				{
					myself.i_quest0 = 2;
					myself.c_quest0 = attacker;
				}
				break;
			}
			case 2:
			{
				break;
			}
		}
		super;
	}

}
