Heal.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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.L2ItemInstance;
  19. import com.l2jserver.gameserver.model.L2Object;
  20. import com.l2jserver.gameserver.model.L2Skill;
  21. import com.l2jserver.gameserver.model.actor.L2Character;
  22. import com.l2jserver.gameserver.model.actor.L2Npc;
  23. import com.l2jserver.gameserver.model.actor.L2Summon;
  24. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.actor.instance.L2SiegeFlagInstance;
  27. import com.l2jserver.gameserver.network.SystemMessageId;
  28. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  29. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  30. import com.l2jserver.gameserver.skills.Formulas;
  31. import com.l2jserver.gameserver.skills.Stats;
  32. import com.l2jserver.gameserver.templates.item.L2Item;
  33. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  34. /**
  35. * This class ...
  36. *
  37. * @version $Revision: 1.1.2.2.2.4 $ $Date: 2005/04/06 16:13:48 $
  38. */
  39. public class Heal implements ISkillHandler
  40. {
  41. private static final L2SkillType[] SKILL_IDS =
  42. {
  43. L2SkillType.HEAL,
  44. L2SkillType.HEAL_STATIC
  45. };
  46. /**
  47. *
  48. * @see com.l2jserver.gameserver.handler.ISkillHandler#useSkill(com.l2jserver.gameserver.model.actor.L2Character, com.l2jserver.gameserver.model.L2Skill, com.l2jserver.gameserver.model.L2Object[])
  49. */
  50. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  51. {
  52. //check for other effects
  53. ISkillHandler handler = SkillHandler.getInstance().getSkillHandler(L2SkillType.BUFF);
  54. if (handler != null)
  55. handler.useSkill(activeChar, skill, targets);
  56. double power = skill.getPower();
  57. switch (skill.getSkillType())
  58. {
  59. case HEAL_STATIC:
  60. break;
  61. default:
  62. final L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  63. double staticShotBonus = 0;
  64. int mAtkMul = 1; // mAtk multiplier
  65. if (weaponInst != null
  66. && weaponInst.getChargedSpiritshot() != L2ItemInstance.CHARGED_NONE)
  67. {
  68. if (activeChar instanceof L2PcInstance && ((L2PcInstance)activeChar).isMageClass())
  69. {
  70. staticShotBonus = skill.getMpConsume(); // static bonus for spiritshots
  71. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  72. {
  73. mAtkMul = 4;
  74. staticShotBonus *= 2.4; // static bonus for blessed spiritshots
  75. }
  76. else
  77. mAtkMul = 2;
  78. }
  79. else
  80. {
  81. // no static bonus
  82. // grade dynamic bonus
  83. switch (weaponInst.getItem().getItemGrade())
  84. {
  85. case L2Item.CRYSTAL_S84:
  86. mAtkMul = 4;
  87. break;
  88. case L2Item.CRYSTAL_S80:
  89. mAtkMul = 2;
  90. break;
  91. }
  92. // shot dynamic bonus
  93. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  94. mAtkMul *= 4; // 16x/8x/4x s84/s80/other
  95. else
  96. mAtkMul += 1; // 5x/3x/1x s84/s80/other
  97. }
  98. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  99. }
  100. // If there is no weapon equipped, check for an active summon.
  101. else if (activeChar instanceof L2Summon
  102. && ((L2Summon)activeChar).getChargedSpiritShot() != L2ItemInstance.CHARGED_NONE)
  103. {
  104. staticShotBonus = skill.getMpConsume(); // static bonus for spiritshots
  105. if (((L2Summon)activeChar).getChargedSpiritShot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  106. {
  107. staticShotBonus *= 2.4; // static bonus for blessed spiritshots
  108. mAtkMul = 4;
  109. }
  110. else
  111. mAtkMul = 2;
  112. ((L2Summon)activeChar).setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  113. }
  114. else if (activeChar instanceof L2Npc && ((L2Npc)activeChar)._spiritshotcharged)
  115. {
  116. staticShotBonus = 2.4 * skill.getMpConsume(); // always blessed spiritshots
  117. mAtkMul = 4;
  118. ((L2Npc)activeChar)._spiritshotcharged = false;
  119. }
  120. power += staticShotBonus + Math.sqrt(mAtkMul * activeChar.getMAtk(activeChar, null));
  121. }
  122. double hp;
  123. for (L2Character target: (L2Character[]) targets)
  124. {
  125. // We should not heal if char is dead/invul
  126. if (target == null || target.isDead() || target.isInvul())
  127. continue;
  128. if (target instanceof L2DoorInstance || target instanceof L2SiegeFlagInstance)
  129. continue;
  130. // Player holding a cursed weapon can't be healed and can't heal
  131. if (target != activeChar)
  132. {
  133. if (target instanceof L2PcInstance && ((L2PcInstance) target).isCursedWeaponEquipped())
  134. continue;
  135. else if (activeChar instanceof L2PcInstance && ((L2PcInstance)activeChar).isCursedWeaponEquipped())
  136. continue;
  137. }
  138. switch (skill.getSkillType())
  139. {
  140. case HEAL_PERCENT:
  141. hp = target.getMaxHp() * power / 100.0;
  142. break;
  143. default:
  144. hp = power;
  145. hp *= target.calcStat(Stats.HEAL_EFFECTIVNESS, 100, null, null) / 100;
  146. }
  147. // Healer proficiency (since CT1)
  148. hp *= activeChar.calcStat(Stats.HEAL_PROFICIENCY, 100, null, null) / 100;
  149. // Extra bonus (since CT1.5)
  150. if (!skill.isPotion())
  151. hp += target.calcStat(Stats.HEAL_STATIC_BONUS, 0, null, null);
  152. // Heal critic, since CT2.3 Gracia Final
  153. if(skill.getSkillType() == L2SkillType.HEAL && !skill.isPotion()
  154. && Formulas.calcMCrit(activeChar.getMCriticalHit(target, skill)))
  155. hp *= 3;
  156. //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
  157. hp = Math.min(hp, target.getMaxRecoverableHp() - target.getCurrentHp());
  158. if (hp < 0)
  159. hp = 0;
  160. target.setCurrentHp(hp + target.getCurrentHp());
  161. StatusUpdate su = new StatusUpdate(target);
  162. su.addAttribute(StatusUpdate.CUR_HP, (int) target.getCurrentHp());
  163. target.sendPacket(su);
  164. if (target instanceof L2PcInstance)
  165. {
  166. if (skill.getId() == 4051)
  167. {
  168. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.REJUVENATING_HP);
  169. target.sendPacket(sm);
  170. }
  171. else
  172. {
  173. if (activeChar instanceof L2PcInstance && activeChar != target)
  174. {
  175. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S2_HP_RESTORED_BY_C1);
  176. sm.addString(activeChar.getName());
  177. sm.addNumber((int) hp);
  178. target.sendPacket(sm);
  179. }
  180. else
  181. {
  182. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_HP_RESTORED);
  183. sm.addNumber((int) hp);
  184. target.sendPacket(sm);
  185. }
  186. }
  187. }
  188. }
  189. }
  190. /**
  191. *
  192. * @see com.l2jserver.gameserver.handler.ISkillHandler#getSkillIds()
  193. */
  194. public L2SkillType[] getSkillIds()
  195. {
  196. return SKILL_IDS;
  197. }
  198. }