Mdam.java 7.3 KB

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