CpHealPercent.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 CpHealPercent extends L2Effect
  28. {
  29. public CpHealPercent(Env env, EffectTemplate template)
  30. {
  31. super(env, template);
  32. }
  33. @Override
  34. public L2EffectType getEffectType()
  35. {
  36. return L2EffectType.CPHEAL_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.getMaxCp();
  50. else
  51. amount = target.getMaxCp() * power / 100.0;
  52. amount = Math.min(amount, target.getMaxRecoverableCp() - target.getCurrentCp());
  53. // Prevent negative amounts
  54. if (amount < 0)
  55. amount = 0;
  56. // To prevent -value heals, set the value only if current Cp is less than max recoverable.
  57. if (target.getCurrentCp() < target.getMaxRecoverableCp())
  58. target.setCurrentCp(amount + target.getCurrentCp());
  59. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CP_WILL_BE_RESTORED);
  60. sm.addNumber((int) amount);
  61. target.sendPacket(sm);
  62. su.addAttribute(StatusUpdate.CUR_CP, (int) target.getCurrentCp());
  63. target.sendPacket(su);
  64. return true;
  65. }
  66. @Override
  67. public boolean onActionTime()
  68. {
  69. return false;
  70. }
  71. }