class 1 ai_boss03_orfen : party_leader_aggressive
{
parameter:
	int	b03_x1 = 0;
	int	b03_y1 = 0;
	int	b03_z1 = 0;
	int	b03_x2 = 0;
	int	b03_y2 = 0;
	int	b03_z2 = 0;
	int	b03_x3 = 0;
	int	b03_y3 = 0;
	int	b03_z3 = 0;
	int	b03_x4 = 0;
	int	b03_y4 = 0;
	int	b03_z4 = 0;

handler:
	EventHandler CREATED(i6)
	{
		myself::EffectMusic(myself.sm,7000,"BS01_A");
		myself.sm.flag = 0;
		myself.i_ai0 = 0;
		myself::AddTimerEx(3001,10000);
		super;
	}

	EventHandler TIMER_FIRED_EX(timer_id,i6)
	{
		if( timer_id == 3001 )
		{
			if( myself.i_ai0 == 1 && myself.sm.hp > ( myself.sm.max_hp * 0.950000 ) )
			{
				i6 = gg::Rand(100);
				if( i6 < 33 )
				{
					myself::SetTeleportPosOnLost(b03_x2,b03_y2,b03_z2);
					myself::InstantTeleport(myself.sm,b03_x2,b03_y2,b03_z2);
				}
				else if( i6 < 66 )
				{
					myself::SetTeleportPosOnLost(b03_x3,b03_y3,b03_z3);
					myself::InstantTeleport(myself.sm,b03_x3,b03_y3,b03_z3);
				}
				else
				{
					myself::SetTeleportPosOnLost(b03_x4,b03_y4,b03_z4);
					myself::InstantTeleport(myself.sm,b03_x4,b03_y4,b03_z4);
				}
				myself.i_ai0 = 0;
				myself.sm.flag = ( myself.sm.flag + 1 );
				myself::RemoveAllAttackDesire();
			}
			else if( myself.i_ai0 == 1 && myself::InMyTerritory(myself.sm) == 0 )
			{
				myself::SetTeleportPosOnLost(b03_x1,b03_y1,b03_z1);
				myself::InstantTeleport(myself.sm,b03_x1,b03_y1,b03_z1);
			}
			myself::AddTimerEx(3001,10000);
		}
		super;
	}

	EventHandler OUT_OF_TERRITORY(i6)
	{
		if( myself.i_ai0 > 0.500000 )
		{
			myself::SetTeleportPosOnLost(b03_x1,b03_y1,b03_z1);
			myself::InstantTeleport(myself.sm,b03_x1,b03_y1,b03_z1);
		}
		else if( myself.i_ai0 < 0.500000 )
		{
			i6 = gg::Rand(100);
			if( i6 < 33 )
			{
				myself::SetTeleportPosOnLost(b03_x2,b03_y2,b03_z2);
				myself::InstantTeleport(myself.sm,b03_x2,b03_y2,b03_z2);
			}
			else if( i6 < 66 )
			{
				myself::SetTeleportPosOnLost(b03_x3,b03_y3,b03_z3);
				myself::InstantTeleport(myself.sm,b03_x3,b03_y3,b03_z3);
			}
			else
			{
				myself::SetTeleportPosOnLost(b03_x4,b03_y4,b03_z4);
				myself::InstantTeleport(myself.sm,b03_x4,b03_y4,b03_z4);
			}
		}
		myself::RemoveAllAttackDesire();
		myself.sm.flag = ( myself.sm.flag + 1 );
	}

