Manadam.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package handlers.skillhandlers;
  16. import com.l2jserver.gameserver.handler.ISkillHandler;
  17. import com.l2jserver.gameserver.model.L2Object;
  18. import com.l2jserver.gameserver.model.ShotType;
  19. import com.l2jserver.gameserver.model.actor.L2Character;
  20. import com.l2jserver.gameserver.model.effects.L2Effect;
  21. import com.l2jserver.gameserver.model.skills.L2Skill;
  22. import com.l2jserver.gameserver.model.skills.L2SkillType;
  23. import com.l2jserver.gameserver.model.stats.Env;
  24. import com.l2jserver.gameserver.model.stats.Formulas;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  27. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  28. /**
  29. * Class handling the Mana damage skill
  30. * @author slyce
  31. */
  32. public class Manadam implements ISkillHandler
  33. {
  34. private static final L2SkillType[] SKILL_IDS =
  35. {
  36. L2SkillType.MANADAM
  37. };
  38. @Override
  39. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  40. {
  41. if (activeChar.isAlikeDead())
  42. {
  43. return;
  44. }
  45. boolean ss = skill.isPhysical() && activeChar.isChargedShot(ShotType.SOULSHOTS);
  46. boolean sps = skill.isMagic() && activeChar.isChargedShot(ShotType.SPIRITSHOTS);
  47. boolean bss = skill.isMagic() && activeChar.isChargedShot(ShotType.BLESSED_SPIRITSHOTS);
  48. for (L2Character target : (L2Character[]) targets)
  49. {
  50. if (Formulas.calcSkillReflect(target, skill) == Formulas.SKILL_REFLECT_SUCCEED)
  51. {
  52. target = activeChar;
  53. }
  54. boolean acted = Formulas.calcMagicAffected(activeChar, target, skill);
  55. if (target.isInvul() || !acted)
  56. {
  57. activeChar.sendPacket(SystemMessageId.MISSED_TARGET);
  58. }
  59. else
  60. {
  61. if (skill.hasEffects())
  62. {
  63. byte shld = Formulas.calcShldUse(activeChar, target, skill);
  64. target.stopSkillEffects(skill.getId());
  65. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  66. {
  67. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  68. }
  69. else
  70. {
  71. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  72. sm.addCharName(target);
  73. sm.addSkillName(skill);
  74. activeChar.sendPacket(sm);
  75. }
  76. }
  77. double damage = skill.isStaticDamage() ? skill.getPower() : Formulas.calcManaDam(activeChar, target, skill, ss, bss);
  78. if (!skill.isStaticDamage() && Formulas.calcMCrit(activeChar.getMCriticalHit(target, skill)))
  79. {
  80. damage *= 3.;
  81. activeChar.sendPacket(SystemMessageId.CRITICAL_HIT_MAGIC);
  82. }
  83. double mp = (damage > target.getCurrentMp() ? target.getCurrentMp() : damage);
  84. target.reduceCurrentMp(mp);
  85. if (damage > 0)
  86. {
  87. target.stopEffectsOnDamage(true);
  88. }
  89. if (target.isPlayer())
  90. {
  91. StatusUpdate sump = new StatusUpdate(target);
  92. sump.addAttribute(StatusUpdate.CUR_MP, (int) target.getCurrentMp());
  93. // [L2J_JP EDIT START - TSL]
  94. target.sendPacket(sump);
  95. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S2_MP_HAS_BEEN_DRAINED_BY_C1);
  96. sm.addCharName(activeChar);
  97. sm.addNumber((int) mp);
  98. target.sendPacket(sm);
  99. }
  100. if (activeChar.isPlayer())
  101. {
  102. SystemMessage sm2 = SystemMessage.getSystemMessage(SystemMessageId.YOUR_OPPONENTS_MP_WAS_REDUCED_BY_S1);
  103. sm2.addNumber((int) mp);
  104. activeChar.sendPacket(sm2);
  105. }
  106. // [L2J_JP EDIT END - TSL]
  107. }
  108. }
  109. if (skill.hasSelfEffects())
  110. {
  111. L2Effect effect = activeChar.getFirstEffect(skill.getId());
  112. if (effect != null && effect.isSelfEffect())
  113. {
  114. // Replace old effect with new one.
  115. effect.exit();
  116. }
  117. // cast self effect if any
  118. skill.getEffectsSelf(activeChar);
  119. }
  120. activeChar.setChargedShot(bss ? ShotType.BLESSED_SPIRITSHOTS : ShotType.SPIRITSHOTS, false);
  121. }
  122. @Override
  123. public L2SkillType[] getSkillIds()
  124. {
  125. return SKILL_IDS;
  126. }
  127. }