ManaHealByLevel.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.skillhandlers;
  20. import com.l2jserver.gameserver.handler.ISkillHandler;
  21. import com.l2jserver.gameserver.model.L2Object;
  22. import com.l2jserver.gameserver.model.ShotType;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.effects.L2Effect;
  25. import com.l2jserver.gameserver.model.skills.L2Skill;
  26. import com.l2jserver.gameserver.model.skills.L2SkillType;
  27. import com.l2jserver.gameserver.model.stats.Stats;
  28. import com.l2jserver.gameserver.network.SystemMessageId;
  29. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  30. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  31. /**
  32. * @version $Revision: 1.1.2.2.2.1 $ $Date: 2005/03/02 15:38:36 $
  33. */
  34. public class ManaHealByLevel implements ISkillHandler
  35. {
  36. private static final L2SkillType[] SKILL_IDS =
  37. {
  38. L2SkillType.MANAHEAL_BY_LEVEL
  39. };
  40. @Override
  41. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  42. {
  43. for (L2Character target : (L2Character[]) targets)
  44. {
  45. if (target.isInvul())
  46. {
  47. continue;
  48. }
  49. double mp = skill.getPower();
  50. // recharged mp influenced by difference between target level and skill level
  51. // if target is within 5 levels or lower then skill level there's no penalty.
  52. mp = target.calcStat(Stats.RECHARGE_MP_RATE, mp, null, null);
  53. if (target.getLevel() > skill.getMagicLevel())
  54. {
  55. int lvlDiff = target.getLevel() - skill.getMagicLevel();
  56. // if target is too high compared to skill level, the amount of recharged mp gradually decreases.
  57. if (lvlDiff == 6)
  58. {
  59. mp *= 0.9; // only 90% effective
  60. }
  61. else if (lvlDiff == 7)
  62. {
  63. mp *= 0.8; // 80%
  64. }
  65. else if (lvlDiff == 8)
  66. {
  67. mp *= 0.7; // 70%
  68. }
  69. else if (lvlDiff == 9)
  70. {
  71. mp *= 0.6; // 60%
  72. }
  73. else if (lvlDiff == 10)
  74. {
  75. mp *= 0.5; // 50%
  76. }
  77. else if (lvlDiff == 11)
  78. {
  79. mp *= 0.4; // 40%
  80. }
  81. else if (lvlDiff == 12)
  82. {
  83. mp *= 0.3; // 30%
  84. }
  85. else if (lvlDiff == 13)
  86. {
  87. mp *= 0.2; // 20%
  88. }
  89. else if (lvlDiff == 14)
  90. {
  91. mp *= 0.1; // 10%
  92. }
  93. else if (lvlDiff >= 15)
  94. {
  95. mp = 0; // 0mp recharged
  96. }
  97. }
  98. // from CT2 u will receive exact MP, u can't go over it, if u have full MP and u get MP buff, u will receive 0MP restored message
  99. mp = Math.min(mp, target.getMaxRecoverableMp() - target.getCurrentMp());
  100. // Prevent negative amounts
  101. if (mp < 0)
  102. {
  103. mp = 0;
  104. }
  105. target.setCurrentMp(mp + target.getCurrentMp());
  106. StatusUpdate sump = new StatusUpdate(target);
  107. sump.addAttribute(StatusUpdate.CUR_MP, (int) target.getCurrentMp());
  108. target.sendPacket(sump);
  109. SystemMessage sm;
  110. // if skill power is "0 or less" don't show heal system message.
  111. if (skill.getPower() > 0)
  112. {
  113. if (activeChar.isPlayer() && (activeChar != target))
  114. {
  115. sm = SystemMessage.getSystemMessage(SystemMessageId.S2_MP_RESTORED_BY_C1);
  116. sm.addCharName(activeChar);
  117. }
  118. else
  119. {
  120. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_MP_RESTORED);
  121. }
  122. sm.addNumber((int) mp);
  123. target.sendPacket(sm);
  124. }
  125. if (skill.hasEffects())
  126. {
  127. target.stopSkillEffects(skill.getId());
  128. skill.getEffects(activeChar, target);
  129. sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  130. sm.addSkillName(skill);
  131. target.sendPacket(sm);
  132. }
  133. }
  134. if (skill.hasSelfEffects())
  135. {
  136. L2Effect effect = activeChar.getFirstEffect(skill.getId());
  137. if ((effect != null) && effect.isSelfEffect())
  138. {
  139. // Replace old effect with new one.
  140. effect.exit();
  141. }
  142. // cast self effect if any
  143. skill.getEffectsSelf(activeChar);
  144. }
  145. activeChar.setChargedShot(activeChar.isChargedShot(ShotType.BLESSED_SPIRITSHOTS) ? ShotType.BLESSED_SPIRITSHOTS : ShotType.SPIRITSHOTS, false);
  146. }
  147. @Override
  148. public L2SkillType[] getSkillIds()
  149. {
  150. return SKILL_IDS;
  151. }
  152. }