	EventHandler ATTACKED(attacker,damage,skill_name_id,i0)
	{
		if( attacker.yongma_type == 1 && myself::GetAbnormalLevel(attacker,myself::Skill_GetAbnormalType(1090049)) <= 0 )
		{
			if( myself::Skill_GetConsumeMP(1090049) < myself.sm.mp && myself::Skill_GetConsumeHP(1090049) < myself.sm.hp && myself::Skill_InReuseDelay(1090049) == 0 )
			{
				myself::AddUseSkillDesire(attacker,1090049,0,1,1000000);
			}
		}
		if( myself.i_ai0 == 0 && ( myself.sm.max_hp * 0.500000 ) > myself.sm.hp )
		{
			myself::SetTeleportPosOnLost(b03_x1,b03_y1,b03_z1);
			myself::InstantTeleport(myself.sm,b03_x1,b03_y1,b03_z1);
			myself.i_ai0 = 1;
			myself::RemoveAllAttackDesire();
			myself.sm.flag = ( myself.sm.flag + 1 );
		}
		if( attacker.is_pc != 0 || myself::IsInCategory(11,attacker.npc_class_id) )
		{
			if( myself::DistFromMe(attacker) > 300 && gg::Rand(100) < 10 && myself::DistFromMe(attacker) < 1000 )
			{
				i0 = gg::Rand(100);
				if( i0 < 33 )
				{
					myself::Say(myself::MakeFString(1000028,attacker.name,"","","",""));
				}
				else if( i0 < 66 )
				{
					myself::Say(myself::MakeFString(1000029,attacker.name,"","","",""));
				}
				else
				{
					myself::Say(myself::MakeFString(1000030,attacker.name,"","","",""));
				}
				myself::InstantTeleport(attacker,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z));
				if( myself::Skill_GetConsumeMP(1040129) < myself.sm.mp && myself::Skill_GetConsumeHP(1040129) < myself.sm.hp && myself::Skill_InReuseDelay(1040129) == 0 )
				{
					myself::AddUseSkillDesire(attacker,1040129,0,1,1000000);
				}
			}
			else if( gg::Rand(100) < 20 )
			{
				if( myself::Skill_GetConsumeMP(1040385) < myself.sm.mp && myself::Skill_GetConsumeHP(1040385) < myself.sm.hp && myself::Skill_InReuseDelay(1040385) == 0 )
				{
					myself::AddUseSkillDesire(myself.sm,1040385,0,1,1000000);
				}
			}
		}
		if( attacker.is_pc != 0 || myself::IsInCategory(11,attacker.npc_class_id) )
		{
			myself::AddAttackDesire(attacker,1,( ( ( damage / myself.sm.max_hp ) / 0.050000 ) * 10000 ));
		}
	}

	EventHandler SEE_SPELL(speller,skill_name_id,i0)
	{
		if( myself.sm.alive != 0 )
		{
			if( myself::Skill_GetEffectPoint(skill_name_id) > 0 && gg::Rand(100) < 20 && myself::DistFromMe(speller) < 1000 )
			{
				i0 = gg::Rand(100);
				if( i0 < 25 )
				{
					myself::Say(myself::MakeFString(1000028,speller.name,"","","",""));
				}
				else if( i0 < 50 )
				{
					myself::Say(myself::MakeFString(1000029,speller.name,"","","",""));
				}
				else if( i0 < 75 )
				{
					myself::Say(myself::MakeFString(1000030,speller.name,"","","",""));
				}
				else
				{
					myself::Say(myself::MakeFString(1000031,speller.name,"","","",""));
				}
				myself::InstantTeleport(speller,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z));
				if( myself::Skill_GetConsumeMP(1040129) < myself.sm.mp && myself::Skill_GetConsumeHP(1040129) < myself.sm.hp && myself::Skill_InReuseDelay(1040129) == 0 )
				{
					myself::AddUseSkillDesire(speller,1040129,0,1,1000000);
				}
			}
			super;
		}
	}

	EventHandler PARTY_ATTACKED(attacker,private,damage)
	{
		if( private != myself.sm )
		{
			if( attacker.is_pc != 0 || myself::IsInCategory(11,attacker.npc_class_id) )
			{
				myself::AddAttackDesire(attacker,1,( ( ( ( ( damage / myself.sm.max_hp ) / 0.050000 ) * damage ) * private.weight_point ) * 1000 ));
			}
		}
	}

	EventHandler CLAN_ATTACKED(attacker,damage)
	{
		if( attacker.is_pc != 0 || myself::IsInCategory(11,attacker.npc_class_id) )
		{
			myself::AddAttackDesire(attacker,1,( ( ( damage / myself.sm.max_hp ) / 0.050000 ) * 3000 ));
		}
	}

	EventHandler MY_DYING()
	{
		myself::EffectMusic(myself.sm,7000,"BS02_D");
	}

}
