L2SkillDrain.java 8.4 KB

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