Heal.java 4.5 KB

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