HealPercent.java 2.8 KB

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