Heal.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (C) 2004-2015 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.enums.ShotType;
  21. import com.l2jserver.gameserver.model.StatsSet;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.conditions.Condition;
  24. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  25. import com.l2jserver.gameserver.model.effects.L2EffectType;
  26. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  27. import com.l2jserver.gameserver.model.items.type.CrystalType;
  28. import com.l2jserver.gameserver.model.skills.BuffInfo;
  29. import com.l2jserver.gameserver.model.stats.Formulas;
  30. import com.l2jserver.gameserver.model.stats.Stats;
  31. import com.l2jserver.gameserver.network.SystemMessageId;
  32. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  33. /**
  34. * Heal effect implementation.
  35. * @author UnAfraid
  36. */
  37. public final class Heal extends AbstractEffect
  38. {
  39. private final double _power;
  40. public Heal(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  41. {
  42. super(attachCond, applyCond, set, params);
  43. _power = params.getDouble("power", 0);
  44. }
  45. @Override
  46. public L2EffectType getEffectType()
  47. {
  48. return L2EffectType.HEAL;
  49. }
  50. @Override
  51. public boolean isInstant()
  52. {
  53. return true;
  54. }
  55. @Override
  56. public void onStart(BuffInfo info)
  57. {
  58. L2Character target = info.getEffected();
  59. L2Character activeChar = info.getEffector();
  60. if ((target == null) || target.isDead() || target.isDoor() || target.isInvul())
  61. {
  62. return;
  63. }
  64. double amount = _power;
  65. double staticShotBonus = 0;
  66. int mAtkMul = 1;
  67. boolean sps = info.getSkill().isMagic() && activeChar.isChargedShot(ShotType.SPIRITSHOTS);
  68. boolean bss = info.getSkill().isMagic() && activeChar.isChargedShot(ShotType.BLESSED_SPIRITSHOTS);
  69. if (((sps || bss) && (activeChar.isPlayer() && activeChar.getActingPlayer().isMageClass())) || activeChar.isSummon())
  70. {
  71. staticShotBonus = info.getSkill().getMpConsume(); // static bonus for spiritshots
  72. mAtkMul = bss ? 4 : 2;
  73. staticShotBonus *= bss ? 2.4 : 1.0;
  74. }
  75. else if ((sps || bss) && activeChar.isNpc())
  76. {
  77. staticShotBonus = 2.4 * info.getSkill().getMpConsume(); // always blessed spiritshots
  78. mAtkMul = 4;
  79. }
  80. else
  81. {
  82. // no static bonus
  83. // grade dynamic bonus
  84. final L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  85. if (weaponInst != null)
  86. {
  87. mAtkMul = weaponInst.getItem().getItemGrade() == CrystalType.S84 ? 4 : weaponInst.getItem().getItemGrade() == CrystalType.S80 ? 2 : 1;
  88. }
  89. // shot dynamic bonus
  90. mAtkMul = bss ? mAtkMul * 4 : mAtkMul + 1;
  91. }
  92. if (!info.getSkill().isStatic())
  93. {
  94. amount += staticShotBonus + Math.sqrt(mAtkMul * activeChar.getMAtk(activeChar, null));
  95. amount = target.calcStat(Stats.HEAL_EFFECT, amount, null, null);
  96. // Heal critic, since CT2.3 Gracia Final
  97. if (info.getSkill().isMagic() && Formulas.calcMCrit(activeChar.getMCriticalHit(target, info.getSkill())))
  98. {
  99. amount *= 3;
  100. }
  101. }
  102. // Prevents overheal and negative amount
  103. amount = Math.max(Math.min(amount, target.getMaxRecoverableHp() - target.getCurrentHp()), 0);
  104. if (amount != 0)
  105. {
  106. target.setCurrentHp(amount + target.getCurrentHp());
  107. }
  108. if (target.isPlayer())
  109. {
  110. if (info.getSkill().getId() == 4051)
  111. {
  112. target.sendPacket(SystemMessageId.REJUVENATING_HP);
  113. }
  114. else
  115. {
  116. if (activeChar.isPlayer() && (activeChar != target))
  117. {
  118. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S2_HP_RESTORED_BY_C1);
  119. sm.addString(activeChar.getName());
  120. sm.addInt((int) amount);
  121. target.sendPacket(sm);
  122. }
  123. else
  124. {
  125. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_HP_RESTORED);
  126. sm.addInt((int) amount);
  127. target.sendPacket(sm);
  128. }
  129. }
  130. }
  131. }
  132. }