ManaHeal.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (C) 2004-2014 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.effecthandlers;
  20. import com.l2jserver.gameserver.model.StatsSet;
  21. import com.l2jserver.gameserver.model.actor.L2Character;
  22. import com.l2jserver.gameserver.model.conditions.Condition;
  23. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  24. import com.l2jserver.gameserver.model.effects.L2EffectType;
  25. import com.l2jserver.gameserver.model.skills.BuffInfo;
  26. import com.l2jserver.gameserver.model.stats.Stats;
  27. import com.l2jserver.gameserver.network.SystemMessageId;
  28. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  29. /**
  30. * Mana Heal effect implementation.
  31. * @author UnAfraid
  32. */
  33. public final class ManaHeal extends AbstractEffect
  34. {
  35. private final double _power;
  36. public ManaHeal(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  37. {
  38. super(attachCond, applyCond, set, params);
  39. _power = params.getDouble("power", 0);
  40. }
  41. @Override
  42. public L2EffectType getEffectType()
  43. {
  44. return L2EffectType.MANAHEAL;
  45. }
  46. @Override
  47. public boolean isInstant()
  48. {
  49. return true;
  50. }
  51. @Override
  52. public void onStart(BuffInfo info)
  53. {
  54. L2Character target = info.getEffected();
  55. if ((target == null) || target.isDead() || target.isDoor() || target.isInvul())
  56. {
  57. return;
  58. }
  59. double amount = _power;
  60. if (!info.getSkill().isStatic())
  61. {
  62. amount = target.calcStat(Stats.MANA_CHARGE, amount, null, null);
  63. }
  64. // Prevents overheal and negative amount
  65. amount = Math.max(Math.min(amount, target.getMaxRecoverableMp() - target.getCurrentMp()), 0);
  66. if (amount != 0)
  67. {
  68. target.setCurrentMp(amount + target.getCurrentMp());
  69. }
  70. SystemMessage sm;
  71. if (info.getEffector().getObjectId() != target.getObjectId())
  72. {
  73. sm = SystemMessage.getSystemMessage(SystemMessageId.S2_MP_RESTORED_BY_C1);
  74. sm.addCharName(info.getEffector());
  75. }
  76. else
  77. {
  78. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_MP_RESTORED);
  79. }
  80. sm.addInt((int) amount);
  81. target.sendPacket(sm);
  82. }
  83. }