ManaHealByLevel.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (C) 2004-2013 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.actor.L2Character;
  21. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  22. import com.l2jserver.gameserver.model.effects.L2Effect;
  23. import com.l2jserver.gameserver.model.effects.L2EffectType;
  24. import com.l2jserver.gameserver.model.stats.Env;
  25. import com.l2jserver.gameserver.model.stats.Stats;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  28. /**
  29. * Mana Heal By Level effect implementation.
  30. * @author UnAfraid
  31. */
  32. public class ManaHealByLevel extends L2Effect
  33. {
  34. public ManaHealByLevel(Env env, EffectTemplate template)
  35. {
  36. super(env, template);
  37. }
  38. @Override
  39. public L2EffectType getEffectType()
  40. {
  41. return L2EffectType.MANAHEAL_BY_LEVEL;
  42. }
  43. @Override
  44. public boolean isInstant()
  45. {
  46. return true;
  47. }
  48. @Override
  49. public boolean onStart()
  50. {
  51. L2Character target = getEffected();
  52. if ((target == null) || target.isDead() || target.isDoor() || target.isInvul())
  53. {
  54. return false;
  55. }
  56. double amount = calc();
  57. // recharged mp influenced by difference between target level and skill level
  58. // if target is within 5 levels or lower then skill level there's no penalty.
  59. amount = target.calcStat(Stats.MANA_CHARGE, amount, null, null);
  60. if (target.getLevel() > getSkill().getMagicLevel())
  61. {
  62. int lvlDiff = target.getLevel() - getSkill().getMagicLevel();
  63. // if target is too high compared to skill level, the amount of recharged mp gradually decreases.
  64. if (lvlDiff == 6)
  65. {
  66. amount *= 0.9; // only 90% effective
  67. }
  68. else if (lvlDiff == 7)
  69. {
  70. amount *= 0.8; // 80%
  71. }
  72. else if (lvlDiff == 8)
  73. {
  74. amount *= 0.7; // 70%
  75. }
  76. else if (lvlDiff == 9)
  77. {
  78. amount *= 0.6; // 60%
  79. }
  80. else if (lvlDiff == 10)
  81. {
  82. amount *= 0.5; // 50%
  83. }
  84. else if (lvlDiff == 11)
  85. {
  86. amount *= 0.4; // 40%
  87. }
  88. else if (lvlDiff == 12)
  89. {
  90. amount *= 0.3; // 30%
  91. }
  92. else if (lvlDiff == 13)
  93. {
  94. amount *= 0.2; // 20%
  95. }
  96. else if (lvlDiff == 14)
  97. {
  98. amount *= 0.1; // 10%
  99. }
  100. else if (lvlDiff >= 15)
  101. {
  102. amount = 0; // 0mp recharged
  103. }
  104. }
  105. // Prevents overheal and negative amount
  106. amount = Math.max(Math.min(amount, target.getMaxRecoverableMp() - target.getCurrentMp()), 0);
  107. if (amount != 0)
  108. {
  109. target.setCurrentMp(amount + target.getCurrentMp());
  110. }
  111. SystemMessage sm;
  112. if (getEffector().getObjectId() != target.getObjectId())
  113. {
  114. sm = SystemMessage.getSystemMessage(SystemMessageId.S2_MP_RESTORED_BY_C1);
  115. sm.addCharName(getEffector());
  116. }
  117. else
  118. {
  119. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_MP_RESTORED);
  120. }
  121. sm.addNumber((int) amount);
  122. target.sendPacket(sm);
  123. return true;
  124. }
  125. }