Heal.java 4.8 KB

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