Heal.java 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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.L2ItemInstance;
  20. import net.sf.l2j.gameserver.model.L2Object;
  21. import net.sf.l2j.gameserver.model.L2Skill;
  22. import net.sf.l2j.gameserver.model.L2Summon;
  23. import net.sf.l2j.gameserver.model.L2Skill.SkillType;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2DoorInstance;
  25. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  26. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  27. import net.sf.l2j.gameserver.model.actor.instance.L2SiegeFlagInstance;
  28. import net.sf.l2j.gameserver.network.SystemMessageId;
  29. import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
  30. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  31. import net.sf.l2j.gameserver.skills.Stats;
  32. /**
  33. * This class ...
  34. *
  35. * @version $Revision: 1.1.2.2.2.4 $ $Date: 2005/04/06 16:13:48 $
  36. */
  37. public class Heal implements ISkillHandler
  38. {
  39. // all the items ids that this handler knowns
  40. //private static Logger _log = Logger.getLogger(Heal.class.getName());
  41. /* (non-Javadoc)
  42. * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.L2PcInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
  43. */
  44. private static final SkillType[] SKILL_IDS = {SkillType.HEAL, SkillType.HEAL_PERCENT, SkillType.HEAL_STATIC};
  45. /* (non-Javadoc)
  46. * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.L2PcInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
  47. */
  48. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  49. {
  50. // L2Character activeChar = activeChar;
  51. //check for other effects
  52. try {
  53. ISkillHandler handler = SkillHandler.getInstance().getSkillHandler(SkillType.BUFF);
  54. if (handler != null)
  55. handler.useSkill(activeChar, skill, targets);
  56. }
  57. catch (Exception e) {}
  58. L2Character target = null;
  59. L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  60. L2PcInstance player = null;
  61. if (activeChar instanceof L2PcInstance)
  62. player = (L2PcInstance)activeChar;
  63. for (int index = 0; index < targets.length; index++)
  64. {
  65. target = (L2Character)targets[index];
  66. // We should not heal if char is dead
  67. if (target == null || target.isDead())
  68. continue;
  69. // Player holding a cursed weapon can't be healed and can't heal
  70. if (target != activeChar)
  71. {
  72. if (target instanceof L2PcInstance && ((L2PcInstance)target).isCursedWeaponEquipped())
  73. continue;
  74. else if (player != null && player.isCursedWeaponEquipped())
  75. continue;
  76. }
  77. double hp = skill.getPower();
  78. if (skill.getSkillType() == SkillType.HEAL_PERCENT)
  79. {
  80. hp = target.getMaxHp() * hp / 100.0;
  81. }
  82. else
  83. {
  84. //Added effect of SpS and Bsps
  85. if (weaponInst != null)
  86. {
  87. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  88. {
  89. hp *= 1.5;
  90. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  91. }
  92. else if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  93. {
  94. hp *= 1.3;
  95. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  96. }
  97. }
  98. // If there is no weapon equipped, check for an active summon.
  99. else if (activeChar instanceof L2Summon)
  100. {
  101. L2Summon activeSummon = (L2Summon)activeChar;
  102. if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  103. {
  104. hp *= 1.5;
  105. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  106. }
  107. else if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  108. {
  109. hp *= 1.3;
  110. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  111. }
  112. }
  113. else if (activeChar instanceof L2NpcInstance)
  114. {
  115. if(((L2NpcInstance)activeChar).isUsingShot(false)) hp *= 1.5;
  116. }
  117. }
  118. //int cLev = activeChar.getLevel();
  119. //hp += skill.getPower()/*+(Math.sqrt(cLev)*cLev)+cLev*/;
  120. if (skill.getSkillType() == SkillType.HEAL_STATIC)
  121. hp = skill.getPower();
  122. else if (skill.getSkillType() != SkillType.HEAL_PERCENT)
  123. hp *= target.calcStat(Stats.HEAL_EFFECTIVNESS, 100, null, null) / 100;
  124. // Healer proficiency (since CT1)
  125. hp *= activeChar.calcStat(Stats.HEAL_PROFICIENCY, 100, null, null) / 100;
  126. // Extra bonus (since CT1.5)
  127. if (!skill.isPotion())
  128. hp += target.calcStat(Stats.HEAL_STATIC_BONUS, 0, null, null);
  129. if (target instanceof L2DoorInstance || target instanceof L2SiegeFlagInstance)
  130. hp = 0;
  131. //from CT2 u will receive exact HP, u can't go over it, if u have full HP and u get HP buff, u will receive 0HP restored message
  132. if (target.getCurrentHp()+hp >= target.getMaxHp())
  133. hp = (target.getMaxHp()-(target.getCurrentHp()+hp));
  134. if (hp <0)
  135. hp = 0;
  136. target.setCurrentHp(hp + target.getCurrentHp());
  137. target.setLastHealAmount((int) hp);
  138. StatusUpdate su = new StatusUpdate(target.getObjectId());
  139. su.addAttribute(StatusUpdate.CUR_HP, (int)target.getCurrentHp());
  140. target.sendPacket(su);
  141. if (target instanceof L2PcInstance)
  142. {
  143. if (skill.getId() == 4051)
  144. {
  145. SystemMessage sm = new SystemMessage(SystemMessageId.REJUVENATING_HP);
  146. target.sendPacket(sm);
  147. }
  148. else
  149. {
  150. if (activeChar instanceof L2PcInstance && activeChar != target)
  151. {
  152. SystemMessage sm = new SystemMessage(SystemMessageId.S2_HP_RESTORED_BY_S1);
  153. sm.addString(activeChar.getName());
  154. sm.addNumber((int)hp);
  155. target.sendPacket(sm);
  156. }
  157. else
  158. {
  159. SystemMessage sm = new SystemMessage(SystemMessageId.S1_HP_RESTORED);
  160. sm.addNumber((int)hp);
  161. target.sendPacket(sm);
  162. }
  163. }
  164. }
  165. }
  166. }
  167. public SkillType[] getSkillIds()
  168. {
  169. return SKILL_IDS;
  170. }
  171. }