// Like L2OFF you can't use fake death if you are mounted
if (skill.getId() == 60 && isMounted())
return;
// Get effects of the skill
L2Effect effect = getFirstEffect(skill);
// Like L2OFF toogle skills have little delay
if (TOGGLE_USE + 400 > System.currentTimeMillis())
{
return;
}
if(effect != null)
{
//fake death exception
if (skill.getId() != 60)
effect.exit(false);
// Send a Server->Client packet ActionFailed to the L2PcInstance
sendPacket(ActionFailed.STATIC_PACKET);
return;
}
TOGGLE_USE = System.currentTimeMillis();
}
// Check if the skill is active
if(skill.isPassive())
{
// just ignore the passive skill request. why does the client send it anyway ??
// Send a Server->Client packet ActionFailed to the L2PcInstance
sendPacket(ActionFailed.STATIC_PACKET);
return;
}
if(_disabledSkills != null && _disabledSkills.contains(skill_id))
{
SystemMessage sm = new SystemMessage(SystemMessageId.S1_PREPARED_FOR_REUSE);
sm.addSkillName(skill_id, skill.getLevel());
sendPacket(sm);
sm = null;
return;
}
// Check if it's ok to summon
// siege golem (13), Wild Hog Cannon (299), Swoop Cannon (448)
if((skill_id == 13 || skill_id == 299 || skill_id == 448) && !SiegeManager.getInstance().checkIfOkToSummon(this, false) && !FortSiegeManager.getInstance().checkIfOkToSummon(this, false))
return;
//************************************* Check Casting in Progress *******************************************
// If a skill is currently being used, queue this one if this is not the same
// Note that this check is currently imperfect: getCurrentSkill() isn't always null when a skill has
// failed to cast, or the casting is not yet in progress when this is rechecked
if(curr_skill_id != -1 && (isCastingNow() || isCastingPotionNow()))
{
SkillDat currentSkill = getCurrentSkill();
// Check if new skill different from current skill in progress
if (currentSkill != null && skill.getId() == currentSkill.getSkillId())
{
sendPacket(ActionFailed.STATIC_PACKET);
return;
}
if(Config.DEBUG && getQueuedSkill() != null)
{
_log.info(getQueuedSkill().getSkill().getName() + " is already queued for " + getName() + ".");
}
// Create a new SkillDat object and queue it in the player _queuedSkill
setQueuedSkill(skill, forceUse, dontMove);
sendPacket(ActionFailed.STATIC_PACKET);
return;
}
// Create a new SkillDat object and set the player _currentSkill
// This is used mainly to save & queue the button presses, since L2Character has
// _lastSkillCast which could otherwise replace it
setCurrentSkill(skill, forceUse, dontMove);
if (getQueuedSkill() != null) // wiping out previous values, after casting has been aborted
setQueuedSkill(null, false, false);
//triggered skills cannot be used directly
if(_triggeredSkills.size()>0){
if(Config.DEBUG){
System.out.println("Checking if Triggherable Skill: "+skill.getId());
System.out.println("Saved Triggherable Skills");
for(Integer skillId:_triggeredSkills.keySet()){
System.out.println(skillId);
}
}
if(_triggeredSkills.get(skill.getId()) != null){
sendPacket(ActionFailed.STATIC_PACKET);
return;
}
}
//************************************* 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:
if(isInOlympiadMode() && !isOlympiadStart())
setTarget(this);
case TARGET_PARTY:
case TARGET_ALLY:
case TARGET_CLAN:
case TARGET_GROUND:
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(ActionFailed.STATIC_PACKET);
return;
}
// skills can be used on Walls and Doors only durring siege
// Ignore skill UNLOCK
if(skill.isOffensive() && target instanceof L2DoorInstance )
{
boolean isCastle = (((L2DoorInstance) target).getCastle() != null
&& ((L2DoorInstance) target).getCastle().getCastleId() > 0
&& ((L2DoorInstance) target).getCastle().getSiege().getIsInProgress());
boolean isFort = (((L2DoorInstance) target).getFort() != null
&& ((L2DoorInstance) target).getFort().getFortId() > 0
&& ((L2DoorInstance) target).getFort().getSiege().getIsInProgress());
if ((!isCastle && !isFort))
return;
}
// Like L2OFF you can't heal random purple people without using CTRL
SkillDat skilldat = getCurrentSkill();
if (skilldat != null && skill.getSkillType() == SkillType.HEAL && !skilldat.isCtrlPressed() && target instanceof L2PcInstance && ((L2PcInstance) target).getPvpFlag() == 1 && this != target)
{
if ((getClanId() == 0 || ((L2PcInstance) target).getClanId() == 0) || (getClanId() != ((L2PcInstance) target).getClanId()))
{
if ((getAllyId() == 0 || ((L2PcInstance) target).getAllyId() == 0) || (getAllyId() != ((L2PcInstance) target).getAllyId()))
{
if ((getParty() == null || ((L2PcInstance) target).getParty() == null) || (!getParty().equals(((L2PcInstance) target).getParty())))
{
sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
sendPacket(ActionFailed.STATIC_PACKET);
return;
}
}
}
}
// Are the target and the player in the same duel?
if(isInDuel())
{
if(!(target instanceof L2PcInstance && ((L2PcInstance) target).getDuelId() == getDuelId()) && !(target instanceof L2SummonInstance && ((L2Summon) target).getOwner().getDuelId() == getDuelId()))
{
sendMessage("You cannot do this while duelling.");
sendPacket(ActionFailed.STATIC_PACKET);
return;
}
}
//************************************* Check skill availability *******************************************
// Check if this skill is enabled (ex : reuse time)
if(isSkillDisabled(skill_id) /* && !getAccessLevel().allowPeaceAttack() */)
{
// SystemMessage sm = new SystemMessage(SystemMessageId.SKILL_NOT_AVAILABLE);
// sm.addString(skill.getName());
// sendPacket(sm);
// Send a Server->Client packet ActionFailed to the L2PcInstance
sendPacket(ActionFailed.STATIC_PACKET);
return;
}
// Check if all skills are disabled
if(isAllSkillsDisabled() && !getAccessLevel().allowPeaceAttack())
{
// Send a Server->Client packet ActionFailed to the L2PcInstance
sendPacket(ActionFailed.STATIC_PACKET);
return;
}
// prevent casting signets to peace zone
if(skill.getSkillType() == SkillType.SIGNET || skill.getSkillType() == SkillType.SIGNET_CASTTIME)
{
if(isInsidePeaceZone(this))
{
SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
sm.addSkillName(skill_id);
sendPacket(sm);
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(ActionFailed.STATIC_PACKET);
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(ActionFailed.STATIC_PACKET);
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;
}
}
// Like L2OFF if you are mounted on wyvern you can't use own skills
if (isFlying())
{
if (skill_id != 327 && skill_id != 4289 && !skill.isPotion())
{
sendMessage("You cannot use skills while riding a wyvern.");
return;
}
}
// Like L2OFF if you have a summon you can't summon another one (ignore cubics)
if(sklType == L2Skill.SkillType.SUMMON && skill instanceof L2SkillSummon && !((L2SkillSummon) skill).isCubic())
{
if (getPet() != null || isMounted())
{
sendPacket(new SystemMessage(SystemMessageId.YOU_ALREADY_HAVE_A_PET));
return;
}
}
if(skill.getNumCharges() > 0
&& skill.getSkillType() != SkillType.CHARGE
&& skill.getSkillType() != SkillType.CHARGEDAM
&& skill.getSkillType() != SkillType.CHARGE_EFFECT
&& skill.getSkillType() != SkillType.PDAM)
{
EffectCharge effect = (EffectCharge) getFirstEffect(L2Effect.EffectType.CHARGE);
if(effect == null || effect.numCharges < skill.getNumCharges())
{
sendPacket(new SystemMessage(SystemMessageId.SKILL_NOT_AVAILABLE));
return;
}
effect.numCharges -= skill.getNumCharges();
sendPacket(new EtcStatusUpdate(this));
if(effect.numCharges == 0)
{
effect.exit(false);
}
}
//************************************* Check Casting Conditions *******************************************
// Check if the caster own the weapon needed