Heal.java 4.3 KB

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