CpDam.java 4.1 KB

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