ManaHealByLevel.java 3.8 KB

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