class 1 mirror : warrior_pa_casting_3skill_magical
{
handler:
	EventHandler MY_DYING(always_list,code_info,i1,i2,i3,i9,last_attacker,lparty,member,random1_list,target)
	{
		always_list = gg::AllocCodeInfoList();
		target = myself::GetLastAttacker();
		if( target.master )
		{
			target = target.master;
		}
		if( myself::HaveMemo(target,350) == 1 )
		{
			always_list::SetInfo(0,target);
		}
		if( myself::HaveMemo(target,335) == 1 && myself::OwnItemCount(target,3762) && myself::OwnItemCount(target,3804) < 40 )
		{
			always_list::SetInfo(1,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 )
				{
					always_list::SetInfo(2,target);
				}
				if( myself::HaveMemo(target,136) == 1 && myself::GetMemoState(target,136) == 3 )
				{
					always_list::SetInfo(3,target);
				}
			}
		}
		else if( myself::HaveMemo(target,426) == 1 )
		{
			always_list::SetInfo(2,target);
		}
		if( myself::HaveMemo(target,136) == 1 && myself::GetMemoState(target,136) == 3 )
		{
			always_list::SetInfo(3,target);
		}
		while( gg::IsNull(code_info = always_list::Next()) == 0 )
		{
			switch(code_info.code)
			{
				case 0:
				{
					myself::SetCurrentQuestID(350);
					target = code_info::RandomSelectOne();
					if( gg::IsNull(target) == 0 && myself::DistFromMe(target) <= 1500 )
					{
						if( myself::HaveMemo(target,350) == 1 && target == myself.c_quest0 && myself.i_quest0 == 2 )
						{
							i1 = ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( myself::OwnItemCount(target,4651) + myself::OwnItemCount(target,4652) ) + myself::OwnItemCount(target,4653) ) + myself::OwnItemCount(target,4654) ) + myself::OwnItemCount(target,4655) ) + myself::OwnItemCount(target,4656) ) + myself::OwnItemCount(target,4657) ) + myself::OwnItemCount(target,4658) ) + myself::OwnItemCount(target,4659) ) + myself::OwnItemCount(target,4660) ) + myself::OwnItemCount(target,4661) ) + myself::OwnItemCount(target,5579) ) + myself::OwnItemCount(target,5582) ) + myself::OwnItemCount(target,5914) ) + myself::OwnItemCount(target,4629) ) + myself::OwnItemCount(target,4630) ) + myself::OwnItemCount(target,4631) ) + myself::OwnItemCount(target,4632) ) + myself::OwnItemCount(target,4633) ) + myself::OwnItemCount(target,4634) ) + myself::OwnItemCount(target,4635) ) + myself::OwnItemCount(target,4636) ) + myself::OwnItemCount(target,4637) ) + myself::OwnItemCount(target,4638) ) + myself::OwnItemCount(target,4639) ) + myself::OwnItemCount(target,5577) ) + myself::OwnItemCount(target,5580) ) + myself::OwnItemCount(target,5908) ) + myself::OwnItemCount(target,4640) ) + myself::OwnItemCount(target,4641) ) + myself::OwnItemCount(target,4642) ) + myself::OwnItemCount(target,4643) ) + myself::OwnItemCount(target,4644) ) + myself::OwnItemCount(target,4645) ) + myself::OwnItemCount(target,4646) ) + myself::OwnItemCount(target,4647) ) + myself::OwnItemCount(target,4648) ) + myself::OwnItemCount(target,4649) ) + myself::OwnItemCount(target,4650) ) + myself::OwnItemCount(target,5578) ) + myself::OwnItemCount(target,5581) ) + myself::OwnItemCount(target,5911) );
							if( i1 == 1 )
							{
								if( gg::Rand(1000) < 150 && ( myself::GetCurrentTick() - target.quest_last_reward_time ) > 1 )
								{
									i2 = 0;
									i3 = 0;
									if( myself::OwnItemCount(target,4651) == 1 )
									{
										i2 = 4651;
										i3 = 4652;
									}
									else if( myself::OwnItemCount(target,4652) == 1 )
									{
										i2 = 4652;
										i3 = 4653;
									}
									else if( myself::OwnItemCount(target,4653) == 1 )
									{
										i2 = 4653;
										i3 = 4654;
									}
									else if( myself::OwnItemCount(target,4654) == 1 )
									{
										i2 = 4654;
										i3 = 4655;
									}
									else if( myself::OwnItemCount(target,4629) == 1 )
									{
										i2 = 4629;
										i3 = 4630;
									}
									else if( myself::OwnItemCount(target,4630) == 1 )
									{
										i2 = 4630;
										i3 = 4631;
									}
									else if( myself::OwnItemCount(target,4631) == 1 )
									{
										i2 = 4631;
										i3 = 4632;
									}
									else if( myself::OwnItemCount(target,4632) == 1 )
									{
										i2 = 4632;
										i3 = 4633;
									}
									else if( myself::OwnItemCount(target,4640) == 1 )
									{
										i2 = 4640;
										i3 = 4641;
									}
									else if( myself::OwnItemCount(target,4641) == 1 )
									{
										i2 = 4641;
										i3 = 4642;
									}
									else if( myself::OwnItemCount(target,4642) == 1 )
									{
										i2 = 4642;
										i3 = 4643;
									}
									else if( myself::OwnItemCount(target,4643) == 1 )
									{
										i2 = 4643;
										i3 = 4644;
									}
									if( i2 > 0 && i3 > 0 )
									{
										target.quest_last_reward_time = myself::GetCurrentTick();
										myself::DeleteItem1(target,i2,1);
										myself::GiveItem1(target,i3,1);
										myself::SoundEffect(target,"ItemSound.quest_itemget");
										myself::ShowSystemMessage(target,974);
									}
									else
									{
										myself::ShowSystemMessage(target,978);
									}
								}
								else
								{
									myself::ShowSystemMessage(target,975);
								}
							}
							else if( i1 > 1 )
							{
								myself::ShowSystemMessage(target,977);
							}
						}
					}
					break;
				}
				case 1:
				{
					myself::SetCurrentQuestID(335);
					target = code_info::RandomSelectOne();
					if( gg::IsNull(target) == 0 && myself::DistFromMe(target) <= 1500 )
					{
						if( gg::Rand(100) < 86 )
						{
							myself::GiveItem1(target,3804,1);
							if( myself::OwnItemCount(target,3804) >= 40 )
							{
								myself::SoundEffect(target,"ItemSound.quest_middle");
							}
							else
							{
								myself::SoundEffect(target,"ItemSound.quest_itemget");
							}
						}
						if( gg::Rand(20) == 0 )
						{
							myself::CreateOnePrivate(1027149,"gremlin_filcher",0,1);
							myself::Say(myself::MakeFString(33512,"","","","",""));
						}
					}
					break;
				}
				case 2:
				{
					myself::SetCurrentQuestID(426);
					target = code_info::RandomSelectOne();
					if( gg::IsNull(target) == 0 && myself::DistFromMe(target) <= 1500 )
					{
						if( gg::Rand(100) < 74 )
						{
							myself::GiveItem1(target,7586,1);
							myself::SoundEffect(target,"ItemSound.quest_itemget");
						}
					}
					break;
				}
				case 3:
				{
					myself::SetCurrentQuestID(136);
					target = code_info::RandomSelectOne();
					if( gg::IsNull(target) == 0 && myself::DistFromMe(target) <= 1500 )
					{
						if( gg::Rand(100) < 70 )
						{
							if( myself::OwnItemCount(target,9787) >= 34 )
							{
								myself::GiveItem1(target,9787,2);
								myself::SoundEffect(target,"ItemSound.quest_middle");
								myself::SetFlagJournal(target,136,4);
								myself::AddLog(11,target,136);
								myself::SetMemoState(target,136,4);
							}
							else
							{
								myself::GiveItem1(target,9787,2);
								myself::SoundEffect(target,"ItemSound.quest_itemget");
							}
						}
					}
					break;
				}
			}
		}
		super;
	}

	EventHandler ATTACKED(attacker,damage,skill_name_id)
	{
		myself::SetCurrentQuestID(350);
		switch(myself.i_quest0)
		{
			case 0:
			{
				myself.i_quest0 = 1;
				if( ( skill_name_id / 256 ) == ( 536576 / 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 ) == ( 536576 / 256 ) && myself.sm.hp <= ( myself.sm.max_hp * 0.500000 ) )
				{
					myself.i_quest0 = 2;
					myself.c_quest0 = attacker;
				}
				break;
			}
			case 2:
			{
				break;
			}
		}
		super;
	}

}
