Manadam.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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.actor.L2Character;
  19. import com.l2jserver.gameserver.model.actor.L2Summon;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.model.effects.L2Effect;
  22. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  23. import com.l2jserver.gameserver.model.skills.L2Skill;
  24. import com.l2jserver.gameserver.model.skills.L2SkillType;
  25. import com.l2jserver.gameserver.model.stats.Env;
  26. import com.l2jserver.gameserver.model.stats.Formulas;
  27. import com.l2jserver.gameserver.network.SystemMessageId;
  28. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  29. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  30. /**
  31. * Class handling the Mana damage skill
  32. * @author slyce
  33. */
  34. public class Manadam implements ISkillHandler
  35. {
  36. private static final L2SkillType[] SKILL_IDS =
  37. {
  38. L2SkillType.MANADAM
  39. };
  40. @Override
  41. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  42. {
  43. if (activeChar.isAlikeDead())
  44. return;
  45. boolean ss = false;
  46. boolean bss = false;
  47. L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  48. if (weaponInst != null)
  49. {
  50. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  51. {
  52. bss = true;
  53. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  54. }
  55. else if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  56. {
  57. ss = true;
  58. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  59. }
  60. }
  61. // If there is no weapon equipped, check for an active summon.
  62. else if (activeChar instanceof L2Summon)
  63. {
  64. L2Summon activeSummon = (L2Summon) activeChar;
  65. if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  66. {
  67. bss = true;
  68. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  69. }
  70. else if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  71. {
  72. ss = true;
  73. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  74. }
  75. }
  76. for (L2Character target: (L2Character[]) targets)
  77. {
  78. if (Formulas.calcSkillReflect(target, skill) == Formulas.SKILL_REFLECT_SUCCEED)
  79. target = activeChar;
  80. boolean acted = Formulas.calcMagicAffected(activeChar, target, skill);
  81. if (target.isInvul() || !acted)
  82. {
  83. activeChar.sendPacket(SystemMessageId.MISSED_TARGET);
  84. }
  85. else
  86. {
  87. if (skill.hasEffects())
  88. {
  89. byte shld = Formulas.calcShldUse(activeChar, target, skill);
  90. target.stopSkillEffects(skill.getId());
  91. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, false, ss, bss))
  92. skill.getEffects(activeChar, target, new Env(shld, ss, false, bss));
  93. else
  94. {
  95. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  96. sm.addCharName(target);
  97. sm.addSkillName(skill);
  98. activeChar.sendPacket(sm);
  99. }
  100. }
  101. double damage = skill.isStaticDamage() ? skill.getPower() : Formulas.calcManaDam(activeChar, target, skill, ss, bss);
  102. if (!skill.isStaticDamage() && Formulas.calcMCrit(activeChar.getMCriticalHit(target, skill)))
  103. {
  104. damage *= 3.;
  105. activeChar.sendPacket(SystemMessageId.CRITICAL_HIT_MAGIC);
  106. }
  107. double mp = (damage > target.getCurrentMp() ? target.getCurrentMp() : damage);
  108. target.reduceCurrentMp(mp);
  109. if (damage > 0)
  110. target.stopEffectsOnDamage(true);
  111. if (target instanceof L2PcInstance)
  112. {
  113. StatusUpdate sump = new StatusUpdate(target);
  114. sump.addAttribute(StatusUpdate.CUR_MP, (int) target.getCurrentMp());
  115. // [L2J_JP EDIT START - TSL]
  116. target.sendPacket(sump);
  117. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S2_MP_HAS_BEEN_DRAINED_BY_C1);
  118. sm.addCharName(activeChar);
  119. sm.addNumber((int) mp);
  120. target.sendPacket(sm);
  121. }
  122. if (activeChar instanceof L2PcInstance)
  123. {
  124. SystemMessage sm2 = SystemMessage.getSystemMessage(SystemMessageId.YOUR_OPPONENTS_MP_WAS_REDUCED_BY_S1);
  125. sm2.addNumber((int) mp);
  126. activeChar.sendPacket(sm2);
  127. }
  128. // [L2J_JP EDIT END - TSL]
  129. }
  130. }
  131. if (skill.hasSelfEffects())
  132. {
  133. L2Effect effect = activeChar.getFirstEffect(skill.getId());
  134. if (effect != null && effect.isSelfEffect())
  135. {
  136. //Replace old effect with new one.
  137. effect.exit();
  138. }
  139. // cast self effect if any
  140. skill.getEffectsSelf(activeChar);
  141. }
  142. }
  143. @Override
  144. public L2SkillType[] getSkillIds()
  145. {
  146. return SKILL_IDS;
  147. }
  148. }