Heal.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.effecthandlers;
  20. import com.l2jserver.gameserver.model.ShotType;
  21. import com.l2jserver.gameserver.model.actor.L2Character;
  22. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  23. import com.l2jserver.gameserver.model.effects.L2Effect;
  24. import com.l2jserver.gameserver.model.effects.L2EffectType;
  25. import com.l2jserver.gameserver.model.items.L2Item;
  26. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  27. import com.l2jserver.gameserver.model.stats.Env;
  28. import com.l2jserver.gameserver.model.stats.Formulas;
  29. import com.l2jserver.gameserver.model.stats.Stats;
  30. import com.l2jserver.gameserver.network.SystemMessageId;
  31. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  32. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  33. /**
  34. * @author UnAfraid
  35. */
  36. public class Heal extends L2Effect
  37. {
  38. public Heal(Env env, EffectTemplate template)
  39. {
  40. super(env, template);
  41. }
  42. @Override
  43. public L2EffectType getEffectType()
  44. {
  45. return L2EffectType.HEAL;
  46. }
  47. @Override
  48. public boolean onStart()
  49. {
  50. L2Character target = getEffected();
  51. L2Character activeChar = getEffector();
  52. if ((target == null) || target.isDead() || target.isDoor())
  53. {
  54. return false;
  55. }
  56. double amount = calc();
  57. double staticShotBonus = 0;
  58. int mAtkMul = 1;
  59. boolean sps = getSkill().isMagic() && activeChar.isChargedShot(ShotType.SPIRITSHOTS);
  60. boolean bss = getSkill().isMagic() && activeChar.isChargedShot(ShotType.BLESSED_SPIRITSHOTS);
  61. if (((sps || bss) && (activeChar.isPlayer() && activeChar.getActingPlayer().isMageClass())) || activeChar.isSummon())
  62. {
  63. staticShotBonus = getSkill().getMpConsume(); // static bonus for spiritshots
  64. if (bss)
  65. {
  66. mAtkMul = 4;
  67. staticShotBonus *= 2.4; // static bonus for blessed spiritshots
  68. }
  69. else
  70. {
  71. mAtkMul = 2;
  72. }
  73. }
  74. else if ((sps || bss) && activeChar.isNpc())
  75. {
  76. staticShotBonus = 2.4 * getSkill().getMpConsume(); // always blessed spiritshots
  77. mAtkMul = 4;
  78. }
  79. else
  80. {
  81. // no static bonus
  82. // grade dynamic bonus
  83. final L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  84. if (weaponInst != null)
  85. {
  86. switch (weaponInst.getItem().getItemGrade())
  87. {
  88. case L2Item.CRYSTAL_S84:
  89. mAtkMul = 4;
  90. break;
  91. case L2Item.CRYSTAL_S80:
  92. mAtkMul = 2;
  93. break;
  94. }
  95. }
  96. // shot dynamic bonus
  97. if (bss)
  98. {
  99. mAtkMul *= 4; // 16x/8x/4x s84/s80/other
  100. }
  101. else
  102. {
  103. mAtkMul += 1; // 5x/3x/1x s84/s80/other
  104. }
  105. }
  106. if (!getSkill().isStatic())
  107. {
  108. amount += staticShotBonus + Math.sqrt(mAtkMul * activeChar.getMAtk(activeChar, null));
  109. amount *= target.calcStat(Stats.HEAL_EFFECTIVNESS, 100, null, null) / 100;
  110. // Healer proficiency (since CT1)
  111. amount *= activeChar.calcStat(Stats.HEAL_PROFICIENCY, 100, null, null) / 100;
  112. // Extra bonus (since CT1.5)
  113. amount += target.calcStat(Stats.HEAL_STATIC_BONUS, 0, null, null);
  114. // Heal critic, since CT2.3 Gracia Final
  115. if (getSkill().isMagic() && Formulas.calcMCrit(activeChar.getMCriticalHit(target, getSkill())))
  116. {
  117. amount *= 3;
  118. }
  119. }
  120. // Prevents overheal and negative amount
  121. amount = Math.max(Math.min(amount, target.getMaxRecoverableHp() - target.getCurrentHp()), 0);
  122. target.setCurrentHp(amount + target.getCurrentHp());
  123. StatusUpdate su = new StatusUpdate(target);
  124. su.addAttribute(StatusUpdate.CUR_HP, (int) target.getCurrentHp());
  125. target.sendPacket(su);
  126. if (target.isPlayer())
  127. {
  128. if (getSkill().getId() == 4051)
  129. {
  130. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.REJUVENATING_HP);
  131. target.sendPacket(sm);
  132. }
  133. else
  134. {
  135. if (activeChar.isPlayer() && (activeChar != target))
  136. {
  137. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S2_HP_RESTORED_BY_C1);
  138. sm.addString(activeChar.getName());
  139. sm.addNumber((int) amount);
  140. target.sendPacket(sm);
  141. }
  142. else
  143. {
  144. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_HP_RESTORED);
  145. sm.addNumber((int) amount);
  146. target.sendPacket(sm);
  147. }
  148. }
  149. }
  150. activeChar.setChargedShot(bss ? ShotType.BLESSED_SPIRITSHOTS : ShotType.SPIRITSHOTS, false);
  151. return true;
  152. }
  153. @Override
  154. public boolean onActionTime()
  155. {
  156. return false;
  157. }
  158. }