class 1 warrior_casting_3skill_magical4 : warrior
{
parameter:
	int	MagicHeal = 1033473;
	int	Buff = 1031169;
	int	CancelMagic = 1048065;
	int	CheckMagic = 0;
	int	CheckMagic1 = 0;
	int	CheckMagic2 = 0;

handler:
	EventHandler CREATED()
	{
		myself.i_ai0 = 0;
		myself.i_ai1 = 0;
		myself.i_ai2 = 0;
		super;
	}

	EventHandler ATTACKED(attacker,damage,i0)
	{
		i0 = myself::FloatToInt(( ( myself.sm.hp / myself.sm.max_hp ) * 100 ));
		if( gg::Rand(100) < 33 && i0 < 70 )
		{
			if( myself::Skill_GetConsumeMP(MagicHeal) < myself.sm.mp && myself::Skill_GetConsumeHP(MagicHeal) < myself.sm.hp && myself::Skill_InReuseDelay(MagicHeal) == 0 )
			{
				myself::AddUseSkillDesire(myself.sm,MagicHeal,1,1,1000000);
			}
		}
		if( attacker.is_pc != 0 || myself::IsInCategory(11,attacker.npc_class_id) )
		{
			if( myself.i_ai1 == 0 && gg::Rand(100) < 33 && myself::FloatToInt(( ( myself.sm.hp / myself.sm.max_hp ) * 100 )) > 50 )
			{
				if( myself::Skill_GetConsumeMP(Buff) < myself.sm.mp && myself::Skill_GetConsumeHP(Buff) < myself.sm.hp && myself::Skill_InReuseDelay(Buff) == 0 )
				{
					myself::AddUseSkillDesire(myself.sm,Buff,1,1,1000000);
				}
			}
			else if( gg::Rand(200) < 1 && myself.i_ai2 == 0 && myself.sm.hp > ( myself.sm.max_hp * 0.600000 ) )
			{
				if( myself::IsNullCreature(myself.top_desire_target) == 0 )
				{
					if( ( CheckMagic == 0 || myself::GetAbnormalLevel(attacker,myself::Skill_GetAbnormalType(CheckMagic)) <= 0 ) && ( ( CheckMagic1 == 0 || myself::GetAbnormalLevel(attacker,myself::Skill_GetAbnormalType(CheckMagic1)) <= 0 ) && ( ( CheckMagic2 == 0 || myself::GetAbnormalLevel(attacker,myself::Skill_GetAbnormalType(CheckMagic2)) <= 0 ) && myself.top_desire_target == attacker ) ) )
					{
						if( myself::Skill_GetConsumeMP(CancelMagic) < myself.sm.mp && myself::Skill_GetConsumeHP(CancelMagic) < myself.sm.hp && myself::Skill_InReuseDelay(CancelMagic) == 0 )
						{
							myself::AddUseSkillDesire(attacker,CancelMagic,0,1,1000000);
						}
						myself.i_ai2 = 1;
					}
				}
			}
			myself.i_ai1 = 1;
		}
		super;
	}

	EventHandler CLAN_ATTACKED(attacker,victim,damage,i0)
	{
		if( gg::Rand(100) < 33 && myself.p_state != 3 )
		{
			if( myself::Skill_GetConsumeMP(MagicHeal) < myself.sm.mp && myself::Skill_GetConsumeHP(MagicHeal) < myself.sm.hp && myself::Skill_InReuseDelay(MagicHeal) == 0 )
			{
				myself::AddUseSkillDesire(victim,MagicHeal,1,1,1000000);
			}
		}
		super;
	}

}
