class 1 warrior_casting_ddmagic_selfrangeddmagic : warrior
{
parameter:
	int	W_LongRangeDDMagic = 1064961;
	int	SelfRangeDDMagic = 1032449;

handler:
	EventHandler ATTACKED(attacker,damage,f0)
	{
		if( attacker.is_pc != 0 || myself::IsInCategory(11,attacker.npc_class_id) )
		{
			if( myself::IsNullCreature(myself.top_desire_target) == 0 )
			{
				if( myself::GetAbnormalLevel(myself.sm,myself::Skill_GetAbnormalType(307457)) >= 0 && myself::DistFromMe(myself.top_desire_target) > 40 )
				{
					if( myself::CanAttack(myself.top_desire_target) == 1 )
					{
						if( attacker.is_pc != 0 || myself::IsInCategory(11,attacker.npc_class_id) )
						{
							f0 = 0;
							if( SetHateGroup >= 0 )
							{
								if( myself::IsInCategory(SetHateGroup,attacker.occupation) )
								{
									f0 = ( f0 + SetHateGroupRatio );
								}
							}
							if( attacker.occupation == SetHateOccupation )
							{
								f0 = ( f0 + SetHateOccupationRatio );
							}
							if( SetHateRace == attacker.race )
							{
								f0 = ( f0 + SetHateRaceRatio );
							}
							f0 = ( ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) + ( ( f0 / 100 ) * ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) ) );
							myself::AddAttackDesire(attacker,1,( f0 * 100 ));
						}
					}
					else if( myself::CanAttack(myself.top_desire_target) == 0 && myself::DistFromMe(myself.top_desire_target) < 600 )
					{
						if( myself::Skill_GetConsumeMP(W_LongRangeDDMagic) < myself.sm.mp && myself::Skill_GetConsumeHP(W_LongRangeDDMagic) < myself.sm.hp && myself::Skill_InReuseDelay(W_LongRangeDDMagic) == 0 )
						{
							myself::AddUseSkillDesire(myself.top_desire_target,W_LongRangeDDMagic,0,1,1000000);
						}
					}
					else
					{
						myself::RemoveAttackDesire(myself.top_desire_target.id);
						if( attacker.is_pc != 0 || myself::IsInCategory(11,attacker.npc_class_id) )
						{
							f0 = 0;
							if( SetHateGroup >= 0 )
							{
								if( myself::IsInCategory(SetHateGroup,attacker.occupation) )
								{
									f0 = ( f0 + SetHateGroupRatio );
								}
							}
							if( attacker.occupation == SetHateOccupation )
							{
								f0 = ( f0 + SetHateOccupationRatio );
							}
							if( SetHateRace == attacker.race )
							{
								f0 = ( f0 + SetHateRaceRatio );
							}
							f0 = ( ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) + ( ( f0 / 100 ) * ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) ) );
							myself::AddAttackDesire(attacker,1,( f0 * 100 ));
						}
					}
				}
				if( myself::DistFromMe(attacker) > 200 && myself::DistFromMe(attacker) < 600 && myself.top_desire_target == attacker )
				{
					if( myself::Skill_GetConsumeMP(W_LongRangeDDMagic) < myself.sm.mp && myself::Skill_GetConsumeHP(W_LongRangeDDMagic) < myself.sm.hp && myself::Skill_InReuseDelay(W_LongRangeDDMagic) == 0 )
					{
						myself::AddUseSkillDesire(attacker,W_LongRangeDDMagic,0,1,1000000);
					}
				}
				if( gg::Rand(100) < 33 && myself.top_desire_target != attacker && myself::DistFromMe(attacker) < 200 )
				{
					if( myself::Skill_GetConsumeMP(SelfRangeDDMagic) < myself.sm.mp && myself::Skill_GetConsumeHP(SelfRangeDDMagic) < myself.sm.hp && myself::Skill_InReuseDelay(SelfRangeDDMagic) == 0 )
					{
						myself::AddUseSkillDesire(attacker,SelfRangeDDMagic,0,1,1000000);
					}
				}
			}
		}
		super;
	}

	EventHandler CLAN_ATTACKED(attacker,damage)
	{
		if( myself::GetLifeTime() > 7 && ( attacker.is_pc != 0 || myself::IsInCategory(11,attacker.npc_class_id) ) )
		{
			if( myself::IsNullCreature(myself.top_desire_target) == 0 )
			{
				if( myself::DistFromMe(attacker) < 200 && gg::Rand(100) < 33 && myself.top_desire_target != attacker )
				{
					if( myself::Skill_GetConsumeMP(SelfRangeDDMagic) < myself.sm.mp && myself::Skill_GetConsumeHP(SelfRangeDDMagic) < myself.sm.hp && myself::Skill_InReuseDelay(SelfRangeDDMagic) == 0 )
					{
						myself::AddUseSkillDesire(myself.sm,SelfRangeDDMagic,0,1,1000000);
					}
				}
			}
		}
		super;
	}

	EventHandler USE_SKILL_FINISHED()
	{
		if( myself::IsNullCreature(myself.top_desire_target) == 0 )
		{
			if( myself::DistFromMe(myself.top_desire_target) > 200 && myself.top_desire_target.is_pc == 1 )
			{
				if( myself::Skill_GetConsumeMP(W_LongRangeDDMagic) < myself.sm.mp && myself::Skill_GetConsumeHP(W_LongRangeDDMagic) < myself.sm.hp && myself::Skill_InReuseDelay(W_LongRangeDDMagic) == 0 )
				{
					myself::AddUseSkillDesire(myself.top_desire_target,W_LongRangeDDMagic,0,1,1000000);
				}
			}
		}
		super;
	}

}
