CpDam.java 4.2 KB

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