ManaHealByLevel.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.StatusUpdate;
  28. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  29. /**
  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 onStart()
  45. {
  46. L2Character target = getEffected();
  47. if ((target == null) || target.isDead() || target.isDoor())
  48. {
  49. return false;
  50. }
  51. StatusUpdate su = new StatusUpdate(target);
  52. double amount = calc();
  53. // recharged mp influenced by difference between target level and skill level
  54. // if target is within 5 levels or lower then skill level there's no penalty.
  55. amount = target.calcStat(Stats.RECHARGE_MP_RATE, amount, null, null);
  56. if (target.getLevel() > getSkill().getMagicLevel())
  57. {
  58. int lvlDiff = target.getLevel() - getSkill().getMagicLevel();
  59. // if target is too high compared to skill level, the amount of recharged mp gradually decreases.
  60. if (lvlDiff == 6)
  61. {
  62. amount *= 0.9; // only 90% effective
  63. }
  64. else if (lvlDiff == 7)
  65. {
  66. amount *= 0.8; // 80%
  67. }
  68. else if (lvlDiff == 8)
  69. {
  70. amount *= 0.7; // 70%
  71. }
  72. else if (lvlDiff == 9)
  73. {
  74. amount *= 0.6; // 60%
  75. }
  76. else if (lvlDiff == 10)
  77. {
  78. amount *= 0.5; // 50%
  79. }
  80. else if (lvlDiff == 11)
  81. {
  82. amount *= 0.4; // 40%
  83. }
  84. else if (lvlDiff == 12)
  85. {
  86. amount *= 0.3; // 30%
  87. }
  88. else if (lvlDiff == 13)
  89. {
  90. amount *= 0.2; // 20%
  91. }
  92. else if (lvlDiff == 14)
  93. {
  94. amount *= 0.1; // 10%
  95. }
  96. else if (lvlDiff >= 15)
  97. {
  98. amount = 0; // 0mp recharged
  99. }
  100. }
  101. // Prevents overheal and negative amount
  102. amount = Math.max(Math.min(amount, target.getMaxRecoverableMp() - target.getCurrentMp()), 0);
  103. target.setCurrentMp(amount + target.getCurrentMp());
  104. SystemMessage sm;
  105. if (getEffector().getObjectId() != target.getObjectId())
  106. {
  107. sm = SystemMessage.getSystemMessage(SystemMessageId.S2_MP_RESTORED_BY_C1);
  108. sm.addCharName(getEffector());
  109. }
  110. else
  111. {
  112. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_MP_RESTORED);
  113. }
  114. sm.addNumber((int) amount);
  115. target.sendPacket(sm);
  116. su.addAttribute(StatusUpdate.CUR_MP, (int) target.getCurrentMp());
  117. target.sendPacket(su);
  118. return true;
  119. }
  120. @Override
  121. public boolean onActionTime()
  122. {
  123. return false;
  124. }
  125. }