HealPercent.java 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.actor.L2Character;
  17. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  18. import com.l2jserver.gameserver.model.effects.L2Effect;
  19. import com.l2jserver.gameserver.model.effects.L2EffectType;
  20. import com.l2jserver.gameserver.model.stats.Env;
  21. import com.l2jserver.gameserver.network.SystemMessageId;
  22. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  23. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  24. /**
  25. * @author UnAfraid
  26. */
  27. public class HealPercent extends L2Effect
  28. {
  29. public HealPercent(Env env, EffectTemplate template)
  30. {
  31. super(env, template);
  32. }
  33. @Override
  34. public L2EffectType getEffectType()
  35. {
  36. return L2EffectType.HEAL_PERCENT;
  37. }
  38. @Override
  39. public boolean onStart()
  40. {
  41. L2Character target = getEffected();
  42. if (target == null || target.isDead() || target.isDoor())
  43. return false;
  44. StatusUpdate su = new StatusUpdate(target);
  45. double amount = 0;
  46. double power = calc();
  47. boolean full = (power == 100.0);
  48. if (full)
  49. amount = target.getMaxHp();
  50. else
  51. amount = target.getMaxHp() * power / 100.0;
  52. amount = Math.min(amount, target.getMaxRecoverableHp() - target.getCurrentHp());
  53. // Prevent negative amounts
  54. if (amount < 0)
  55. amount = 0;
  56. // To prevent -value heals, set the value only if current hp is less than max recoverable.
  57. if (target.getCurrentHp() < target.getMaxRecoverableHp())
  58. target.setCurrentHp(amount + target.getCurrentHp());
  59. SystemMessage sm;
  60. if (getEffector().getObjectId() != target.getObjectId())
  61. {
  62. sm = SystemMessage.getSystemMessage(SystemMessageId.S2_HP_RESTORED_BY_C1);
  63. sm.addCharName(getEffector());
  64. }
  65. else
  66. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_HP_RESTORED);
  67. sm.addNumber((int)amount);
  68. target.sendPacket(sm);
  69. su.addAttribute(StatusUpdate.CUR_HP, (int) target.getCurrentHp());
  70. target.sendPacket(su);
  71. return true;
  72. }
  73. @Override
  74. public boolean onActionTime()
  75. {
  76. return false;
  77. }
  78. }