BalanceLife.java 3.6 KB

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