CpDam.java 4.1 KB

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