Mdam.java 7.2 KB

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