Mdam.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.skillhandlers;
  20. import java.util.logging.Level;
  21. import java.util.logging.LogRecord;
  22. import java.util.logging.Logger;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.gameserver.handler.ISkillHandler;
  25. import com.l2jserver.gameserver.model.L2Object;
  26. import com.l2jserver.gameserver.model.ShotType;
  27. import com.l2jserver.gameserver.model.actor.L2Character;
  28. import com.l2jserver.gameserver.model.effects.L2Effect;
  29. import com.l2jserver.gameserver.model.skills.L2Skill;
  30. import com.l2jserver.gameserver.model.skills.L2SkillType;
  31. import com.l2jserver.gameserver.model.stats.Env;
  32. import com.l2jserver.gameserver.model.stats.Formulas;
  33. import com.l2jserver.gameserver.network.SystemMessageId;
  34. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  35. public class Mdam implements ISkillHandler
  36. {
  37. protected static final Logger _log = Logger.getLogger(Mdam.class.getName());
  38. private static final Logger _logDamage = Logger.getLogger("damage");
  39. private static final L2SkillType[] SKILL_IDS =
  40. {
  41. L2SkillType.MDAM,
  42. L2SkillType.DEATHLINK
  43. };
  44. @Override
  45. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  46. {
  47. if (activeChar.isAlikeDead())
  48. {
  49. return;
  50. }
  51. boolean ss = skill.useSoulShot() && activeChar.isChargedShot(ShotType.SOULSHOTS);
  52. boolean sps = skill.useSpiritShot() && activeChar.isChargedShot(ShotType.SPIRITSHOTS);
  53. boolean bss = skill.useSpiritShot() && activeChar.isChargedShot(ShotType.BLESSED_SPIRITSHOTS);
  54. for (L2Character target : (L2Character[]) targets)
  55. {
  56. if (activeChar.isPlayer() && target.isPlayer() && target.getActingPlayer().isFakeDeath())
  57. {
  58. target.stopFakeDeath(true);
  59. }
  60. else if (target.isDead())
  61. {
  62. continue;
  63. }
  64. final boolean mcrit = Formulas.calcMCrit(activeChar.getMCriticalHit(target, skill));
  65. final byte shld = Formulas.calcShldUse(activeChar, target, skill);
  66. final byte reflect = Formulas.calcSkillReflect(target, skill);
  67. int damage = skill.isStaticDamage() ? (int) skill.getPower() : (int) Formulas.calcMagicDam(activeChar, target, skill, shld, sps, bss, mcrit);
  68. // Curse of Divinity Formula (each buff increase +30%)
  69. if (!skill.isStaticDamage() && skill.getDependOnTargetBuff())
  70. {
  71. damage *= (((target.getBuffCount() * 0.3) + 1.3) / 4);
  72. }
  73. if (!skill.isStaticDamage() && (skill.getMaxSoulConsumeCount() > 0) && activeChar.isPlayer())
  74. {
  75. // Souls Formula (each soul increase +4%)
  76. int chargedSouls = (activeChar.getActingPlayer().getChargedSouls() <= skill.getMaxSoulConsumeCount()) ? activeChar.getActingPlayer().getChargedSouls() : skill.getMaxSoulConsumeCount();
  77. damage *= 1 + (chargedSouls * 0.04);
  78. }
  79. // Possibility of a lethal strike
  80. Formulas.calcLethalHit(activeChar, target, skill);
  81. if (damage > 0)
  82. {
  83. // Manage attack or cast break of the target (calculating rate, sending message...)
  84. if (!target.isRaid() && Formulas.calcAtkBreak(target, damage))
  85. {
  86. target.breakAttack();
  87. target.breakCast();
  88. }
  89. // vengeance reflected damage
  90. // DS: because only skill using vengeanceMdam is Shield Deflect Magic
  91. // and for this skill no damage should pass to target, just hardcode it for now
  92. if ((reflect & Formulas.SKILL_REFLECT_VENGEANCE) != 0)
  93. {
  94. activeChar.reduceCurrentHp(damage, target, skill);
  95. }
  96. else
  97. {
  98. activeChar.sendDamageMessage(target, damage, mcrit, false, false);
  99. target.reduceCurrentHp(damage, activeChar, skill);
  100. }
  101. if (skill.hasEffects())
  102. {
  103. if ((reflect & Formulas.SKILL_REFLECT_SUCCEED) != 0) // reflect skill effects
  104. {
  105. activeChar.stopSkillEffects(skill.getId());
  106. skill.getEffects(target, activeChar);
  107. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  108. sm.addSkillName(skill);
  109. activeChar.sendPacket(sm);
  110. }
  111. else
  112. {
  113. // activate attacked effects, if any
  114. target.stopSkillEffects(skill.getId());
  115. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  116. {
  117. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  118. }
  119. else
  120. {
  121. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  122. sm.addCharName(target);
  123. sm.addSkillName(skill);
  124. activeChar.sendPacket(sm);
  125. }
  126. }
  127. }
  128. // Logging damage
  129. if (Config.LOG_GAME_DAMAGE && activeChar.isPlayable() && (damage > Config.LOG_GAME_DAMAGE_THRESHOLD))
  130. {
  131. LogRecord record = new LogRecord(Level.INFO, "");
  132. record.setParameters(new Object[]
  133. {
  134. activeChar,
  135. " did damage ",
  136. damage,
  137. skill,
  138. " to ",
  139. target
  140. });
  141. record.setLoggerName("mdam");
  142. _logDamage.log(record);
  143. }
  144. }
  145. }
  146. // self Effect :]
  147. if (skill.hasSelfEffects())
  148. {
  149. final L2Effect effect = activeChar.getFirstEffect(skill.getId());
  150. if ((effect != null) && effect.isSelfEffect())
  151. {
  152. // Replace old effect with new one.
  153. effect.exit();
  154. }
  155. skill.getEffectsSelf(activeChar);
  156. }
  157. activeChar.setChargedShot(bss ? ShotType.BLESSED_SPIRITSHOTS : ShotType.SPIRITSHOTS, false);
  158. if (skill.isSuicideAttack())
  159. {
  160. activeChar.doDie(activeChar);
  161. }
  162. }
  163. @Override
  164. public L2SkillType[] getSkillIds()
  165. {
  166. return SKILL_IDS;
  167. }
  168. }