if(isSkillDisabled(skill.getId()))
{
if(activeChar instanceof L2PcInstance && !(skill.getId() == 2166))
{
SystemMessage sm = new SystemMessage(SystemMessageId.S1_PREPARED_FOR_REUSE);
sm.addSkillName(skill.getId(), skill.getLevel());
sendPacket(sm);
sm = null;
}
// Cp potion message
else if(activeChar instanceof L2PcInstance && (skill.getId() == 2166))
{
if (skill.getLevel() == 2)
((L2PcInstance) activeChar).sendMessage("Greater CP Potion is not available at this time: being prepared for reuse.");
else if (skill.getLevel() == 1)
((L2PcInstance) activeChar).sendMessage("CP Potion is not available at this time: being prepared for reuse.");
}
return;
}
// Check if the skill is a magic spell and if the L2Character is not muted
if(skill.isMagic() && isMuted() && !skill.isPotion())
{
getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
return;
}
// Check if the skill is psychical and if the L2Character is not psychical_muted
if(!skill.isMagic() && isPsychicalMuted() && !skill.isPotion())
{
getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
return;
}
// Can't use Hero and resurrect skills during Olympiad
if(activeChar instanceof L2PcInstance && ((L2PcInstance) activeChar).isInOlympiadMode() && (skill.isHeroSkill() || skill.getSkillType() == SkillType.RESURRECT))
{
SystemMessage sm = new SystemMessage(SystemMessageId.THIS_SKILL_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
sendPacket(sm);
sm = null;
return;
}
// Like L2OFF you can't use skills when you are attacking now
if (activeChar instanceof L2PcInstance && !skill.isPotion())
{
L2ItemInstance rhand = ((L2PcInstance) this).getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
if ((rhand != null && rhand.getItemType() == L2WeaponType.BOW))
{
if (isAttackingNow())
return;
}
}
// prevent casting signets to peace zone
if (skill.getSkillType() == SkillType.SIGNET || skill.getSkillType() == SkillType.SIGNET_CASTTIME)
{
/*for (L2Effect effect : getAllEffects())
{
if (effect.getEffectType() == L2Effect.EffectType.SIGNET_EFFECT
|| effect.getEffectType() == L2Effect.EffectType.SIGNET_GROUND)
{
SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
sm.addSkillName(skill.getId());
sendPacket(sm);
return;
}
}*/
L2WorldRegion region = getWorldRegion();
if (region == null) return;
boolean canCast = true;
if (skill.getTargetType() == SkillTargetType.TARGET_GROUND && this instanceof L2PcInstance)
{
Point3D wp = ((L2PcInstance) this).getCurrentSkillWorldPosition();
if (!region.checkEffectRangeInsidePeaceZone(skill, wp.getX(), wp.getY(), wp.getZ()))
canCast = false;
}
else if (!region.checkEffectRangeInsidePeaceZone(skill, getX(), getY(), getZ()))
canCast = false;
if (!canCast)
{
SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
sm.addSkillName(skill.getId());
sendPacket(sm);
return;
}
}
//Recharge AutoSoulShot
if(skill.useSoulShot())
{
if(activeChar instanceof L2PcInstance)
{
((L2PcInstance) activeChar).rechargeAutoSoulShot(true, false, false);
}
else if(this instanceof L2Summon)
{
((L2Summon) activeChar).getOwner().rechargeAutoSoulShot(true, false, true);
}
}
else if(skill.useSpiritShot())
{
if(activeChar instanceof L2PcInstance)
{
((L2PcInstance) activeChar).rechargeAutoSoulShot(false, true, false);
}
else if(activeChar instanceof L2Summon)
{
((L2Summon) activeChar).getOwner().rechargeAutoSoulShot(false, true, true);
}
}
//else if (skill.useFishShot())
//{
// if (this instanceof L2PcInstance)
// ((L2PcInstance)this).rechargeAutoSoulShot(true, false, false);
//}
// Get all possible targets of the skill in a table in function of the skill target type
final L2Object[] targets = skill.getTargetList(activeChar);
// Set the target of the skill in function of Skill Type and Target Type
L2Character target = null;
if(skill.getTargetType() == SkillTargetType.TARGET_AURA || skill.getTargetType() == SkillTargetType.TARGET_GROUND || skill.isPotion())
{
target = this;
}
else if(targets == null || targets.length == 0)
{
getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
return;
}
else if((skill.getSkillType() == SkillType.BUFF || skill.getSkillType() == SkillType.HEAL || skill.getSkillType() == SkillType.COMBATPOINTHEAL || skill.getSkillType() == SkillType.COMBATPOINTPERCENTHEAL || skill.getSkillType() == SkillType.MANAHEAL || skill.getSkillType() == SkillType.REFLECT || skill.getSkillType() == SkillType.SEED || skill.getTargetType() == L2Skill.SkillTargetType.TARGET_SELF || skill.getTargetType() == L2Skill.SkillTargetType.TARGET_PET || skill.getTargetType() == L2Skill.SkillTargetType.TARGET_PARTY || skill.getTargetType() == L2Skill.SkillTargetType.TARGET_CLAN || skill.getTargetType() == L2Skill.SkillTargetType.TARGET_ALLY) && !skill.isPotion())
{
target = (L2Character) targets[0];
/*if (this instanceof L2PcInstance && target instanceof L2PcInstance && target.getAI().getIntention() == CtrlIntention.AI_INTENTION_ATTACK)
{
if(skill.getSkillType() == SkillType.BUFF || skill.getSkillType() == SkillType.HOT || skill.getSkillType() == SkillType.HEAL || skill.getSkillType() == SkillType.HEAL_PERCENT || skill.getSkillType() == SkillType.MANAHEAL || skill.getSkillType() == SkillType.MANAHEAL_PERCENT || skill.getSkillType() == SkillType.BALANCE_LIFE)
target.setLastBuffer(this);
if (((L2PcInstance)this).isInParty() && skill.getTargetType() == L2Skill.SkillTargetType.TARGET_PARTY)
{
for (L2PcInstance member : ((L2PcInstance)this).getParty().getPartyMembers())
member.setLastBuffer(this);
}
}*/
}
else
{
target = (L2Character) getTarget();
}
if(target == null)
{
getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
return;
}
// Player can't heal rb config
if(!Config.PLAYERS_CAN_HEAL_RB
&& activeChar instanceof L2PcInstance
&& !((L2PcInstance) activeChar).isGM()
&& (target instanceof L2RaidBossInstance || target instanceof L2GrandBossInstance)
&& (skill.getSkillType() == SkillType.HEAL || skill.getSkillType() == SkillType.HEAL_PERCENT))
{
this.sendPacket( ActionFailed.STATIC_PACKET );
return;
}
if (activeChar instanceof L2PcInstance && target instanceof L2NpcInstance && Config.DISABLE_ATTACK_NPC_TYPE)
{
String mobtype = ((L2NpcInstance) target).getTemplate().type;
if (!Config.LIST_ALLOWED_NPC_TYPES.contains(mobtype))
{
SystemMessage sm = new SystemMessage(SystemMessageId.S1_S2);
sm.addString("Npc Type "+mobtype+" has Protection - No Attack Allowed!");
((L2PcInstance) activeChar).sendPacket(sm);
((L2PcInstance) activeChar).sendPacket(ActionFailed.STATIC_PACKET);
return;
}
}
if(skill.isPotion())
setLastPotionCast(skill);
else
setLastSkillCast(skill);
// Get the Identifier of the skill
int magicId = skill.getId();
// Get the Display Identifier for a skill that client can't display
int displayId = skill.getDisplayId();
// Get the level of the skill
int level = skill.getLevel();
if(level < 1)
{
level = 1;
}
// Get the casting time of the skill (base)
int hitTime = skill.getHitTime();
int coolTime = skill.getCoolTime();
final boolean effectWhileCasting = skill.hasEffectWhileCasting();
boolean forceBuff = skill.getSkillType() == SkillType.FORCE_BUFF && target instanceof L2PcInstance;
// Calculate the casting time of the skill (base + modifier of MAtkSpd)
// Don't modify the skill time for FORCE_BUFF skills. The skill time for those skills represent the buff time.
if(!effectWhileCasting && !forceBuff && !skill.isStaticHitTime())
{
hitTime = Formulas.getInstance().calcMAtkSpd(activeChar, skill, hitTime);
if(coolTime > 0)
{
coolTime = Formulas.getInstance().calcMAtkSpd(activeChar, skill, coolTime);
}
}
// Calculate altered Cast Speed due to BSpS/SpS only for Magic skills
if((checkBss() || checkSps()) && !skill.isStaticHitTime() && !skill.isPotion() && skill.isMagic()){
//Only takes 70% of the time to cast a BSpS/SpS cast
hitTime = (int) (0.70 * hitTime);
coolTime = (int) (0.70 * coolTime);
//Because the following are magic skills that do not actively 'eat' BSpS/SpS,
//I must 'eat' them here so players don't take advantage of infinite speed increase
/* MANAHEAL, MANARECHARGE, RESURRECT, RECALL*/
if(skill.getSkillType() == SkillType.MANAHEAL || skill.getSkillType() == SkillType.MANARECHARGE || skill.getSkillType() == SkillType.RESURRECT || skill.getSkillType() == SkillType.RECALL)
{
if(checkBss())
removeBss();
else
removeSps();
}
}
/*
// Calculate altered Cast Speed due to BSpS/SpS
L2ItemInstance weaponInst = getActiveWeaponInstance();
if(weaponInst != null && skill.isMagic() && !forceBuff && skill.getTargetType() != SkillTargetType.TARGET_SELF && !skill.isStaticHitTime() && !skill.isPotion())
{
if(weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT || weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_SPIRITSHOT)
{
//Only takes 70% of the time to cast a BSpS/SpS cast
hitTime = (int) (0.70 * hitTime);
coolTime = (int) (0.70 * coolTime);
//Because the following are magic skills that do not actively 'eat' BSpS/SpS,
//I must 'eat' them here so players don't take advantage of infinite speed increase
if(skill.getSkillType() == SkillType.BUFF || skill.getSkillType() == SkillType.MANAHEAL || skill.getSkillType() == SkillType.RESURRECT || skill.getSkillType() == SkillType.RECALL || skill.getSkillType() == SkillType.DOT)
{
weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
}
}
}
weaponInst = null;
*/
if(skill.isPotion()){
// Set the _castEndTime and _castInterruptTim. +10 ticks for lag situations, will be reseted in onMagicFinalizer
_castPotionEndTime = 10 + GameTimeController.getGameTicks() + (coolTime + hitTime) / GameTimeController.MILLIS_IN_TICK;
_castPotionInterruptTime = -2 + GameTimeController.getGameTicks() + hitTime / GameTimeController.MILLIS_IN_TICK;
}else{
// Set the _castEndTime and _castInterruptTim. +10 ticks for lag situations, will be reseted in onMagicFinalizer
_castEndTime = 10 + GameTimeController.getGameTicks() + (coolTime + hitTime) / GameTimeController.MILLIS_IN_TICK;
_castInterruptTime = -2 + GameTimeController.getGameTicks() + hitTime / GameTimeController.MILLIS_IN_TICK;
}
// Init the reuse time of the skill
//int reuseDelay = (int)(skill.getReuseDelay() * getStat().getMReuseRate(skill));
//reuseDelay *= 333.0 / (skill.isMagic() ? getMAtkSpd() : getPAtkSpd());
int reuseDelay = skill.getReuseDelay();
if(activeChar instanceof L2PcInstance && Formulas.getInstance().calcSkillMastery(activeChar))
{
reuseDelay = 0;
}
else if(!skill.isStaticReuse() && !skill.isPotion())
{
if(skill.isMagic())
{
reuseDelay *= getStat().getMReuseRate(skill);
}
else
{
reuseDelay *= getStat().getPReuseRate(skill);
}
reuseDelay *= 333.0 / (skill.isMagic() ? getMAtkSpd() : getPAtkSpd());
}
// To turn local player in target direction
setHeading(Util.calculateHeadingFrom(getX(), getY(), target.getX(), target.getY()));
/*
if(skill.isOffensive() && skill.getTargetType() != SkillTargetType.TARGET_AURA && target.isBehind(this))
{
moveToLocation(target.getX(), target.getY(), target.getZ(), 0);
stopMove(null);
}
*/
// Start the effect as long as the player is casting.
if(effectWhileCasting)
{
callSkill(skill, targets);
}
// Send a Server->Client packet MagicSkillUser with target, displayId, level, skillTime, reuseDelay
// to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character
broadcastPacket(new MagicSkillUser(this, target, displayId, level, hitTime, reuseDelay));
// Send a system message USE_S1 to the L2Character
if (activeChar instanceof L2PcInstance && magicId != 1312)
{
if (skill.isPotion())
{
SystemMessage sm = new SystemMessage(SystemMessageId.USE_S1_);
if (magicId == 2005)
sm.addItemName(728);
else if (magicId == 2003)
sm.addItemName(726);
// Message greater cp potions like retail
else if (magicId == 2166 && skill.getLevel() == 2)
sm.addItemName(5592);
// Message cp potions like retail
else if (magicId == 2166 && skill.getLevel() == 1)
sm.addItemName(5591);
else
sm.addSkillName(magicId, skill.getLevel());
sendPacket(sm);
sm = null;
}
else
{
SystemMessage sm = new SystemMessage(SystemMessageId.USE_S1);
if (magicId == 2005)
sm.addItemName(728);
else if (magicId == 2003)
sm.addItemName(726);
// Message greater cp potions like retail
else if (magicId == 2166 && skill.getLevel() == 2)
sm.addItemName(5592);
// Message cp potions like retail
else if (magicId == 2166 && skill.getLevel() == 1)
sm.addItemName(5591);
else
sm.addSkillName(magicId, skill.getLevel());
// Skill 2046 is used only for animation on pets
if (magicId != 2046)
sendPacket(sm);
sm = null;