}
// ************************************* Check Target *******************************************
// Create and set a L2Object containing the target of the skill
L2Object target = null;
SkillTargetType sklTargetType = skill.getTargetType();
SkillType sklType = skill.getSkillType();
switch (sklTargetType)
{
// Target the player if skill type is AURA, PARTY, CLAN or SELF
case TARGET_AURA:
case TARGET_PARTY:
case TARGET_ALLY:
case TARGET_CLAN:
case TARGET_SELF:
target = this;
break;
case TARGET_PET:
target = getPet();
break;
default:
target = getTarget();
break;
}
// Check the validity of the target
if (target == null)
{
sendPacket(new SystemMessage(SystemMessageId.TARGET_CANT_FOUND));
sendPacket(new ActionFailed());
return;
}
// Are the target and the player in the same duel?
if (isInDuel())
{
if (!((target instanceof L2PcInstance) && (((L2PcInstance) target).getDuelId() == getDuelId())))
{
sendMessage("You cannot do this while duelling.");
sendPacket(new ActionFailed());
return;
}
}
// ************************************* Check skill availability *******************************************
// Check if this skill is enabled (ex : reuse time)
if (isSkillDisabled(skill.getId()) && (getAccessLevel() < Config.GM_PEACEATTACK))
{
SystemMessage sm = new SystemMessage(SystemMessageId.SKILL_NOT_AVAILABLE);
sm.addString(skill.getName());
sendPacket(sm);
// Send a Server->Client packet ActionFailed to the L2PcInstance
sendPacket(new ActionFailed());
return;
}
// Check if all skills are disabled
if (isAllSkillsDisabled() && (getAccessLevel() < Config.GM_PEACEATTACK))
{
// Send a Server->Client packet ActionFailed to the L2PcInstance
sendPacket(new ActionFailed());
return;
}
// ************************************* Check Consumables *******************************************
// Check if the caster has enough MP
if (getCurrentMp() < (getStat().getMpConsume(skill) + getStat().getMpInitialConsume(skill)))
{
// Send a System Message to the caster
sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_MP));
// Send a Server->Client packet ActionFailed to the L2PcInstance
sendPacket(new ActionFailed());
return;
}
// Check if the caster has enough HP
if (getCurrentHp() <= skill.getHpConsume())
{
// Send a System Message to the caster
sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_HP));
// Send a Server->Client packet ActionFailed to the L2PcInstance
sendPacket(new ActionFailed());
return;
}
// Check if the spell consummes an Item
if (skill.getItemConsume() > 0)
{
// Get the L2ItemInstance consummed by the spell
L2ItemInstance requiredItems = getInventory().getItemByItemId(skill.getItemConsumeId());
// Check if the caster owns enought consummed Item to cast
if ((requiredItems == null) || (requiredItems.getCount() < skill.getItemConsume()))
{
// Checked: when a summon skill failed, server show required consume item count
if (sklType == L2Skill.SkillType.SUMMON)
{
SystemMessage sm = new SystemMessage(SystemMessageId.SUMMONING_SERVITOR_COSTS_S2_S1);
sm.addItemName(skill.getItemConsumeId());
sm.addNumber(skill.getItemConsume());
sendPacket(sm);
}
else
{
// Send a System Message to the caster
sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_ITEMS));
}
return;
}
}
// ************************************* Check Casting Conditions *******************************************
// Check if the caster own the weapon needed
if (!skill.getWeaponDependancy(this))
{
// Send a Server->Client packet ActionFailed to the L2PcInstance
sendPacket(new ActionFailed());
return;
}
// Check if all casting conditions are completed
if (!skill.checkCondition(this, target, false))
{
// Send a Server->Client packet ActionFailed to the L2PcInstance
sendPacket(new ActionFailed());
return;
}
// ************************************* Check Player State *******************************************
// Abnormal effects(ex : Stun, Sleep...) are checked in L2Character useMagic()
// Check if the player use "Fake Death" skill
if (isAlikeDead())
{
// Send a Server->Client packet ActionFailed to the L2PcInstance
sendPacket(new ActionFailed());
return;
}
// Check if the caster is sitting
if (isSitting() && !skill.isPotion())
{
// Send a System Message to the caster
sendPacket(new SystemMessage(SystemMessageId.CANT_MOVE_SITTING));
// Send a Server->Client packet ActionFailed to the L2PcInstance
sendPacket(new ActionFailed());
return;
}
if (isFishing() && ((sklType != SkillType.PUMPING) && (sklType != SkillType.REELING) && (sklType != SkillType.FISHING)))
{
// Only fishing skills are available
sendPacket(new SystemMessage(SystemMessageId.ONLY_FISHING_SKILLS_NOW));
return;
}
// ************************************* Check Skill Type *******************************************
// Check if this is offensive magic skill
if (skill.isOffensive())
{
if ((isInsidePeaceZone(this, target)) && (getAccessLevel() < Config.GM_PEACEATTACK))
{
// If L2Character or target is in a peace zone, send a system message TARGET_IN_PEACEZONE a Server->Client packet ActionFailed
sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE));
sendPacket(new ActionFailed());
return;
}
if (isInOlympiadMode() && !isOlympiadStart())
{
// if L2PcInstance is in Olympia and the match isn't already start, send a Server->Client packet ActionFailed
sendPacket(new ActionFailed());
return;
}
// Check if the target is attackable
if (!target.isAttackable() && (getAccessLevel() < Config.GM_PEACEATTACK))
{
// If target is not attackable, send a Server->Client packet ActionFailed
sendPacket(new ActionFailed());
return;
}
// Check if a Forced ATTACK is in progress on non-attackable target
if (!target.isAutoAttackable(this) && !forceUse && (sklTargetType != SkillTargetType.TARGET_AURA) && (sklTargetType != SkillTargetType.TARGET_CLAN) && (sklTargetType != SkillTargetType.TARGET_ALLY) && (sklTargetType != SkillTargetType.TARGET_PARTY) && (sklTargetType != SkillTargetType.TARGET_SELF))
{
// Send a Server->Client packet ActionFailed to the L2PcInstance
sendPacket(new ActionFailed());
return;
}