ManaHeal.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package handlers.skillhandlers;
  16. import com.l2jserver.gameserver.handler.ISkillHandler;
  17. import com.l2jserver.gameserver.model.L2Effect;
  18. import com.l2jserver.gameserver.model.L2Object;
  19. import com.l2jserver.gameserver.model.L2Skill;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  24. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  25. import com.l2jserver.gameserver.skills.Stats;
  26. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  27. /**
  28. * This class ...
  29. *
  30. * @version $Revision: 1.1.2.2.2.1 $ $Date: 2005/03/02 15:38:36 $
  31. */
  32. public class ManaHeal implements ISkillHandler
  33. {
  34. private static final L2SkillType[] SKILL_IDS =
  35. {
  36. L2SkillType.MANAHEAL,
  37. L2SkillType.MANARECHARGE,
  38. L2SkillType.MANA_BY_LEVEL
  39. };
  40. /**
  41. *
  42. * @see com.l2jserver.gameserver.handler.ISkillHandler#useSkill(com.l2jserver.gameserver.model.actor.L2Character, com.l2jserver.gameserver.model.L2Skill, com.l2jserver.gameserver.model.L2Object[])
  43. */
  44. public void useSkill(L2Character actChar, L2Skill skill, L2Object[] targets)
  45. {
  46. for (L2Character target: (L2Character[]) targets)
  47. {
  48. if (target.isInvul())
  49. continue;
  50. double mp = skill.getPower();
  51. switch (skill.getSkillType())
  52. {
  53. case MANARECHARGE:
  54. mp = target.calcStat(Stats.RECHARGE_MP_RATE, mp, null, null);
  55. break;
  56. case MANA_BY_LEVEL:
  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. mp = target.calcStat(Stats.RECHARGE_MP_RATE, mp, null, null);
  60. if (target.getLevel() > skill.getMagicLevel())
  61. {
  62. int lvlDiff = target.getLevel() - skill.getMagicLevel();
  63. //if target is too high compared to skill level, the amount of recharged mp gradually decreases.
  64. if (lvlDiff == 6) //6 levels difference:
  65. mp *= 0.9; //only 90% effective
  66. else if (lvlDiff == 7)
  67. mp *= 0.8; //80%
  68. else if (lvlDiff == 8)
  69. mp *= 0.7; //70%
  70. else if (lvlDiff == 9)
  71. mp *= 0.6; //60%
  72. else if (lvlDiff == 10)
  73. mp *= 0.5; //50%
  74. else if (lvlDiff == 11)
  75. mp *= 0.4; //40%
  76. else if (lvlDiff == 12)
  77. mp *= 0.3; //30%
  78. else if (lvlDiff == 13)
  79. mp *= 0.2; //20%
  80. else if (lvlDiff == 14)
  81. mp *= 0.1; //10%
  82. else if (lvlDiff >= 15) //15 levels or more:
  83. mp = 0; //0mp recharged
  84. }
  85. }
  86. //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
  87. mp = Math.min(mp, target.getMaxRecoverableMp() - target.getCurrentMp());
  88. // Prevent negative amounts
  89. if (mp < 0)
  90. mp = 0;
  91. target.setCurrentMp(mp + target.getCurrentMp());
  92. StatusUpdate sump = new StatusUpdate(target);
  93. sump.addAttribute(StatusUpdate.CUR_MP, (int) target.getCurrentMp());
  94. target.sendPacket(sump);
  95. SystemMessage sm;
  96. if (actChar instanceof L2PcInstance && actChar != target)
  97. {
  98. sm = SystemMessage.getSystemMessage(SystemMessageId.S2_MP_RESTORED_BY_C1);
  99. sm.addString(actChar.getName());
  100. sm.addNumber((int) mp);
  101. target.sendPacket(sm);
  102. }
  103. else
  104. {
  105. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_MP_RESTORED);
  106. sm.addNumber((int) mp);
  107. target.sendPacket(sm);
  108. }
  109. if (skill.hasEffects())
  110. {
  111. target.stopSkillEffects(skill.getId());
  112. skill.getEffects(actChar, target);
  113. sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  114. sm.addSkillName(skill);
  115. target.sendPacket(sm);
  116. }
  117. }
  118. if (skill.hasSelfEffects())
  119. {
  120. L2Effect effect = actChar.getFirstEffect(skill.getId());
  121. if (effect != null && effect.isSelfEffect())
  122. {
  123. //Replace old effect with new one.
  124. effect.exit();
  125. }
  126. // cast self effect if any
  127. skill.getEffectsSelf(actChar);
  128. }
  129. }
  130. /**
  131. *
  132. * @see com.l2jserver.gameserver.handler.ISkillHandler#getSkillIds()
  133. */
  134. public L2SkillType[] getSkillIds()
  135. {
  136. return SKILL_IDS;
  137. }
  138. }