Manadam.java 4.7 KB

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