ManaHealByLevel.java 3.7 KB

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