Mdam.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 handlers.skillhandlers;
  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.handler.ISkillHandler;
  21. import com.l2jserver.gameserver.model.L2Object;
  22. import com.l2jserver.gameserver.model.ShotType;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.effects.L2Effect;
  25. import com.l2jserver.gameserver.model.skills.L2Skill;
  26. import com.l2jserver.gameserver.model.skills.L2SkillType;
  27. import com.l2jserver.gameserver.model.stats.Env;
  28. import com.l2jserver.gameserver.model.stats.Formulas;
  29. import com.l2jserver.gameserver.network.SystemMessageId;
  30. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  31. public class Mdam implements ISkillHandler
  32. {
  33. protected static final Logger _log = Logger.getLogger(Mdam.class.getName());
  34. private static final Logger _logDamage = Logger.getLogger("damage");
  35. private static final L2SkillType[] SKILL_IDS =
  36. {
  37. L2SkillType.MDAM,
  38. L2SkillType.DEATHLINK
  39. };
  40. @Override
  41. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  42. {
  43. if (activeChar.isAlikeDead())
  44. {
  45. return;
  46. }
  47. boolean ss = skill.isPhysical() && activeChar.isChargedShot(ShotType.SOULSHOTS);
  48. boolean sps = skill.isMagic() && activeChar.isChargedShot(ShotType.SPIRITSHOTS);
  49. boolean bss = skill.isMagic() && activeChar.isChargedShot(ShotType.BLESSED_SPIRITSHOTS);
  50. for (L2Character target : (L2Character[]) targets)
  51. {
  52. if (activeChar.isPlayer() && target.isPlayer() && target.getActingPlayer().isFakeDeath())
  53. {
  54. target.stopFakeDeath(true);
  55. }
  56. else if (target.isDead())
  57. {
  58. continue;
  59. }
  60. final boolean mcrit = Formulas.calcMCrit(activeChar.getMCriticalHit(target, skill));
  61. final byte shld = Formulas.calcShldUse(activeChar, target, skill);
  62. final byte reflect = Formulas.calcSkillReflect(target, skill);
  63. int damage = skill.isStaticDamage() ? (int) skill.getPower() : (int) Formulas.calcMagicDam(activeChar, target, skill, shld, sps, bss, mcrit);
  64. // Curse of Divinity Formula (each buff increase +30%)
  65. if (!skill.isStaticDamage() && skill.getDependOnTargetBuff())
  66. {
  67. damage *= (((target.getBuffCount() * 0.3) + 1.3) / 4);
  68. }
  69. if (!skill.isStaticDamage() && skill.getMaxSoulConsumeCount() > 0 && activeChar.isPlayer())
  70. {
  71. switch (activeChar.getActingPlayer().getSouls())
  72. {
  73. case 0:
  74. break;
  75. case 1:
  76. damage *= 1.10;
  77. break;
  78. case 2:
  79. damage *= 1.12;
  80. break;
  81. case 3:
  82. damage *= 1.15;
  83. break;
  84. case 4:
  85. damage *= 1.18;
  86. break;
  87. default:
  88. damage *= 1.20;
  89. break;
  90. }
  91. }
  92. // Possibility of a lethal strike
  93. Formulas.calcLethalHit(activeChar, target, skill);
  94. if (damage > 0)
  95. {
  96. // Manage attack or cast break of the target (calculating rate, sending message...)
  97. if (!target.isRaid() && Formulas.calcAtkBreak(target, damage))
  98. {
  99. target.breakAttack();
  100. target.breakCast();
  101. }
  102. // vengeance reflected damage
  103. // DS: because only skill using vengeanceMdam is Shield Deflect Magic
  104. // and for this skill no damage should pass to target, just hardcode it for now
  105. if ((reflect & Formulas.SKILL_REFLECT_VENGEANCE) != 0)
  106. {
  107. activeChar.reduceCurrentHp(damage, target, skill);
  108. }
  109. else
  110. {
  111. activeChar.sendDamageMessage(target, damage, mcrit, false, false);
  112. target.reduceCurrentHp(damage, activeChar, skill);
  113. }
  114. if (skill.hasEffects())
  115. {
  116. if ((reflect & Formulas.SKILL_REFLECT_SUCCEED) != 0) // reflect skill effects
  117. {
  118. activeChar.stopSkillEffects(skill.getId());
  119. skill.getEffects(target, activeChar);
  120. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  121. sm.addSkillName(skill);
  122. activeChar.sendPacket(sm);
  123. }
  124. else
  125. {
  126. // activate attacked effects, if any
  127. target.stopSkillEffects(skill.getId());
  128. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  129. {
  130. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  131. }
  132. else
  133. {
  134. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  135. sm.addCharName(target);
  136. sm.addSkillName(skill);
  137. activeChar.sendPacket(sm);
  138. }
  139. }
  140. }
  141. // Logging damage
  142. if (Config.LOG_GAME_DAMAGE && activeChar.isPlayable() && damage > Config.LOG_GAME_DAMAGE_THRESHOLD)
  143. {
  144. LogRecord record = new LogRecord(Level.INFO, "");
  145. record.setParameters(new Object[]
  146. {
  147. activeChar,
  148. " did damage ",
  149. damage,
  150. skill,
  151. " to ",
  152. target
  153. });
  154. record.setLoggerName("mdam");
  155. _logDamage.log(record);
  156. }
  157. }
  158. }
  159. // self Effect :]
  160. if (skill.hasSelfEffects())
  161. {
  162. final L2Effect effect = activeChar.getFirstEffect(skill.getId());
  163. if (effect != null && effect.isSelfEffect())
  164. {
  165. // Replace old effect with new one.
  166. effect.exit();
  167. }
  168. skill.getEffectsSelf(activeChar);
  169. }
  170. activeChar.setChargedShot(bss ? ShotType.BLESSED_SPIRITSHOTS : ShotType.SPIRITSHOTS, false);
  171. if (skill.isSuicideAttack())
  172. {
  173. activeChar.doDie(activeChar);
  174. }
  175. }
  176. @Override
  177. public L2SkillType[] getSkillIds()
  178. {
  179. return SKILL_IDS;
  180. }
  181. }