Heal.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.skillhandlers;
  20. import com.l2jserver.gameserver.handler.ISkillHandler;
  21. import com.l2jserver.gameserver.handler.SkillHandler;
  22. import com.l2jserver.gameserver.model.L2Object;
  23. import com.l2jserver.gameserver.model.ShotType;
  24. import com.l2jserver.gameserver.model.actor.L2Character;
  25. import com.l2jserver.gameserver.model.actor.instance.L2SiegeFlagInstance;
  26. import com.l2jserver.gameserver.model.items.L2Item;
  27. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  28. import com.l2jserver.gameserver.model.skills.L2Skill;
  29. import com.l2jserver.gameserver.model.skills.L2SkillType;
  30. import com.l2jserver.gameserver.model.stats.Formulas;
  31. import com.l2jserver.gameserver.model.stats.Stats;
  32. import com.l2jserver.gameserver.network.SystemMessageId;
  33. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  34. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  35. public class Heal implements ISkillHandler
  36. {
  37. private static final L2SkillType[] SKILL_IDS =
  38. {
  39. L2SkillType.HEAL,
  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. {
  48. handler.useSkill(activeChar, skill, targets);
  49. }
  50. double power = skill.getPower();
  51. boolean sps = skill.isMagic() && activeChar.isChargedShot(ShotType.SPIRITSHOTS);
  52. boolean bss = skill.isMagic() && activeChar.isChargedShot(ShotType.BLESSED_SPIRITSHOTS);
  53. double staticShotBonus = 0;
  54. int mAtkMul = 1; // mAtk multiplier
  55. if (((sps || bss) && (activeChar.isPlayer() && activeChar.getActingPlayer().isMageClass())) || activeChar.isSummon())
  56. {
  57. staticShotBonus = skill.getMpConsume(); // static bonus for spiritshots
  58. if (bss)
  59. {
  60. mAtkMul = 4;
  61. staticShotBonus *= 2.4; // static bonus for blessed spiritshots
  62. }
  63. else
  64. {
  65. mAtkMul = 2;
  66. }
  67. }
  68. else if ((sps || bss) && activeChar.isNpc())
  69. {
  70. staticShotBonus = 2.4 * skill.getMpConsume(); // always blessed spiritshots
  71. mAtkMul = 4;
  72. }
  73. else
  74. {
  75. // no static bonus
  76. // grade dynamic bonus
  77. final L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  78. if (weaponInst != null)
  79. {
  80. switch (weaponInst.getItem().getItemGrade())
  81. {
  82. case L2Item.CRYSTAL_S84:
  83. mAtkMul = 4;
  84. break;
  85. case L2Item.CRYSTAL_S80:
  86. mAtkMul = 2;
  87. break;
  88. }
  89. }
  90. // shot dynamic bonus
  91. if (bss)
  92. {
  93. mAtkMul *= 4; // 16x/8x/4x s84/s80/other
  94. }
  95. else
  96. {
  97. mAtkMul += 1; // 5x/3x/1x s84/s80/other
  98. }
  99. }
  100. power += staticShotBonus + Math.sqrt(mAtkMul * activeChar.getMAtk(activeChar, null));
  101. activeChar.setChargedShot(bss ? ShotType.BLESSED_SPIRITSHOTS : ShotType.SPIRITSHOTS, false);
  102. double hp;
  103. for (L2Character target : (L2Character[]) targets)
  104. {
  105. // if skill power is "0 or less" don't show heal system message.
  106. if (skill.getPower() <= 0)
  107. {
  108. continue;
  109. }
  110. // We should not heal if char is dead/invul
  111. if ((target == null) || target.isDead() || target.isInvul())
  112. {
  113. continue;
  114. }
  115. if (target.isDoor() || (target instanceof L2SiegeFlagInstance))
  116. {
  117. continue;
  118. }
  119. // Player holding a cursed weapon can't be healed and can't heal
  120. if (target != activeChar)
  121. {
  122. if (target.isPlayer() && target.getActingPlayer().isCursedWeaponEquipped())
  123. {
  124. continue;
  125. }
  126. else if (activeChar.isPlayer() && activeChar.getActingPlayer().isCursedWeaponEquipped())
  127. {
  128. continue;
  129. }
  130. }
  131. switch (skill.getSkillType())
  132. {
  133. case HEAL_PERCENT:
  134. hp = (target.getMaxHp() * power) / 100.0;
  135. break;
  136. default:
  137. hp = power;
  138. hp *= target.calcStat(Stats.HEAL_EFFECTIVNESS, 100, null, null) / 100;
  139. }
  140. // Healer proficiency (since CT1)
  141. hp *= activeChar.calcStat(Stats.HEAL_PROFICIENCY, 100, null, null) / 100;
  142. // Extra bonus (since CT1.5)
  143. if (!skill.isStatic())
  144. {
  145. hp += target.calcStat(Stats.HEAL_STATIC_BONUS, 0, null, null);
  146. }
  147. // Heal critic, since CT2.3 Gracia Final
  148. if ((skill.getSkillType() == L2SkillType.HEAL) && !skill.isStatic() && Formulas.calcMCrit(activeChar.getMCriticalHit(target, skill)))
  149. {
  150. hp *= 3;
  151. }
  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. // Prevent negative amounts
  155. hp = Math.max(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.isPlayer())
  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.isPlayer() && (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. @Override
  187. public L2SkillType[] getSkillIds()
  188. {
  189. return SKILL_IDS;
  190. }
  191. }