ManaHealByLevel.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 ManaHealByLevel extends L2Effect
  29. {
  30. public ManaHealByLevel(Env env, EffectTemplate template)
  31. {
  32. super(env, template);
  33. }
  34. @Override
  35. public L2EffectType getEffectType()
  36. {
  37. return L2EffectType.MANAHEAL_BY_LEVEL;
  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. //recharged mp influenced by difference between target level and skill level
  48. //if target is within 5 levels or lower then skill level there's no penalty.
  49. amount = target.calcStat(Stats.RECHARGE_MP_RATE, amount, null, null);
  50. if (target.getLevel() > getSkill().getMagicLevel())
  51. {
  52. int lvlDiff = target.getLevel() - getSkill().getMagicLevel();
  53. //if target is too high compared to skill level, the amount of recharged mp gradually decreases.
  54. if (lvlDiff == 6) //6 levels difference:
  55. amount *= 0.9; //only 90% effective
  56. else if (lvlDiff == 7)
  57. amount *= 0.8; //80%
  58. else if (lvlDiff == 8)
  59. amount *= 0.7; //70%
  60. else if (lvlDiff == 9)
  61. amount *= 0.6; //60%
  62. else if (lvlDiff == 10)
  63. amount *= 0.5; //50%
  64. else if (lvlDiff == 11)
  65. amount *= 0.4; //40%
  66. else if (lvlDiff == 12)
  67. amount *= 0.3; //30%
  68. else if (lvlDiff == 13)
  69. amount *= 0.2; //20%
  70. else if (lvlDiff == 14)
  71. amount *= 0.1; //10%
  72. else if (lvlDiff >= 15) //15 levels or more:
  73. amount = 0; //0mp recharged
  74. }
  75. amount = Math.min(amount, target.getMaxRecoverableMp() - target.getCurrentMp());
  76. // Prevent negative amounts
  77. if (amount < 0)
  78. amount = 0;
  79. // To prevent -value heals, set the value only if current mp is less than max recoverable.
  80. if (target.getCurrentMp() < target.getMaxRecoverableMp())
  81. target.setCurrentMp(amount + target.getCurrentMp());
  82. SystemMessage sm;
  83. if (getEffector().getObjectId() != target.getObjectId())
  84. {
  85. sm = SystemMessage.getSystemMessage(SystemMessageId.S2_MP_RESTORED_BY_C1);
  86. sm.addCharName(getEffector());
  87. }
  88. else
  89. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_MP_RESTORED);
  90. sm.addNumber((int) amount);
  91. target.sendPacket(sm);
  92. su.addAttribute(StatusUpdate.CUR_MP, (int) target.getCurrentMp());
  93. target.sendPacket(su);
  94. return true;
  95. }
  96. @Override
  97. public boolean onActionTime()
  98. {
  99. return false;
  100. }
  101. }