class 1 quest_0503_imperial_gravekeeper : default_npc
{
parameter:

handler:
	EventHandler NO_DESIRE()
	{
		myself::AddMoveAroundDesire(5,5);
	}

	EventHandler CREATED()
	{
		myself.i_ai0 = 1;
		myself.i_ai1 = 50;
		myself.i_ai2 = 80;
		myself.sm.weight_point = 10;
	}

	EventHandler ATTACKED(attacker,damage,skill_name_id)
	{
		if( myself.sm.in_peacezone != 1 )
		{
			if( myself::FloatToInt(( ( myself.sm.hp / myself.sm.max_hp ) * 100 )) <= myself.i_ai1 )
			{
				if( myself.i_ai0 == 1 || myself.i_ai0 == 3 )
				{
					myself::InstantTeleportInMyTerritory(179520,6464,-2706,200);
				}
				else
				{
					myself::InstantTeleportInMyTerritory(171104,6496,-2706,200);
				}
			}
			if( myself::Skill_GetConsumeMP(1044481) < myself.sm.mp && myself::Skill_GetConsumeHP(1044481) < myself.sm.hp && myself::Skill_InReuseDelay(1044481) == 0 )
			{
				myself::AddUseSkillDesire(myself.sm,1044481,1,1,1000000);
			}
			if( myself.i_ai1 == 50 )
			{
				myself.i_ai1 = 30;
			}
			else if( myself.i_ai1 == 30 )
			{
				myself.i_ai1 = -1;
			}
		}
		if( myself::FloatToInt(( ( myself.sm.hp / myself.sm.max_hp ) * 100 )) <= myself.i_ai2 )
		{
			if( myself.i_ai2 == 80 )
			{
				myself.i_ai2 = 40;
			}
			else if( myself.i_ai2 == 40 )
			{
				myself.i_ai2 = 20;
			}
			else
			{
				myself.i_ai2 = -1;
			}
			myself::CreateOnePrivate(1027180,"imperial_slave",0,1);
			myself::CreateOnePrivate(1027180,"imperial_slave",0,1);
			myself::CreateOnePrivate(1027180,"imperial_slave",0,1);
			myself::CreateOnePrivate(1027180,"imperial_slave",0,1);
		}
		if( myself::FloatToInt(( ( myself.sm.hp / myself.sm.max_hp ) * 100 )) > 50 )
		{
			myself.i_ai1 = 50;
		}
		else if( myself::FloatToInt(( ( myself.sm.hp / myself.sm.max_hp ) * 100 )) > 30 )
		{
			myself.i_ai1 = 30;
		}
		if( myself::FloatToInt(( ( myself.sm.hp / myself.sm.max_hp ) * 100 )) > 80 )
		{
			myself.i_ai2 = 80;
		}
		else if( myself::FloatToInt(( ( myself.sm.hp / myself.sm.max_hp ) * 100 )) > 40 )
		{
			myself.i_ai2 = 40;
		}
		else if( myself::FloatToInt(( ( myself.sm.hp / myself.sm.max_hp ) * 100 )) > 20 )
		{
			myself.i_ai2 = 20;
		}
		if( attacker.is_pc != 0 || myself::IsInCategory(11,attacker.npc_class_id) )
		{
			myself::AddAttackDesire(attacker,1,( ( ( damage / myself.sm.max_hp ) / 0.050000 ) * 100 ));
		}
	}

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

	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 ) * 50 ));
		}
	}

	EventHandler OUT_OF_TERRITORY()
	{
		myself::RemoveAllAttackDesire();
	}

}
