EffectHeal.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. *
  3. */
  4. package handlers.effecthandlers;
  5. import com.l2jserver.gameserver.model.L2Effect;
  6. import com.l2jserver.gameserver.model.L2ItemInstance;
  7. import com.l2jserver.gameserver.model.actor.L2Character;
  8. import com.l2jserver.gameserver.model.actor.L2Npc;
  9. import com.l2jserver.gameserver.model.actor.L2Summon;
  10. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  11. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  12. import com.l2jserver.gameserver.network.SystemMessageId;
  13. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  14. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  15. import com.l2jserver.gameserver.skills.Env;
  16. import com.l2jserver.gameserver.skills.Formulas;
  17. import com.l2jserver.gameserver.skills.Stats;
  18. import com.l2jserver.gameserver.templates.effects.EffectTemplate;
  19. import com.l2jserver.gameserver.templates.item.L2Item;
  20. import com.l2jserver.gameserver.templates.skills.L2EffectType;
  21. /**
  22. * @author UnAfraid
  23. */
  24. public class EffectHeal extends L2Effect
  25. {
  26. public EffectHeal(Env env, EffectTemplate template)
  27. {
  28. super(env, template);
  29. }
  30. @Override
  31. public L2EffectType getEffectType()
  32. {
  33. return L2EffectType.HEAL;
  34. }
  35. @Override
  36. public boolean onStart()
  37. {
  38. L2Character target = getEffected();
  39. L2Character activeChar = getEffector();
  40. if (target == null || target.isDead() || target instanceof L2DoorInstance)
  41. return false;
  42. double amount = calc();
  43. final L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  44. double staticShotBonus = 0;
  45. int mAtkMul = 1;
  46. if (weaponInst != null && weaponInst.getChargedSpiritshot() != L2ItemInstance.CHARGED_NONE)
  47. {
  48. if (activeChar instanceof L2PcInstance && ((L2PcInstance) activeChar).isMageClass())
  49. {
  50. staticShotBonus = getSkill().getMpConsume(); // static bonus for spiritshots
  51. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  52. {
  53. mAtkMul = 4;
  54. staticShotBonus *= 2.4; // static bonus for blessed spiritshots
  55. }
  56. else
  57. mAtkMul = 2;
  58. }
  59. else
  60. {
  61. // no static bonus
  62. // grade dynamic bonus
  63. switch (weaponInst.getItem().getItemGrade())
  64. {
  65. case L2Item.CRYSTAL_S84:
  66. mAtkMul = 4;
  67. break;
  68. case L2Item.CRYSTAL_S80:
  69. mAtkMul = 2;
  70. break;
  71. }
  72. // shot dynamic bonus
  73. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  74. mAtkMul *= 4; // 16x/8x/4x s84/s80/other
  75. else
  76. mAtkMul += 1; // 5x/3x/1x s84/s80/other
  77. }
  78. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  79. }
  80. // If there is no weapon equipped, check for an active summon.
  81. else if (activeChar instanceof L2Summon && ((L2Summon) activeChar).getChargedSpiritShot() != L2ItemInstance.CHARGED_NONE)
  82. {
  83. staticShotBonus = getSkill().getMpConsume(); // static bonus for spiritshots
  84. if (((L2Summon) activeChar).getChargedSpiritShot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  85. {
  86. staticShotBonus *= 2.4; // static bonus for blessed spiritshots
  87. mAtkMul = 4;
  88. }
  89. else
  90. mAtkMul = 2;
  91. ((L2Summon) activeChar).setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  92. }
  93. else if (activeChar instanceof L2Npc && ((L2Npc) activeChar)._spiritshotcharged)
  94. {
  95. staticShotBonus = 2.4 * getSkill().getMpConsume(); // always blessed spiritshots
  96. mAtkMul = 4;
  97. ((L2Npc) activeChar)._spiritshotcharged = false;
  98. }
  99. if (!getSkill().isStaticHeal())
  100. {
  101. amount += staticShotBonus + Math.sqrt(mAtkMul * activeChar.getMAtk(activeChar, null));
  102. amount *= target.calcStat(Stats.HEAL_EFFECTIVNESS, 100, null, null) / 100;
  103. // Healer proficiency (since CT1)
  104. amount *= activeChar.calcStat(Stats.HEAL_PROFICIENCY, 100, null, null) / 100;
  105. // Extra bonus (since CT1.5)
  106. if (!getSkill().isPotion())
  107. amount += target.calcStat(Stats.HEAL_STATIC_BONUS, 0, null, null);
  108. // Heal critic, since CT2.3 Gracia Final
  109. if (!getSkill().isPotion() && Formulas.calcMCrit(activeChar.getMCriticalHit(target, getSkill())))
  110. amount *= 3;
  111. }
  112. amount = Math.min(amount, target.getMaxRecoverableHp() - target.getCurrentHp());
  113. // Prevent negative amounts
  114. if (amount < 0)
  115. amount = 0;
  116. target.setCurrentHp(amount + target.getCurrentHp());
  117. StatusUpdate su = new StatusUpdate(target);
  118. su.addAttribute(StatusUpdate.CUR_HP, (int) target.getCurrentHp());
  119. target.sendPacket(su);
  120. if (target instanceof L2PcInstance)
  121. {
  122. if (getSkill().getId() == 4051)
  123. {
  124. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.REJUVENATING_HP);
  125. target.sendPacket(sm);
  126. }
  127. else
  128. {
  129. if (activeChar instanceof L2PcInstance && activeChar != target)
  130. {
  131. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S2_HP_RESTORED_BY_C1);
  132. sm.addString(activeChar.getName());
  133. sm.addNumber((int) amount);
  134. target.sendPacket(sm);
  135. }
  136. else
  137. {
  138. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_HP_RESTORED);
  139. sm.addNumber((int) amount);
  140. target.sendPacket(sm);
  141. }
  142. }
  143. }
  144. return true;
  145. }
  146. @Override
  147. public boolean onActionTime()
  148. {
  149. return false;
  150. }
  151. }