ManaHealByLevel.java 3.8 KB

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