BalanceLife.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 net.sf.l2j.gameserver.handler.skillhandlers;
  16. import net.sf.l2j.gameserver.handler.ISkillHandler;
  17. import net.sf.l2j.gameserver.handler.SkillHandler;
  18. import net.sf.l2j.gameserver.model.L2Character;
  19. import net.sf.l2j.gameserver.model.L2Object;
  20. import net.sf.l2j.gameserver.model.L2Skill;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  22. import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
  23. import net.sf.l2j.gameserver.templates.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 net.sf.l2j.gameserver.handler.ISkillHandler#useSkill(net.sf.l2j.gameserver.model.L2Character, net.sf.l2j.gameserver.model.L2Skill, net.sf.l2j.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. try
  46. {
  47. ISkillHandler handler = SkillHandler.getInstance().getSkillHandler(L2SkillType.BUFF);
  48. if (handler != null)
  49. handler.useSkill(activeChar, skill, targets);
  50. }
  51. catch (Exception e)
  52. {
  53. }
  54. L2Character target = null;
  55. L2PcInstance player = null;
  56. if (activeChar instanceof L2PcInstance)
  57. player = (L2PcInstance) activeChar;
  58. double fullHP = 0;
  59. double currentHPs = 0;
  60. for (int index = 0; index < targets.length; index++)
  61. {
  62. target = (L2Character) targets[index];
  63. // We should not heal if char is dead
  64. if (target == null || target.isDead())
  65. continue;
  66. // Player holding a cursed weapon can't be healed and can't heal
  67. if (target != activeChar)
  68. {
  69. if (target instanceof L2PcInstance && ((L2PcInstance) target).isCursedWeaponEquipped())
  70. continue;
  71. else if (player != null && player.isCursedWeaponEquipped())
  72. continue;
  73. }
  74. fullHP += target.getMaxHp();
  75. currentHPs += target.getCurrentHp();
  76. }
  77. double percentHP = currentHPs / fullHP;
  78. for (int index = 0; index < targets.length; index++)
  79. {
  80. target = (L2Character) targets[index];
  81. double newHP = target.getMaxHp() * percentHP;
  82. double totalHeal = newHP - target.getCurrentHp();
  83. target.setCurrentHp(newHP);
  84. if (totalHeal > 0)
  85. target.setLastHealAmount((int) totalHeal);
  86. StatusUpdate su = new StatusUpdate(target.getObjectId());
  87. su.addAttribute(StatusUpdate.CUR_HP, (int) target.getCurrentHp());
  88. target.sendPacket(su);
  89. target.sendMessage("HP of the party has been balanced.");
  90. }
  91. }
  92. /**
  93. *
  94. * @see net.sf.l2j.gameserver.handler.ISkillHandler#getSkillIds()
  95. */
  96. public L2SkillType[] getSkillIds()
  97. {
  98. return SKILL_IDS;
  99. }
  100. }