Heal.java 5.9 KB

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