Manadam.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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.L2Skill.SkillType;
  23. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  25. import net.sf.l2j.gameserver.network.SystemMessageId;
  26. import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
  27. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  28. import net.sf.l2j.gameserver.skills.Formulas;
  29. /**
  30. * Class handling the Mana damage skill
  31. *
  32. * @author slyce
  33. */
  34. public class Manadam implements ISkillHandler
  35. {
  36. private static final SkillType[] SKILL_IDS = { SkillType.MANADAM };
  37. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  38. {
  39. L2Character target = null;
  40. if (activeChar.isAlikeDead())
  41. return;
  42. boolean ss = false;
  43. boolean bss = false;
  44. L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  45. if (weaponInst != null)
  46. {
  47. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  48. {
  49. bss = true;
  50. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  51. }
  52. else if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  53. {
  54. ss = true;
  55. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  56. }
  57. }
  58. // If there is no weapon equipped, check for an active summon.
  59. else if (activeChar instanceof L2Summon)
  60. {
  61. L2Summon activeSummon = (L2Summon) activeChar;
  62. if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  63. {
  64. bss = true;
  65. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  66. }
  67. else if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  68. {
  69. ss = true;
  70. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  71. }
  72. }
  73. else if (activeChar instanceof L2NpcInstance)
  74. {
  75. bss = ((L2NpcInstance) activeChar).isUsingShot(false);
  76. ss = ((L2NpcInstance) activeChar).isUsingShot(true);
  77. }
  78. for (int index = 0; index < targets.length; index++)
  79. {
  80. target = (L2Character) targets[index];
  81. if (target.reflectSkill(skill))
  82. target = activeChar;
  83. boolean acted = Formulas.getInstance().calcMagicAffected(activeChar, target, skill);
  84. if (target.isInvul() || !acted)
  85. {
  86. activeChar.sendPacket(new SystemMessage(SystemMessageId.MISSED_TARGET));
  87. }
  88. else
  89. {
  90. double damage = Formulas.getInstance().calcManaDam(activeChar, target, skill, ss, bss);
  91. double mp = (damage > target.getCurrentMp() ? target.getCurrentMp() : damage);
  92. target.reduceCurrentMp(mp);
  93. if (damage > 0)
  94. {
  95. if (target.isSleeping())
  96. {
  97. target.stopSleeping(null);
  98. }
  99. else if (target.isImmobileUntilAttacked())
  100. {
  101. target.stopImmobileUntilAttacked(null);
  102. }
  103. }
  104. if (target instanceof L2PcInstance)
  105. {
  106. StatusUpdate sump = new StatusUpdate(target.getObjectId());
  107. sump.addAttribute(StatusUpdate.CUR_MP, (int) target.getCurrentMp());
  108. // [L2J_JP EDIT START - TSL]
  109. target.sendPacket(sump);
  110. SystemMessage sm = new SystemMessage(SystemMessageId.S2_MP_HAS_BEEN_DRAINED_BY_S1);
  111. sm.addCharName(activeChar);
  112. sm.addNumber((int) mp);
  113. target.sendPacket(sm);
  114. }
  115. if (activeChar instanceof L2PcInstance)
  116. {
  117. SystemMessage sm2 = new SystemMessage(SystemMessageId.YOUR_OPPONENTS_MP_WAS_REDUCED_BY_S1);
  118. sm2.addNumber((int) mp);
  119. activeChar.sendPacket(sm2);
  120. }
  121. // [L2J_JP EDIT END - TSL]
  122. }
  123. }
  124. }
  125. public SkillType[] getSkillIds()
  126. {
  127. return SKILL_IDS;
  128. }
  129. }