Heal.java 6.5 KB

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