HealOverTime.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.effects.EffectTemplate;
  17. import com.l2jserver.gameserver.model.effects.L2Effect;
  18. import com.l2jserver.gameserver.model.effects.L2EffectType;
  19. import com.l2jserver.gameserver.model.stats.Env;
  20. import com.l2jserver.gameserver.network.serverpackets.ExRegMax;
  21. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  22. public class HealOverTime extends L2Effect
  23. {
  24. public HealOverTime(Env env, EffectTemplate template)
  25. {
  26. super(env, template);
  27. }
  28. // Special constructor to steal this effect
  29. public HealOverTime(Env env, L2Effect effect)
  30. {
  31. super(env, effect);
  32. }
  33. @Override
  34. protected boolean effectCanBeStolen()
  35. {
  36. return true;
  37. }
  38. @Override
  39. public L2EffectType getEffectType()
  40. {
  41. return L2EffectType.HEAL_OVER_TIME;
  42. }
  43. @Override
  44. public boolean onStart()
  45. {
  46. if (getEffected().isPlayer())
  47. {
  48. getEffected().sendPacket(new ExRegMax(calc(), getTotalCount() * getAbnormalTime(), getAbnormalTime()));
  49. }
  50. return true;
  51. }
  52. @Override
  53. public boolean onActionTime()
  54. {
  55. if (getEffected().isDead())
  56. return false;
  57. else if (getEffected().isDoor())
  58. return false;
  59. double hp = getEffected().getCurrentHp();
  60. double maxhp = getEffected().getMaxRecoverableHp();
  61. // Not needed to set the HP and send update packet if player is already at max HP
  62. if (hp >= maxhp)
  63. return true;
  64. hp += calc();
  65. if (hp > maxhp)
  66. hp = maxhp;
  67. getEffected().setCurrentHp(hp);
  68. StatusUpdate suhp = new StatusUpdate(getEffected());
  69. suhp.addAttribute(StatusUpdate.CUR_HP, (int) hp);
  70. getEffected().sendPacket(suhp);
  71. return true;
  72. }
  73. }