Heal.java 7.4 KB

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