CpDam.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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.L2Npc;
  20. import com.l2jserver.gameserver.model.actor.L2Summon;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  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. public class CpDam implements ISkillHandler
  28. {
  29. private static final L2SkillType[] SKILL_IDS =
  30. {
  31. L2SkillType.CPDAM
  32. };
  33. @Override
  34. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  35. {
  36. if (activeChar.isAlikeDead())
  37. return;
  38. boolean ss = false;
  39. boolean sps = false;
  40. boolean bss = false;
  41. L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  42. if (weaponInst != null)
  43. {
  44. if (skill.isMagic())
  45. {
  46. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  47. {
  48. bss = true;
  49. }
  50. else if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  51. {
  52. sps = true;
  53. }
  54. }
  55. else if (weaponInst.getChargedSoulshot() == L2ItemInstance.CHARGED_SOULSHOT)
  56. {
  57. ss = true;
  58. }
  59. }
  60. // If there is no weapon equipped, check for an active summon.
  61. else if (activeChar instanceof L2Summon)
  62. {
  63. L2Summon activeSummon = (L2Summon) activeChar;
  64. if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  65. {
  66. bss = true;
  67. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  68. }
  69. else if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  70. {
  71. ss = true;
  72. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  73. }
  74. }
  75. else if (activeChar instanceof L2Npc)
  76. {
  77. ss = ((L2Npc) activeChar)._soulshotcharged;
  78. ((L2Npc) activeChar)._soulshotcharged = false;
  79. bss = ((L2Npc) activeChar)._spiritshotcharged;
  80. ((L2Npc) activeChar)._spiritshotcharged = false;
  81. }
  82. for (L2Character target: (L2Character[]) targets)
  83. {
  84. if (activeChar instanceof L2PcInstance && target instanceof L2PcInstance && ((L2PcInstance)target).isFakeDeath())
  85. {
  86. target.stopFakeDeath(true);
  87. }
  88. else if (target.isDead() || target.isInvul())
  89. {
  90. continue;
  91. }
  92. byte shld = Formulas.calcShldUse(activeChar, target, skill);
  93. int damage = (int) (target.getCurrentCp() - (target.getCurrentCp() - skill.getPower()));
  94. // Manage attack or cast break of the target (calculating rate, sending message...)
  95. if (!target.isRaid() && Formulas.calcAtkBreak(target, damage))
  96. {
  97. target.breakAttack();
  98. target.breakCast();
  99. }
  100. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  101. activeChar.sendDamageMessage(target, damage, false, false, false);
  102. target.setCurrentCp(target.getCurrentCp() - damage);
  103. }
  104. }
  105. @Override
  106. public L2SkillType[] getSkillIds()
  107. {
  108. return SKILL_IDS;
  109. }
  110. }