Manadam.java 5.7 KB

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