BalanceLife.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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.handler.SkillHandler;
  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.serverpackets.StatusUpdate;
  23. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  24. /**
  25. * This class ...
  26. *
  27. * @author earendil
  28. *
  29. * @version $Revision: 1.1.2.2.2.4 $ $Date: 2005/04/06 16:13:48 $
  30. */
  31. public class BalanceLife implements ISkillHandler
  32. {
  33. private static final L2SkillType[] SKILL_IDS =
  34. {
  35. L2SkillType.BALANCE_LIFE
  36. };
  37. /**
  38. *
  39. * @see com.l2jserver.gameserver.handler.ISkillHandler#useSkill(com.l2jserver.gameserver.model.actor.L2Character, com.l2jserver.gameserver.model.L2Skill, com.l2jserver.gameserver.model.L2Object[])
  40. */
  41. @Override
  42. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  43. {
  44. // L2Character activeChar = activeChar;
  45. // check for other effects
  46. ISkillHandler handler = SkillHandler.getInstance().getHandler(L2SkillType.BUFF);
  47. if (handler != null)
  48. handler.useSkill(activeChar, skill, targets);
  49. L2PcInstance player = null;
  50. if (activeChar instanceof L2PcInstance)
  51. player = (L2PcInstance) activeChar;
  52. double fullHP = 0;
  53. double currentHPs = 0;
  54. for (L2Character target: (L2Character[]) targets)
  55. {
  56. // We should not heal if char is dead/
  57. if (target == null || target.isDead())
  58. continue;
  59. // Player holding a cursed weapon can't be healed and can't heal
  60. if (target != activeChar)
  61. {
  62. if (target instanceof L2PcInstance && ((L2PcInstance) target).isCursedWeaponEquipped())
  63. continue;
  64. else if (player != null && player.isCursedWeaponEquipped())
  65. continue;
  66. }
  67. fullHP += target.getMaxHp();
  68. currentHPs += target.getCurrentHp();
  69. }
  70. double percentHP = currentHPs / fullHP;
  71. for (L2Character target: (L2Character[]) targets)
  72. {
  73. if (target == null || target.isDead())
  74. continue;
  75. // Player holding a cursed weapon can't be healed and can't heal
  76. if (target != activeChar)
  77. {
  78. if (target instanceof L2PcInstance && ((L2PcInstance) target).isCursedWeaponEquipped())
  79. continue;
  80. else if (player != null && player.isCursedWeaponEquipped())
  81. continue;
  82. }
  83. double newHP = target.getMaxHp() * percentHP;
  84. if (newHP > target.getCurrentHp()) // The target gets healed
  85. {
  86. // The heal will be blocked if the current hp passes the limit
  87. if (target.getCurrentHp() > target.getMaxRecoverableHp())
  88. newHP = target.getCurrentHp();
  89. // Else dont let the newHP pass the limit
  90. else if (newHP > target.getMaxRecoverableHp())
  91. newHP = target.getMaxRecoverableHp();
  92. }
  93. target.setCurrentHp(newHP);
  94. StatusUpdate su = new StatusUpdate(target);
  95. su.addAttribute(StatusUpdate.CUR_HP, (int) target.getCurrentHp());
  96. target.sendPacket(su);
  97. }
  98. }
  99. /**
  100. *
  101. * @see com.l2jserver.gameserver.handler.ISkillHandler#getSkillIds()
  102. */
  103. @Override
  104. public L2SkillType[] getSkillIds()
  105. {
  106. return SKILL_IDS;
  107. }
  108. }