if (activeChar instanceof L2PcInstance)
{
if (weaponInst == null && skill.isOffensive())
{
SystemMessage sm2 = new SystemMessage(SystemMessageId.S1_S2);
sm2.addString("You must equip a weapon before casting a spell.");
activeChar.sendPacket(sm2);
return;
}
}
if (weaponInst != null)
{
if (skill.isMagic())
{
if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
{
bss = true;
if (skill.getId() != 1020) // vitalize
weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
}
else if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_SPIRITSHOT)
{
sps = true;
if (skill.getId() != 1020) // vitalize
weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
}
}
else
if (weaponInst.getChargedSoulshot() == L2ItemInstance.CHARGED_SOULSHOT)
{
ss = true;
if (skill.getId() != 1020) // vitalize
weaponInst.setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
}
}
// If there is no weapon equipped, check for an active summon.
else if (activeChar instanceof L2Summon)
{
L2Summon activeSummon = (L2Summon) activeChar;
if (skill.isMagic())
{
if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
{
bss = true;
activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
}
else if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_SPIRITSHOT)
{
sps = true;
activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
}
}
else
if (activeSummon.getChargedSoulShot() == L2ItemInstance.CHARGED_SOULSHOT)
{
ss = true;
activeSummon.setChargedSoulShot(L2ItemInstance.CHARGED_NONE);
}
}
for (int index = 0; index < targets.length; index++)
{
// Get a target
if (!(targets[index] instanceof L2Character)) continue;
L2Character target = (L2Character) targets[index];
if (target == null || target.isDead()) //bypass if target is null or dead
continue;
switch (type)
{
case BETRAY:
{
if (Formulas.getInstance().calcSkillSuccess(activeChar, target, skill, ss, sps, bss))
skill.getEffects(activeChar, target);
else
{
SystemMessage sm = new SystemMessage(SystemMessageId.S1_WAS_UNAFFECTED_BY_S2);
sm.addString(target.getName());
sm.addSkillName(skill.getId());
activeChar.sendPacket(sm);
}
break;
}
case FAKE_DEATH:
{
// stun/fakedeath is not mdef dependant, it depends on lvl difference, target CON and power of stun
skill.getEffects(activeChar, target);
break;
}
case ROOT:
case STUN:
{
if(target.reflectSkill(skill))
target = activeChar;
if (Formulas.getInstance().calcSkillSuccess(activeChar, target, skill, ss, sps, bss))
skill.getEffects(activeChar, target);
else
{
if (activeChar instanceof L2PcInstance)
{
SystemMessage sm = new SystemMessage(SystemMessageId.S1_WAS_UNAFFECTED_BY_S2);
sm.addString(target.getName());
sm.addSkillName(skill.getDisplayId());
activeChar.sendPacket(sm);
}
}
break;
}
case SLEEP:
case PARALYZE: //use same as root for now
{
if(target.reflectSkill(skill))
target = activeChar;
if (Formulas.getInstance().calcSkillSuccess(activeChar, target, skill, ss, sps, bss))
skill.getEffects(activeChar, target);
else
{
if (activeChar instanceof L2PcInstance)
{
SystemMessage sm = new SystemMessage(SystemMessageId.S1_WAS_UNAFFECTED_BY_S2);
sm.addString(target.getName());
sm.addSkillName(skill.getDisplayId());
activeChar.sendPacket(sm);
}
}
break;
}
case CONFUSION:
case MUTE:
{
if(target.reflectSkill(skill))
target = activeChar;
if (Formulas.getInstance().calcSkillSuccess(activeChar, target, skill, ss, sps, bss))
{
// stop same type effect if avaiable
L2Effect[] effects = target.getAllEffects();
for (L2Effect e : effects)
if (e.getSkill().getSkillType() == type)
e.exit();
// then restart
// Make above skills mdef dependant
if (Formulas.getInstance().calcSkillSuccess(activeChar, target, skill, ss, sps, bss))
//if(Formulas.getInstance().calcMagicAffected(activeChar, target, skill))
skill.getEffects(activeChar, target);
else
{
if (activeChar instanceof L2PcInstance)
{
SystemMessage sm = new SystemMessage(SystemMessageId.S1_WAS_UNAFFECTED_BY_S2);
sm.addString(target.getName());
sm.addSkillName(skill.getDisplayId());
activeChar.sendPacket(sm);
}
}
}
else
{
if (activeChar instanceof L2PcInstance)
{
SystemMessage sm = new SystemMessage(SystemMessageId.S1_WAS_UNAFFECTED_BY_S2);
sm.addString(target.getName());
sm.addSkillName(skill.getDisplayId());
activeChar.sendPacket(sm);
}
}
break;
}
case CONFUSE_MOB_ONLY:
{
// do nothing if not on mob
if (target instanceof L2Attackable)
skill.getEffects(activeChar, target);
else
activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
break;
}
case AGGDAMAGE:
{
if (target instanceof L2Attackable)
target.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, activeChar, (int) ((150*skill.getPower())/(target.getLevel()+7)));
//TODO [Nemesiss] should this have 100% chance?
skill.getEffects(activeChar, target);
break;
}
case AGGREDUCE:
{
// these skills needs to be rechecked
if (target instanceof L2Attackable)
{
skill.getEffects(activeChar, target);
double aggdiff = ((L2Attackable)target).getHating(activeChar)
- target.calcStat(Stats.AGGRESSION, ((L2Attackable)target).getHating(activeChar), target, skill);
if (skill.getPower() > 0)
((L2Attackable)target).reduceHate(null, (int) skill.getPower());
else if (aggdiff > 0)
((L2Attackable)target).reduceHate(null, (int) aggdiff);
}
break;
}
case AGGREDUCE_CHAR:
{
// these skills needs to be rechecked
if (Formulas.getInstance().calcSkillSuccess(activeChar, target, skill, ss, sps, bss))
{
if (target instanceof L2Attackable)
{
L2Attackable targ = (L2Attackable)target;
targ.stopHating(activeChar);
if (targ.getMostHated() == null)
{
((L2AttackableAI)targ.getAI()).setGlobalAggro(-25);
targ.clearAggroList();
targ.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
targ.setWalking();
}
}
skill.getEffects(activeChar, target);
}
else
{
if (activeChar instanceof L2PcInstance)
{
SystemMessage sm = new SystemMessage(SystemMessageId.S1_WAS_UNAFFECTED_BY_S2);
sm.addString(target.getName());
sm.addSkillName(skill.getId());
activeChar.sendPacket(sm);
}
}
break;
}
case AGGREMOVE:
{
// these skills needs to be rechecked
if (target instanceof L2Attackable && !target.isRaid())
{
if (Formulas.getInstance().calcSkillSuccess(activeChar, target, skill, ss, sps, bss))
{
if (skill.getTargetType() == L2Skill.SkillTargetType.TARGET_UNDEAD)
{
if(target.isUndead())
((L2Attackable)target).reduceHate(null, ((L2Attackable)target).getHating(((L2Attackable)target).getMostHated()));
}
else
((L2Attackable)target).reduceHate(null, ((L2Attackable)target).getHating(((L2Attackable)target).getMostHated()));
}
else
{
if (activeChar instanceof L2PcInstance)
{
SystemMessage sm = new SystemMessage(SystemMessageId.S1_WAS_UNAFFECTED_BY_S2);
sm.addString(target.getName());
sm.addSkillName(skill.getId());
activeChar.sendPacket(sm);
}
}
}
break;
}
case UNBLEED:
{
negateEffect(target,SkillType.BLEED,skill.getPower());
break;
}
case UNPOISON:
{
negateEffect(target,SkillType.POISON,skill.getPower());
break;
}
case ERASE:
{
if (Formulas.getInstance().calcSkillSuccess(activeChar, target, skill, ss, sps, bss)
// doesn't affect siege golem or wild hog cannon
&& !(target instanceof L2SiegeSummonInstance)
)
{
L2PcInstance summonOwner = null;
L2Summon summonPet = null;
summonOwner = ((L2Summon)target).getOwner();
summonPet = summonOwner.getPet();
summonPet.unSummon(summonOwner);
SystemMessage sm = new SystemMessage(SystemMessageId.LETHAL_STRIKE);
summonOwner.sendPacket(sm);
}
else
{
if (activeChar instanceof L2PcInstance)
{
SystemMessage sm = new SystemMessage(SystemMessageId.S1_WAS_UNAFFECTED_BY_S2);
sm.addString(target.getName());
sm.addSkillName(skill.getId());
activeChar.sendPacket(sm);
}
}
break;
}
case MAGE_BANE:
{
for(L2Object t: targets)
{
L2Character target1 = (L2Character) t;
if(target1.reflectSkill(skill))
target1 = activeChar;
if (! Formulas.getInstance().calcSkillSuccess(activeChar, target1, skill, ss, sps, bss))
continue;
L2Effect[] effects = target1.getAllEffects();
for(L2Effect e: effects)
{
for(Func f: e.getStatFuncs())
{
if(f.stat == Stats.MAGIC_ATTACK || f.stat == Stats.MAGIC_ATTACK_SPEED)
{
e.exit();
break;
}
}
}
}
break;
}
case WARRIOR_BANE:
{
for(L2Object t: targets)
{
L2Character target1 = (L2Character) t;
if(target1.reflectSkill(skill))
target1 = activeChar;
if (! Formulas.getInstance().calcSkillSuccess(activeChar, target1, skill, ss, sps, bss))
continue;
L2Effect[] effects = target1.getAllEffects();
for(L2Effect e: effects)
{
for(Func f: e.getStatFuncs())
{
if(f.stat == Stats.RUN_SPEED || f.stat == Stats.POWER_ATTACK_SPEED)
{
e.exit();
break;
}
}
}
}
break;
}
case CANCEL:
case NEGATE:
{
if(target.reflectSkill(skill))
target = activeChar;
//TODO@ Rewrite it to properly use Formulas class.
// cancel
if (skill.getId() == 1056)
{
int lvlmodifier= 52+skill.getMagicLevel()*2;
if(skill.getMagicLevel()==12) lvlmodifier = (Experience.MAX_LEVEL - 1);
int landrate = 90;
if((target.getLevel() - lvlmodifier)>0) landrate = 90-4*(target.getLevel()-lvlmodifier);
landrate = (int) activeChar.calcStat(Stats.CANCEL_VULN, landrate, target, null);
if(Rnd.get(100) < landrate)
{
L2Effect[] effects = target.getAllEffects();
int maxfive = 5;
for (L2Effect e : effects)
{
if (e.getSkill().getId() != 4082 && e.getSkill().getId() != 4215 &&
e.getSkill().getId() != 4515 && e.getSkill().getId() != 110 && e.getSkill().getId() != 111 &&
e.getSkill().getId() != 1323 && e.getSkill().getId() != 1325) // Cannot cancel skills 4082, 4215, 4515, 110, 111, 1323, 1325
{
if(e.getSkill().getSkillType() != SkillType.BUFF) //sleep, slow, surrenders etc
e.exit();
else
{
int rate = 100;
int level = e.getLevel();
if (level > 0) rate = Integer.valueOf(150/(1 + level));
if (rate > 95) rate = 95;
else if (rate < 5) rate = 5;
if(Rnd.get(100) < rate) {
e.exit();
maxfive--;
if(maxfive == 0) break;
}
}
}
}
} else
{
if (activeChar instanceof L2PcInstance)
{
SystemMessage sm = new SystemMessage(SystemMessageId.S1_WAS_UNAFFECTED_BY_S2);
sm.addString(target.getName());
sm.addSkillName(skill.getDisplayId());
activeChar.sendPacket(sm);
}
}
break;
}