Heal.java 5.0 KB

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