Heal.java 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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.handler.SkillHandler;
  18. import com.l2jserver.gameserver.model.L2Object;
  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.L2DoorInstance;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.actor.instance.L2SiegeFlagInstance;
  25. import com.l2jserver.gameserver.model.items.L2Item;
  26. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  27. import com.l2jserver.gameserver.model.skills.L2Skill;
  28. import com.l2jserver.gameserver.model.skills.L2SkillType;
  29. import com.l2jserver.gameserver.model.stats.Formulas;
  30. import com.l2jserver.gameserver.model.stats.Stats;
  31. import com.l2jserver.gameserver.network.SystemMessageId;
  32. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  33. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  34. public class Heal implements ISkillHandler
  35. {
  36. private static final L2SkillType[] SKILL_IDS =
  37. {
  38. L2SkillType.HEAL,
  39. L2SkillType.HEAL_STATIC
  40. };
  41. @Override
  42. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  43. {
  44. //check for other effects
  45. ISkillHandler handler = SkillHandler.getInstance().getHandler(L2SkillType.BUFF);
  46. if (handler != null)
  47. handler.useSkill(activeChar, skill, targets);
  48. double power = skill.getPower();
  49. switch (skill.getSkillType())
  50. {
  51. case HEAL_STATIC:
  52. break;
  53. default:
  54. final L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  55. double staticShotBonus = 0;
  56. int mAtkMul = 1; // mAtk multiplier
  57. if (weaponInst != null
  58. && weaponInst.getChargedSpiritshot() != L2ItemInstance.CHARGED_NONE)
  59. {
  60. if (activeChar instanceof L2PcInstance && ((L2PcInstance)activeChar).isMageClass())
  61. {
  62. staticShotBonus = skill.getMpConsume(); // static bonus for spiritshots
  63. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  64. {
  65. mAtkMul = 4;
  66. staticShotBonus *= 2.4; // static bonus for blessed spiritshots
  67. }
  68. else
  69. mAtkMul = 2;
  70. }
  71. else
  72. {
  73. // no static bonus
  74. // grade dynamic bonus
  75. switch (weaponInst.getItem().getItemGrade())
  76. {
  77. case L2Item.CRYSTAL_S84:
  78. mAtkMul = 4;
  79. break;
  80. case L2Item.CRYSTAL_S80:
  81. mAtkMul = 2;
  82. break;
  83. }
  84. // shot dynamic bonus
  85. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  86. mAtkMul *= 4; // 16x/8x/4x s84/s80/other
  87. else
  88. mAtkMul += 1; // 5x/3x/1x s84/s80/other
  89. }
  90. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  91. }
  92. // If there is no weapon equipped, check for an active summon.
  93. else if (activeChar instanceof L2Summon
  94. && ((L2Summon)activeChar).getChargedSpiritShot() != L2ItemInstance.CHARGED_NONE)
  95. {
  96. staticShotBonus = skill.getMpConsume(); // static bonus for spiritshots
  97. if (((L2Summon)activeChar).getChargedSpiritShot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  98. {
  99. staticShotBonus *= 2.4; // static bonus for blessed spiritshots
  100. mAtkMul = 4;
  101. }
  102. else
  103. mAtkMul = 2;
  104. ((L2Summon)activeChar).setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  105. }
  106. else if (activeChar instanceof L2Npc && ((L2Npc)activeChar)._spiritshotcharged)
  107. {
  108. staticShotBonus = 2.4 * skill.getMpConsume(); // always blessed spiritshots
  109. mAtkMul = 4;
  110. ((L2Npc)activeChar)._spiritshotcharged = false;
  111. }
  112. power += staticShotBonus + Math.sqrt(mAtkMul * activeChar.getMAtk(activeChar, null));
  113. }
  114. double hp;
  115. for (L2Character target: (L2Character[]) targets)
  116. {
  117. // We should not heal if char is dead/invul
  118. if (target == null || target.isDead() || target.isInvul())
  119. continue;
  120. if (target instanceof L2DoorInstance || target instanceof L2SiegeFlagInstance)
  121. continue;
  122. // Player holding a cursed weapon can't be healed and can't heal
  123. if (target != activeChar)
  124. {
  125. if (target instanceof L2PcInstance && ((L2PcInstance) target).isCursedWeaponEquipped())
  126. continue;
  127. else if (activeChar instanceof L2PcInstance && ((L2PcInstance)activeChar).isCursedWeaponEquipped())
  128. continue;
  129. }
  130. switch (skill.getSkillType())
  131. {
  132. case HEAL_PERCENT:
  133. hp = target.getMaxHp() * power / 100.0;
  134. break;
  135. default:
  136. hp = power;
  137. hp *= target.calcStat(Stats.HEAL_EFFECTIVNESS, 100, null, null) / 100;
  138. }
  139. // Healer proficiency (since CT1)
  140. hp *= activeChar.calcStat(Stats.HEAL_PROFICIENCY, 100, null, null) / 100;
  141. // Extra bonus (since CT1.5)
  142. if (!skill.isPotion())
  143. hp += target.calcStat(Stats.HEAL_STATIC_BONUS, 0, null, null);
  144. // Heal critic, since CT2.3 Gracia Final
  145. if(skill.getSkillType() == L2SkillType.HEAL && !skill.isPotion()
  146. && Formulas.calcMCrit(activeChar.getMCriticalHit(target, skill)))
  147. hp *= 3;
  148. //from CT2 u will receive exact HP, u can't go over it, if u have full HP and u get HP buff, u will receive 0HP restored message
  149. hp = Math.min(hp, target.getMaxRecoverableHp() - target.getCurrentHp());
  150. if (hp < 0)
  151. hp = 0;
  152. target.setCurrentHp(hp + target.getCurrentHp());
  153. StatusUpdate su = new StatusUpdate(target);
  154. su.addAttribute(StatusUpdate.CUR_HP, (int) target.getCurrentHp());
  155. target.sendPacket(su);
  156. if (target instanceof L2PcInstance)
  157. {
  158. if (skill.getId() == 4051)
  159. {
  160. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.REJUVENATING_HP);
  161. target.sendPacket(sm);
  162. }
  163. else
  164. {
  165. if (activeChar instanceof L2PcInstance && activeChar != target)
  166. {
  167. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S2_HP_RESTORED_BY_C1);
  168. sm.addString(activeChar.getName());
  169. sm.addNumber((int) hp);
  170. target.sendPacket(sm);
  171. }
  172. else
  173. {
  174. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_HP_RESTORED);
  175. sm.addNumber((int) hp);
  176. target.sendPacket(sm);
  177. }
  178. }
  179. }
  180. }
  181. }
  182. @Override
  183. public L2SkillType[] getSkillIds()
  184. {
  185. return SKILL_IDS;
  186. }
  187. }