L2SkillDrain.java 9.5 KB

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