CpHeal.java 2.3 KB

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