ManaHealByLevel.java 3.7 KB

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