Manadam.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 net.sf.l2j.gameserver.handler.skillhandlers;
  16. import net.sf.l2j.gameserver.handler.ISkillHandler;
  17. import net.sf.l2j.gameserver.model.L2Character;
  18. import net.sf.l2j.gameserver.model.L2ItemInstance;
  19. import net.sf.l2j.gameserver.model.L2Object;
  20. import net.sf.l2j.gameserver.model.L2Skill;
  21. import net.sf.l2j.gameserver.model.L2Summon;
  22. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  23. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  24. import net.sf.l2j.gameserver.network.SystemMessageId;
  25. import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
  26. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  27. import net.sf.l2j.gameserver.skills.Formulas;
  28. import net.sf.l2j.gameserver.templates.L2SkillType;
  29. /**
  30. * Class handling the Mana damage skill
  31. *
  32. * @author slyce
  33. */
  34. public class Manadam implements ISkillHandler
  35. {
  36. private static final L2SkillType[] SKILL_IDS =
  37. {
  38. L2SkillType.MANADAM
  39. };
  40. /**
  41. *
  42. * @see net.sf.l2j.gameserver.handler.ISkillHandler#useSkill(net.sf.l2j.gameserver.model.L2Character, net.sf.l2j.gameserver.model.L2Skill, net.sf.l2j.gameserver.model.L2Object[])
  43. */
  44. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  45. {
  46. L2Character target = null;
  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. else if (activeChar instanceof L2NpcInstance)
  81. {
  82. bss = ((L2NpcInstance) activeChar).isUsingShot(false);
  83. ss = ((L2NpcInstance) activeChar).isUsingShot(true);
  84. }
  85. for (int index = 0; index < targets.length; index++)
  86. {
  87. target = (L2Character) targets[index];
  88. if (target.reflectSkill(skill))
  89. target = activeChar;
  90. boolean acted = Formulas.getInstance().calcMagicAffected(activeChar, target, skill);
  91. if (target.isInvul() || !acted)
  92. {
  93. activeChar.sendPacket(new SystemMessage(SystemMessageId.MISSED_TARGET));
  94. }
  95. else
  96. {
  97. double damage = Formulas.getInstance().calcManaDam(activeChar, target, skill, ss, bss);
  98. double mp = (damage > target.getCurrentMp() ? target.getCurrentMp() : damage);
  99. target.reduceCurrentMp(mp);
  100. if (damage > 0)
  101. {
  102. if (target.isSleeping())
  103. {
  104. target.stopSleeping(null);
  105. }
  106. else if (target.isImmobileUntilAttacked())
  107. {
  108. target.stopImmobileUntilAttacked(null);
  109. }
  110. }
  111. if (target instanceof L2PcInstance)
  112. {
  113. StatusUpdate sump = new StatusUpdate(target.getObjectId());
  114. sump.addAttribute(StatusUpdate.CUR_MP, (int) target.getCurrentMp());
  115. // [L2J_JP EDIT START - TSL]
  116. target.sendPacket(sump);
  117. SystemMessage sm = new SystemMessage(SystemMessageId.S2_MP_HAS_BEEN_DRAINED_BY_S1);
  118. sm.addCharName(activeChar);
  119. sm.addNumber((int) mp);
  120. target.sendPacket(sm);
  121. }
  122. if (activeChar instanceof L2PcInstance)
  123. {
  124. SystemMessage sm2 = new SystemMessage(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. }
  132. /**
  133. *
  134. * @see net.sf.l2j.gameserver.handler.ISkillHandler#getSkillIds()
  135. */
  136. public L2SkillType[] getSkillIds()
  137. {
  138. return SKILL_IDS;
  139. }
  140. }