BalanceLife.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  42. {
  43. // L2Character activeChar = activeChar;
  44. // check for other effects
  45. ISkillHandler handler = SkillHandler.getInstance().getSkillHandler(L2SkillType.BUFF);
  46. if (handler != null)
  47. handler.useSkill(activeChar, skill, targets);
  48. L2PcInstance player = null;
  49. if (activeChar instanceof L2PcInstance)
  50. player = (L2PcInstance) activeChar;
  51. double fullHP = 0;
  52. double currentHPs = 0;
  53. for (L2Character target: (L2Character[]) targets)
  54. {
  55. // We should not heal if char is dead/
  56. if (target == null || target.isDead())
  57. continue;
  58. // Player holding a cursed weapon can't be healed and can't heal
  59. if (target != activeChar)
  60. {
  61. if (target instanceof L2PcInstance && ((L2PcInstance) target).isCursedWeaponEquipped())
  62. continue;
  63. else if (player != null && player.isCursedWeaponEquipped())
  64. continue;
  65. }
  66. fullHP += target.getMaxHp();
  67. currentHPs += target.getCurrentHp();
  68. }
  69. double percentHP = currentHPs / fullHP;
  70. for (L2Character target: (L2Character[]) targets)
  71. {
  72. if (target == null || target.isDead())
  73. continue;
  74. // Player holding a cursed weapon can't be healed and can't heal
  75. if (target != activeChar)
  76. {
  77. if (target instanceof L2PcInstance && ((L2PcInstance) target).isCursedWeaponEquipped())
  78. continue;
  79. else if (player != null && player.isCursedWeaponEquipped())
  80. continue;
  81. }
  82. double newHP = target.getMaxHp() * percentHP;
  83. if (newHP > target.getCurrentHp()) // The target gets healed
  84. {
  85. // The heal will be blocked if the current hp passes the limit
  86. if (target.getCurrentHp() > target.getMaxRecoverableHp())
  87. newHP = target.getCurrentHp();
  88. // Else dont let the newHP pass the limit
  89. else if (newHP > target.getMaxRecoverableHp())
  90. newHP = target.getMaxRecoverableHp();
  91. }
  92. target.setCurrentHp(newHP);
  93. StatusUpdate su = new StatusUpdate(target);
  94. su.addAttribute(StatusUpdate.CUR_HP, (int) target.getCurrentHp());
  95. target.sendPacket(su);
  96. }
  97. }
  98. /**
  99. *
  100. * @see com.l2jserver.gameserver.handler.ISkillHandler#getSkillIds()
  101. */
  102. public L2SkillType[] getSkillIds()
  103. {
  104. return SKILL_IDS;
  105. }
  106. }