class 1 ai_boss06_angel : default_npc
{
parameter:
	float	Attack_DecayRatio = 6.600000;
	float	UseSkill_DecayRatio = 66000.000000;
	float	Attack_BoostValue = 500.000000;
	float	UseSkill_BoostValue = 100000.000000;

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

	EventHandler CREATED()
	{
		myself.i_ai0 = myself.sm.param1;
		myself.i_ai1 = 0;
		myself.i_ai2 = 100;
		myself.i_ai3 = 0;
		myself::AddTimerEx(2001,5000);
		myself::AddTimerEx(2002,5000);
	}

	EventHandler TIMER_FIRED_EX(timer_id,i0)
	{
		if( timer_id == 2001 )
		{
			i0 = ( 5000 + ( gg::Rand(5) * 1000 ) );
			myself::AddTimerEx(2001,i0);
			if( myself.boss.flag == 0 )
			{
				if( myself::IsNullCreature(myself.top_desire_target) == 0 )
				{
					if( myself.top_desire_target.is_pc == 0 )
					{
						myself::RemoveAttackDesire(myself.boss.id);
						myself::LookNeighbor(300);
					}
				}
				myself.i_ai1 = 0;
				if( myself::IsNullCreature(myself.c_ai2) == 0 )
				{
					if( myself.c_ai2.alive == 1 )
					{
						myself::AddAttackDesire(myself.c_ai2,1,( ( ( myself.i_ai2 / myself.sm.max_hp ) / 0.050000 ) * 100 ));
					}
				}
			}
			else
			{
				myself.i_ai1 = 0;
				if( myself.boss.flag == 1 && ( myself.i_ai0 == 1 || myself.i_ai0 == 2 ) )
				{
					myself.i_ai1 = 1;
				}
				else if( myself.boss.flag == 2 && ( myself.i_ai0 == 3 || myself.i_ai0 == 4 ) )
				{
					myself.i_ai1 = 1;
				}
				else if( myself.boss.flag == 3 && ( myself.i_ai0 == 1 || myself.i_ai0 == 3 ) )
				{
					myself.i_ai1 = 1;
				}
				else if( myself.boss.flag == 4 && ( myself.i_ai0 == 2 || myself.i_ai0 == 4 || myself.i_ai0 == 5 ) )
				{
					myself.i_ai1 = 1;
				}
				if( myself.i_ai1 == 0 )
				{
					if( myself::IsNullCreature(myself.top_desire_target) == 0 )
					{
						if( myself.top_desire_target.is_pc == 0 )
						{
							myself::RemoveAttackDesire(myself.boss.id);
						}
						if( myself::IsNullCreature(myself.c_ai2) == 0 )
						{
							myself::AddAttackDesire(myself.c_ai2,1,( ( ( 1.000000 * myself.i_ai2 ) / ( myself.sm.level + 7 ) ) * 100 ));
						}
					}
				}
				else if( myself::IsNullCreature(myself.top_desire_target) == 0 )
				{
					if( myself.top_desire_target.is_pc == 1 )
					{
						myself::RemoveAllAttackDesire();
					}
				}
				myself::AddAttackDesire(myself.boss,1,10000);
			}
		}
		if( timer_id == 2002 )
		{
			if( myself.boss.alive == 0 || myself.boss.flag == 6 )
			{
				myself::Despawn();
			}
			else
			{
				myself::AddTimerEx(2002,5000);
				if( myself.i_ai1 == 1 )
				{
					myself::AddAttackDesire(myself.boss,1,10000);
				}
				else if( myself.i_ai3 == 3 )
				{
					myself.i_ai3 = 0;
					myself::AddAttackDesire(myself.boss,1,1000);
				}
				else if( myself.p_state != 3 )
				{
					myself.i_ai3 = ( myself.i_ai3 + 1 );
					myself::LookNeighbor(300);
				}
			}
		}
	}

	EventHandler ATTACKED(attacker,damage,c0,f0)
	{
		if( attacker.is_pc == 1 )
		{
			myself.c_ai2 = attacker;
			myself.i_ai2 = damage;
		}
		if( myself.i_ai1 == 0 )
		{
			c0 = attacker;
			if( attacker.is_pc != 0 || myself::IsInCategory(11,attacker.npc_class_id) )
			{
				if( damage == 0 )
				{
					damage = 1;
				}
				myself::AddAttackDesire(attacker,1,( ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) * 100 ));
			}
		}
		else
		{
			c0 = myself.boss;
		}
		if( gg::Rand(100) < 10 )
		{
			if( myself::Skill_GetConsumeMP(1057793) < myself.sm.mp && myself::Skill_GetConsumeHP(1057793) < myself.sm.hp && myself::Skill_InReuseDelay(1057793) == 0 )
			{
				myself::AddUseSkillDesire(c0,1057793,0,1,1000000);
			}
		}
		if( gg::Rand(100) < 5 && myself::FloatToInt(( ( myself.sm.hp / myself.sm.max_hp ) * 100 )) < 50 )
		{
			if( myself::Skill_GetConsumeMP(1058049) < myself.sm.mp && myself::Skill_GetConsumeHP(1058049) < myself.sm.hp && myself::Skill_InReuseDelay(1058049) == 0 )
			{
				myself::AddUseSkillDesire(myself.sm,1058049,1,1,1000000);
			}
		}
	}

	EventHandler SEE_CREATURE(creature)
	{
		if( myself::InMyTerritory(creature) == 0 || creature.alive == 0 || creature.is_pc == 0 )
		{
			return;
		}
		if( myself.i_ai1 == 0 )
		{
			if( myself::IsNullCreature(myself.top_desire_target) == 0 )
			{
				if( myself.top_desire_target.is_pc == 0 )
				{
					myself::RemoveAttackDesire(myself.boss.id);
				}
			}
			myself::AddAttackDesire(creature,1,200);
		}
		if( myself::IsNullCreature(myself.c_ai2) == 1 )
		{
			myself.c_ai2 = creature;
			myself.i_ai2 = 100;
		}
		else if( myself.c_ai2.alive == 0 )
		{
			myself.c_ai2 = creature;
			myself.i_ai2 = 100;
		}
	}

}
