class 1 use_hate_and_random : default_npc
{
parameter:
	int	DaemonCharge = 1283843;
	int	DaemonAttack = 1283585;

handler:
	EventHandler CREATED(reply,i0)
	{
		myself.c_quest0 = 0;
		myself.c_quest1 = 0;
		myself.c_quest2 = 0;
		myself.c_quest3 = 0;
		myself.i_quest0 = 0;
		myself::AddTimerEx(55002,1000);
	}

	EventHandler ATTACKED(attacker,damage,f0,h0,skill_name_id)
	{
		if( attacker.is_pc != 0 || myself::IsInCategory(11,attacker.npc_class_id) )
		{
			f0 = 0;
			f0 = ( ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) + ( ( f0 / 100 ) * ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) ) );
			myself::AddAttackDesire(attacker,1,myself::FloatToInt(( f0 * 150 )));
			myself::AddHateInfo(attacker,myself::FloatToInt(( f0 * 150 )),0,1,1);
			if( skill_name_id != 0 )
			{
				if( myself::Skill_GetEffectPoint(skill_name_id) < 0 )
				{
					if( attacker.is_pc != 0 || myself::IsInCategory(11,attacker.npc_class_id) )
					{
						if( myself::FloatToInt(myself::DistFromMe(attacker)) > 500 )
						{
							f0 = 0;
							f0 = ( ( ( ( 1.000000 * i0 ) * damage ) / ( myself.sm.level + 7 ) ) + ( ( f0 / 100 ) * ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) ) );
							myself::AddHateInfo(attacker,myself::FloatToInt(( f0 * 200 )),0,1,1);
						}
					}
				}
			}
			if( myself.i_quest0 == 0 )
			{
				myself::AddTimerEx(55001,15000);
				myself.i_quest0 = 1;
			}
			if( myself.c_quest0 == 0 && myself.c_quest1 == 0 && myself.c_quest2 == 0 && myself.c_quest3 == 0 )
			{
				myself.c_quest0 = attacker;
			}
			if( myself.c_quest0 == 0 && myself.c_quest1 != attacker && myself.c_quest2 != attacker && myself.c_quest3 != attacker )
			{
				myself.c_quest0 = attacker;
			}
			if( myself.c_quest1 == 0 && myself.c_quest0 != attacker && myself.c_quest2 != attacker && myself.c_quest3 != attacker )
			{
				myself.c_quest1 = attacker;
			}
			if( myself.c_quest2 == 0 && myself.c_quest0 != attacker && myself.c_quest1 != attacker && myself.c_quest3 != attacker )
			{
				myself.c_quest2 = attacker;
			}
			if( myself.c_quest3 == 0 && myself.c_quest0 != attacker && myself.c_quest1 != attacker && myself.c_quest2 != attacker )
			{
				myself.c_quest3 = attacker;
			}
		}
	}

	EventHandler TIMER_FIRED_EX(timer_id)
	{
		if( timer_id == 55002 )
		{
			if( myself.c_quest0 != 0 )
			{
				if( myself::IsNullCreature(myself::GetCreatureFromID(myself.c_quest0.id)) == 1 || myself.c_quest0.alive == 0 || myself::FloatToInt(myself::DistFromMe(myself.c_quest0)) > 2000 )
				{
					myself.c_quest0 = 0;
				}
			}
			if( myself.c_quest1 != 0 )
			{
				if( myself::IsNullCreature(myself::GetCreatureFromID(myself.c_quest1.id)) == 1 || myself.c_quest1.alive == 0 || myself::FloatToInt(myself::DistFromMe(myself.c_quest1)) > 2000 )
				{
					myself.c_quest1 = 0;
				}
			}
			if( myself.c_quest2 != 0 )
			{
				if( myself::IsNullCreature(myself::GetCreatureFromID(myself.c_quest2.id)) == 1 || myself.c_quest2.alive == 0 || myself::FloatToInt(myself::DistFromMe(myself.c_quest2)) > 2000 )
				{
					myself.c_quest2 = 0;
				}
			}
			if( myself.c_quest3 != 0 )
			{
				if( myself::IsNullCreature(myself::GetCreatureFromID(myself.c_quest3.id)) == 1 || myself.c_quest3.alive == 0 || myself::FloatToInt(myself::DistFromMe(myself.c_quest3)) > 2000 )
				{
					myself.c_quest3 = 0;
				}
			}
			myself::AddTimerEx(55002,1000);
		}
		if( timer_id == 55001 )
		{
			switch(gg::Rand(4))
			{
				case 0:
				{
					if( myself::IsNullCreature(myself.c_quest0) == 0 && myself.c_quest0.alive != 0 )
					{
						c0 = myself.c_quest0;
					}
					else if( myself::IsNullCreature(myself.c_quest1) == 0 && myself.c_quest1.alive != 0 )
					{
						c0 = myself.c_quest1;
					}
					else if( myself::IsNullCreature(myself.c_quest2) == 0 && myself.c_quest2.alive != 0 )
					{
						c0 = myself.c_quest2;
					}
					else if( myself::IsNullCreature(myself.c_quest3) == 0 && myself.c_quest3.alive != 0 )
					{
						c0 = myself.c_quest3;
					}
					break;
				}
				case 1:
				{
					if( myself::IsNullCreature(myself.c_quest1) == 0 && myself.c_quest1.alive != 0 )
					{
						c0 = myself.c_quest1;
					}
					else if( myself::IsNullCreature(myself.c_quest2) == 0 && myself.c_quest2.alive != 0 )
					{
						c0 = myself.c_quest2;
					}
					else if( myself::IsNullCreature(myself.c_quest0) == 0 && myself.c_quest0.alive != 0 )
					{
						c0 = myself.c_quest0;
					}
					else if( myself::IsNullCreature(myself.c_quest3) == 0 && myself.c_quest3.alive != 0 )
					{
						c0 = myself.c_quest3;
					}
					break;
				}
				case 2:
				{
					if( myself::IsNullCreature(myself.c_quest2) == 0 && myself.c_quest2.alive != 0 )
					{
						c0 = myself.c_quest2;
					}
					else if( myself::IsNullCreature(myself.c_quest3) == 0 && myself.c_quest3.alive != 0 )
					{
						c0 = myself.c_quest3;
					}
					else if( myself::IsNullCreature(myself.c_quest1) == 0 && myself.c_quest1.alive != 0 )
					{
						c0 = myself.c_quest1;
					}
					else if( myself::IsNullCreature(myself.c_quest0) == 0 && myself.c_quest0.alive != 0 )
					{
						c0 = myself.c_quest3;
					}
					break;
				}
				case 3:
				{
					if( myself::IsNullCreature(myself.c_quest3) == 0 && myself.c_quest3.alive != 0 )
					{
						c0 = myself.c_quest3;
					}
					else if( myself::IsNullCreature(myself.c_quest0) == 0 && myself.c_quest0.alive != 0 )
					{
						c0 = myself.c_quest0;
					}
					else if( myself::IsNullCreature(myself.c_quest1) == 0 && myself.c_quest1.alive != 0 )
					{
						c0 = myself.c_quest1;
					}
					else if( myself::IsNullCreature(myself.c_quest2) == 0 && myself.c_quest2.alive != 0 )
					{
						c0 = myself.c_quest2;
					}
					break;
				}
			}
			h0 = myself::GetMaxHateInfo(0);
			if( myself::IsNullCreature(c0) == 0 )
			{
				target = c0;
			}
			else if( myself::IsNullHateInfo(h0) == 0 )
			{
				if( myself::IsNullCreature(h0.creature) == 0 )
				{
					target = h0.creature;
				}
				else
				{
					target = myself.top_desire_target;
				}
			}
			else
			{
				target = myself.top_desire_target;
			}
			if( myself::IsNullCreature(target) == 0 )
			{
				if( GM_ID == 10 )
				{
					myself.c_ai0 = target;
					if( myself::FloatToInt(myself::DistFromMe(target)) < 1500 )
					{
						myself::AddUseSkillDesire(target,DaemonCharge,1,1,1000000);
						myself::AddAttackDesire(target,1,100);
					}
					else
					{
						myself::RemoveAllAttackDesire();
						myself::AddAttackDesire(target,1,500);
						myself::AddUseSkillDesire(target,DaemonCharge,1,1,1000000);
					}
				}
				else if( myself::FloatToInt(myself::DistFromMe(target)) < 150 )
				{
					myself::AddAttackDesire(target,1,200);
					myself::AddUseSkillDesire(target,DaemonAttack,1,1,1000000);
				}
				else
				{
					myself::RemoveAllAttackDesire();
					myself::AddAttackDesire(target,1,500);
					myself::AddUseSkillDesire(target,DaemonAttack,1,1,1000000);
				}
			}
			else
			{
				myself::RandomizeAttackDesire();
			}
			myself.c_quest0 = 0;
			myself.c_quest1 = 0;
			myself.c_quest2 = 0;
			myself.c_quest3 = 0;
			myself::AddTimerEx(55001,30000);
		}
	}

	EventHandler SEE_CREATURE(creature,i0,i1,f0)
	{
		if( myself.c_quest0 == 0 && myself.c_quest1 == 0 && myself.c_quest2 == 0 && myself.c_quest3 == 0 )
		{
			myself.c_quest0 = creature;
		}
		if( myself.c_quest0 == 0 && myself.c_quest1 != creature && myself.c_quest2 != creature && myself.c_quest3 != creature )
		{
			myself.c_quest0 = creature;
		}
		if( myself.c_quest1 == 0 && myself.c_quest0 != creature && myself.c_quest2 != creature && myself.c_quest3 != creature )
		{
			myself.c_quest1 = creature;
		}
		if( myself.c_quest2 == 0 && myself.c_quest0 != creature && myself.c_quest1 != creature && myself.c_quest3 != creature )
		{
			myself.c_quest2 = creature;
		}
		if( myself.c_quest3 == 0 && myself.c_quest0 != creature && myself.c_quest1 != creature && myself.c_quest2 != creature )
		{
			myself.c_quest3 = creature;
		}
		if( myself::GetLifeTime() > 7 )
		{
			if( creature.is_pc != 0 || myself::IsInCategory(11,creature.npc_class_id) )
			{
				f0 = 0;
				i0 = 1;
				f0 = ( ( ( 1.000000 * i0 ) / ( myself.sm.level + 7 ) ) + ( ( f0 / 100 ) * ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) ) );
				myself::AddAttackDesire(creature,1,( f0 * 100 ));
				myself::AddHateInfo(creature,myself::FloatToInt(( f0 * 100 )),0,1,1);
			}
		}
	}

	EventHandler CLAN_ATTACKED(attacker,damage,f0)
	{
		if( myself::GetLifeTime() > 7 )
		{
			if( attacker.is_pc != 0 || myself::IsInCategory(11,attacker.npc_class_id) )
			{
				f0 = 0;
				f0 = ( ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) + ( ( f0 / 100 ) * ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) ) );
				myself::AddAttackDesire(attacker,1,( f0 * 30 ));
				myself::AddHateInfo(attacker,myself::FloatToInt(( f0 * 30 )),0,1,1);
			}
		}
	}

	EventHandler SEE_SPELL(speller,skill_name_id,target,f0,i0)
	{
		if( myself::Skill_GetEffectPoint(skill_name_id) > 0 )
		{
			if( myself.p_state == 3 && myself.top_desire_target == target )
			{
				i0 = myself::Skill_GetEffectPoint(skill_name_id);
				f0 = 0;
				f0 = ( ( ( 1.000000 * i0 ) / ( myself.sm.level + 7 ) ) + ( ( f0 / 100 ) * ( ( 1.000000 * i0 ) / ( myself.sm.level + 7 ) ) ) );
				myself::AddHateInfo(speller,myself::FloatToInt(( ( f0 * 200 ) + 100 )),0,1,1);
			}
		}
	}

	EventHandler DESIRE_MANIPULATION(speller,desire)
	{
		myself::MakeAttackEvent(speller,desire,0);
	}

}
