CpDamPercent.java 4.2 KB

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