Heal.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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.SystemMessage;
  32. /**
  33. * Heal effect implementation.
  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 boolean calcSuccess()
  44. {
  45. return true;
  46. }
  47. @Override
  48. public L2EffectType getEffectType()
  49. {
  50. return L2EffectType.HEAL;
  51. }
  52. @Override
  53. public boolean isInstant()
  54. {
  55. return true;
  56. }
  57. @Override
  58. public boolean onStart()
  59. {
  60. L2Character target = getEffected();
  61. L2Character activeChar = getEffector();
  62. if ((target == null) || target.isDead() || target.isDoor())
  63. {
  64. return false;
  65. }
  66. double amount = calc();
  67. double staticShotBonus = 0;
  68. int mAtkMul = 1;
  69. boolean sps = getSkill().isMagic() && activeChar.isChargedShot(ShotType.SPIRITSHOTS);
  70. boolean bss = getSkill().isMagic() && activeChar.isChargedShot(ShotType.BLESSED_SPIRITSHOTS);
  71. if (((sps || bss) && (activeChar.isPlayer() && activeChar.getActingPlayer().isMageClass())) || activeChar.isSummon())
  72. {
  73. staticShotBonus = getSkill().getMpConsume(); // static bonus for spiritshots
  74. mAtkMul = bss ? 4 : 2;
  75. staticShotBonus *= bss ? 2.4 : 1.0;
  76. }
  77. else if ((sps || bss) && activeChar.isNpc())
  78. {
  79. staticShotBonus = 2.4 * getSkill().getMpConsume(); // always blessed spiritshots
  80. mAtkMul = 4;
  81. }
  82. else
  83. {
  84. // no static bonus
  85. // grade dynamic bonus
  86. final L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  87. if (weaponInst != null)
  88. {
  89. mAtkMul = weaponInst.getItem().getItemGrade() == L2Item.CRYSTAL_S84 ? 4 : weaponInst.getItem().getItemGrade() == L2Item.CRYSTAL_S80 ? 2 : 1;
  90. }
  91. // shot dynamic bonus
  92. mAtkMul = bss ? mAtkMul * 4 : mAtkMul + 1;
  93. }
  94. if (!getSkill().isStatic())
  95. {
  96. amount += staticShotBonus + Math.sqrt(mAtkMul * activeChar.getMAtk(activeChar, null));
  97. amount = target.calcStat(Stats.HEAL_EFFECT, amount, null, null);
  98. // Heal critic, since CT2.3 Gracia Final
  99. if (getSkill().isMagic() && Formulas.calcMCrit(activeChar.getMCriticalHit(target, getSkill())))
  100. {
  101. amount *= 3;
  102. }
  103. }
  104. // Prevents overheal and negative amount
  105. amount = Math.max(Math.min(amount, target.getMaxRecoverableHp() - target.getCurrentHp()), 0);
  106. if (amount != 0)
  107. {
  108. target.setCurrentHp(amount + target.getCurrentHp());
  109. }
  110. if (target.isPlayer())
  111. {
  112. if (getSkill().getId() == 4051)
  113. {
  114. target.sendPacket(SystemMessageId.REJUVENATING_HP);
  115. }
  116. else
  117. {
  118. if (activeChar.isPlayer() && (activeChar != target))
  119. {
  120. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S2_HP_RESTORED_BY_C1);
  121. sm.addString(activeChar.getName());
  122. sm.addNumber((int) amount);
  123. target.sendPacket(sm);
  124. }
  125. else
  126. {
  127. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_HP_RESTORED);
  128. sm.addNumber((int) amount);
  129. target.sendPacket(sm);
  130. }
  131. }
  132. }
  133. return true;
  134. }
  135. }