L2SkillDrain.java 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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.skills.l2skills;
  16. import net.sf.l2j.Config;
  17. import net.sf.l2j.gameserver.model.L2Character;
  18. import net.sf.l2j.gameserver.model.L2Effect;
  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.L2CubicInstance;
  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.network.SystemMessageId;
  27. import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
  28. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  29. import net.sf.l2j.gameserver.skills.Formulas;
  30. import net.sf.l2j.gameserver.templates.StatsSet;
  31. public class L2SkillDrain extends L2Skill {
  32. private float _absorbPart;
  33. private int _absorbAbs;
  34. public L2SkillDrain(StatsSet set)
  35. {
  36. super(set);
  37. _absorbPart = set.getFloat ("absorbPart", 0.f);
  38. _absorbAbs = set.getInteger("absorbAbs", 0);
  39. }
  40. @Override
  41. public void useSkill(L2Character activeChar, L2Object[] targets)
  42. {
  43. if (activeChar.isAlikeDead())
  44. return;
  45. boolean ss = false;
  46. boolean bss = false;
  47. for(int index = 0;index < targets.length;index++)
  48. {
  49. L2Character target = (L2Character)targets[index];
  50. if (target.isAlikeDead() && getTargetType() != SkillTargetType.TARGET_CORPSE_MOB)
  51. continue;
  52. if (activeChar != target && target.isInvul())
  53. continue; // No effect on invulnerable chars unless they cast it themselves.
  54. L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  55. if (weaponInst != null)
  56. {
  57. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  58. {
  59. bss = true;
  60. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  61. }
  62. else if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  63. {
  64. ss = true;
  65. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  66. }
  67. }
  68. // If there is no weapon equipped, check for an active summon.
  69. else if (activeChar instanceof L2Summon)
  70. {
  71. L2Summon activeSummon = (L2Summon)activeChar;
  72. if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  73. {
  74. bss = true;
  75. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  76. }
  77. else if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  78. {
  79. ss = true;
  80. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  81. }
  82. }
  83. else if (activeChar instanceof L2NpcInstance)
  84. {
  85. bss = ((L2NpcInstance)activeChar).isUsingShot(false);
  86. ss = ((L2NpcInstance)activeChar).isUsingShot(true);
  87. }
  88. boolean mcrit = Formulas.getInstance().calcMCrit(activeChar.getMCriticalHit(target, this));
  89. int damage = (int)Formulas.getInstance().calcMagicDam(
  90. activeChar, target, this, ss, bss, mcrit);
  91. int _drain = 0;
  92. int _cp = (int)target.getCurrentCp();
  93. int _hp = (int)target.getCurrentHp();
  94. if (_cp > 0)
  95. {
  96. if (damage < _cp)
  97. _drain = 0;
  98. else
  99. _drain = damage - _cp;
  100. }
  101. else if (damage > _hp)
  102. _drain = _hp;
  103. else
  104. _drain = damage;
  105. double hpAdd = _absorbAbs + _absorbPart * _drain;
  106. double hp = ((activeChar.getCurrentHp() + hpAdd) > activeChar.getMaxHp() ? activeChar.getMaxHp() : (activeChar.getCurrentHp() + hpAdd));
  107. activeChar.setCurrentHp(hp);
  108. StatusUpdate suhp = new StatusUpdate(activeChar.getObjectId());
  109. suhp.addAttribute(StatusUpdate.CUR_HP, (int)hp);
  110. activeChar.sendPacket(suhp);
  111. // Check to see if we should damage the target
  112. if (damage > 0 && (!target.isDead() || getTargetType() != SkillTargetType.TARGET_CORPSE_MOB))
  113. {
  114. // Manage attack or cast break of the target (calculating rate, sending message...)
  115. if (!target.isRaid() && Formulas.getInstance().calcAtkBreak(target, damage))
  116. {
  117. target.breakAttack();
  118. target.breakCast();
  119. }
  120. activeChar.sendDamageMessage(target, damage, mcrit, false, false);
  121. if (hasEffects() && getTargetType() != SkillTargetType.TARGET_CORPSE_MOB)
  122. {
  123. if (target.reflectSkill(this))
  124. {
  125. activeChar.stopSkillEffects(getId());
  126. getEffects((L2Character) null,activeChar);
  127. SystemMessage sm = new SystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  128. sm.addSkillName(getId());
  129. activeChar.sendPacket(sm);
  130. }
  131. else
  132. {
  133. // activate attacked effects, if any
  134. target.stopSkillEffects(getId());
  135. if (Formulas.getInstance().calcSkillSuccess(activeChar, target, this, false, ss, bss))
  136. getEffects(activeChar, target);
  137. else
  138. {
  139. SystemMessage sm = new SystemMessage(SystemMessageId.S1_WAS_UNAFFECTED_BY_S2);
  140. sm.addCharName(target);
  141. sm.addSkillName(this);
  142. activeChar.sendPacket(sm);
  143. }
  144. }
  145. }
  146. target.reduceCurrentHp(damage, activeChar);
  147. }
  148. // Check to see if we should do the decay right after the cast
  149. if (target.isDead() && getTargetType() == SkillTargetType.TARGET_CORPSE_MOB && target instanceof L2NpcInstance) {
  150. ((L2NpcInstance)target).endDecayTask();
  151. }
  152. }
  153. //effect self :]
  154. L2Effect effect = activeChar.getFirstEffect(getId());
  155. if (effect != null && effect.isSelfEffect())
  156. {
  157. //Replace old effect with new one.
  158. effect.exit();
  159. }
  160. // cast self effect if any
  161. getEffectsSelf(activeChar);
  162. }
  163. public void useCubicSkill(L2CubicInstance activeCubic, L2Object[] targets)
  164. {
  165. if (Config.DEBUG)
  166. _log.info("L2SkillDrain: useCubicSkill()");
  167. for(int index = 0;index < targets.length;index++)
  168. {
  169. L2Character target = (L2Character)targets[index];
  170. if (target.isAlikeDead() && getTargetType() != SkillTargetType.TARGET_CORPSE_MOB)
  171. continue;
  172. boolean mcrit = Formulas.getInstance().calcMCrit(activeCubic.getMCriticalHit(target, this));
  173. int damage = (int)Formulas.getInstance().calcMagicDam(activeCubic, target, this, mcrit);
  174. if (Config.DEBUG)
  175. _log.info("L2SkillDrain: useCubicSkill() -> damage = " + damage);
  176. double hpAdd = _absorbAbs + _absorbPart * damage;
  177. L2PcInstance owner = activeCubic.getOwner();
  178. double hp = ((owner.getCurrentHp() + hpAdd) > owner.getMaxHp() ? owner.getMaxHp() : (owner.getCurrentHp() + hpAdd));
  179. owner.setCurrentHp(hp);
  180. StatusUpdate suhp = new StatusUpdate(owner.getObjectId());
  181. suhp.addAttribute(StatusUpdate.CUR_HP, (int)hp);
  182. owner.sendPacket(suhp);
  183. // Check to see if we should damage the target
  184. if (damage > 0 && (!target.isDead() || getTargetType() != SkillTargetType.TARGET_CORPSE_MOB))
  185. {
  186. target.reduceCurrentHp(damage, activeCubic.getOwner());
  187. // Manage attack or cast break of the target (calculating rate, sending message...)
  188. if (!target.isRaid() && Formulas.getInstance().calcAtkBreak(target, damage)){
  189. target.breakAttack();
  190. target.breakCast();
  191. }
  192. owner.sendDamageMessage(target, damage, mcrit, false, false);
  193. }
  194. }
  195. }
  196. }