ManaHeal.java 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.model.stats.Stats;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  24. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  25. /**
  26. * @author UnAfraid
  27. */
  28. public class ManaHeal extends L2Effect
  29. {
  30. public ManaHeal(Env env, EffectTemplate template)
  31. {
  32. super(env, template);
  33. }
  34. @Override
  35. public L2EffectType getEffectType()
  36. {
  37. return L2EffectType.MANAHEAL;
  38. }
  39. @Override
  40. public boolean onStart()
  41. {
  42. L2Character target = getEffected();
  43. if (target == null || target.isDead() || target.isDoor())
  44. return false;
  45. StatusUpdate su = new StatusUpdate(target);
  46. double amount = calc();
  47. if (!getSkill().isStaticHeal())
  48. amount = target.calcStat(Stats.RECHARGE_MP_RATE, amount, null, null);
  49. amount = Math.min(amount, target.getMaxRecoverableMp() - target.getCurrentMp());
  50. // Prevent negative amounts
  51. if (amount < 0)
  52. amount = 0;
  53. // To prevent -value heals, set the value only if current mp is less than max recoverable.
  54. if (target.getCurrentMp() < target.getMaxRecoverableMp())
  55. target.setCurrentMp(amount + target.getCurrentMp());
  56. SystemMessage sm;
  57. if (getEffector().getObjectId() != target.getObjectId())
  58. {
  59. sm = SystemMessage.getSystemMessage(SystemMessageId.S2_MP_RESTORED_BY_C1);
  60. sm.addCharName(getEffector());
  61. }
  62. else
  63. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_MP_RESTORED);
  64. sm.addNumber((int) amount);
  65. target.sendPacket(sm);
  66. su.addAttribute(StatusUpdate.CUR_MP, (int) target.getCurrentMp());
  67. target.sendPacket(su);
  68. return true;
  69. }
  70. @Override
  71. public boolean onActionTime()
  72. {
  73. return false;
  74. }
  75. }