Mdam.java 7.2 KB

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