Mdam.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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 net.sf.l2j.gameserver.handler.skillhandlers;
  16. import java.util.logging.Logger;
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.handler.ISkillHandler;
  19. import net.sf.l2j.gameserver.lib.Log;
  20. import net.sf.l2j.gameserver.model.L2Character;
  21. import net.sf.l2j.gameserver.model.L2Effect;
  22. import net.sf.l2j.gameserver.model.L2ItemInstance;
  23. import net.sf.l2j.gameserver.model.L2Object;
  24. import net.sf.l2j.gameserver.model.L2Skill;
  25. import net.sf.l2j.gameserver.model.L2Summon;
  26. import net.sf.l2j.gameserver.model.L2Skill.SkillType;
  27. import net.sf.l2j.gameserver.model.actor.instance.L2CubicInstance;
  28. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  29. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  30. import net.sf.l2j.gameserver.model.actor.instance.L2RaidBossInstance;
  31. import net.sf.l2j.gameserver.network.SystemMessageId;
  32. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  33. import net.sf.l2j.gameserver.skills.Formulas;
  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. //private static Logger _log = Logger.getLogger(Mdam.class.getName());
  42. /* (non-Javadoc)
  43. * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.L2PcInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
  44. */
  45. protected static final Logger _log = Logger.getLogger(Mdam.class.getName());
  46. private static final SkillType[] SKILL_IDS = {SkillType.MDAM, SkillType.DEATHLINK};
  47. /* (non-Javadoc)
  48. * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.L2PcInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
  49. */
  50. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  51. {
  52. if (activeChar.isAlikeDead()) return;
  53. boolean ss = false;
  54. boolean bss = false;
  55. L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  56. /* if (activeChar instanceof L2PcInstance)
  57. {
  58. if (weaponInst == null)
  59. {
  60. SystemMessage sm2 = new SystemMessage(SystemMessage.S1_S2);
  61. sm2.addString("You must equip a weapon before casting a spell.");
  62. activeChar.sendPacket(sm2);
  63. return;
  64. }
  65. } */
  66. if (weaponInst != null)
  67. {
  68. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  69. {
  70. bss = true;
  71. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  72. }
  73. else if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  74. {
  75. ss = true;
  76. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  77. }
  78. }
  79. // If there is no weapon equipped, check for an active summon.
  80. else if (activeChar instanceof L2Summon)
  81. {
  82. L2Summon activeSummon = (L2Summon) activeChar;
  83. if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  84. {
  85. bss = true;
  86. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  87. }
  88. else if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  89. {
  90. ss = true;
  91. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  92. }
  93. }
  94. else if (activeChar instanceof L2NpcInstance)
  95. {
  96. bss = ((L2NpcInstance)activeChar).isUsingShot(false);
  97. ss = ((L2NpcInstance)activeChar).isUsingShot(true);
  98. }
  99. for (int index = 0; index < targets.length; index++)
  100. {
  101. L2Character target = (L2Character) targets[index];
  102. if (activeChar instanceof L2PcInstance && target instanceof L2PcInstance
  103. && target.isFakeDeath())
  104. {
  105. target.stopFakeDeath(null);
  106. }
  107. else if (target.isDead())
  108. {
  109. continue;
  110. }
  111. // if (skill != null)
  112. // if (skill.isOffensive())
  113. // {
  114. // boolean acted;
  115. // if (skill.getSkillType() == L2Skill.SkillType.DOT || skill.getSkillType() == L2Skill.SkillType.MDOT)
  116. // acted = Formulas.getInstance().calcSkillSuccess(
  117. // activeChar, target, skill);
  118. // else
  119. // acted = Formulas.getInstance().calcMagicAffected(
  120. // activeChar, target, skill);
  121. // if (!acted) {
  122. // activeChar.sendPacket(new SystemMessage(SystemMessage.MISSED_TARGET));
  123. // continue;
  124. // }
  125. //
  126. // }
  127. boolean mcrit = Formulas.getInstance().calcMCrit(activeChar.getMCriticalHit(target, skill));
  128. int damage = (int) Formulas.getInstance().calcMagicDam(activeChar, target, skill, ss, bss,
  129. mcrit);
  130. if (skill.getMaxSoulConsumeCount() > 0 && activeChar instanceof L2PcInstance && ((L2PcInstance) activeChar).getSouls() > 0)
  131. {
  132. switch (((L2PcInstance) activeChar).getSouls())
  133. {
  134. case 1:
  135. damage *= 1.10;
  136. break;
  137. case 2:
  138. damage *= 1.12;
  139. break;
  140. case 3:
  141. damage *= 1.15;
  142. break;
  143. case 4:
  144. damage *= 1.18;
  145. break;
  146. default:
  147. damage *= 1.20;
  148. break;
  149. }
  150. }
  151. if (damage > 5000 && activeChar instanceof L2PcInstance)
  152. {
  153. String name = "";
  154. if (target instanceof L2RaidBossInstance) name = "RaidBoss ";
  155. if (target instanceof L2NpcInstance)
  156. name += target.getName() + "(" + ((L2NpcInstance) target).getTemplate().npcId + ")";
  157. if (target instanceof L2PcInstance)
  158. name = target.getName() + "(" + target.getObjectId() + ") ";
  159. name += target.getLevel() + " lvl";
  160. Log.add(activeChar.getName() + "(" + activeChar.getObjectId() + ") "
  161. + activeChar.getLevel() + " lvl did damage " + damage + " with skill "
  162. + skill.getName() + "(" + skill.getId() + ") to " + name, "damage_mdam");
  163. }
  164. // Why are we trying to reduce the current target HP here?
  165. // Why not inside the below "if" condition, after the effects processing as it should be?
  166. // It doesn't seem to make sense for me. I'm moving this line inside the "if" condition, right after the effects processing...
  167. // [changed by nexus - 2006-08-15]
  168. //target.reduceCurrentHp(damage, activeChar);
  169. if (damage > 0)
  170. {
  171. // Manage attack or cast break of the target (calculating rate, sending message...)
  172. if (!target.isRaid() && Formulas.getInstance().calcAtkBreak(target, damage))
  173. {
  174. target.breakAttack();
  175. target.breakCast();
  176. }
  177. activeChar.sendDamageMessage(target, damage, mcrit, false, false);
  178. if (skill.hasEffects())
  179. {
  180. if (target.reflectSkill(skill))
  181. {
  182. activeChar.stopSkillEffects(skill.getId());
  183. skill.getEffects((L2Character) null, activeChar);
  184. SystemMessage sm = new SystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  185. sm.addSkillName(skill);
  186. activeChar.sendPacket(sm);
  187. }
  188. else
  189. {
  190. // activate attacked effects, if any
  191. target.stopSkillEffects(skill.getId());
  192. if (Formulas.getInstance().calcSkillSuccess(activeChar, target, skill, false, ss, bss))
  193. skill.getEffects(activeChar, target);
  194. else
  195. {
  196. SystemMessage sm = new SystemMessage(SystemMessageId.S1_WAS_UNAFFECTED_BY_S2);
  197. sm.addCharName(target);
  198. sm.addSkillName(skill);
  199. activeChar.sendPacket(sm);
  200. }
  201. }
  202. }
  203. target.reduceCurrentHp(damage, activeChar);
  204. }
  205. // Possibility of a lethal strike
  206. Formulas.getInstance().calcLethalHit(activeChar, target, skill);
  207. }
  208. // self Effect :]
  209. L2Effect effect = activeChar.getFirstEffect(skill.getId());
  210. if (effect != null && effect.isSelfEffect())
  211. {
  212. //Replace old effect with new one.
  213. effect.exit();
  214. }
  215. skill.getEffectsSelf(activeChar);
  216. if (skill.isSuicideAttack())
  217. activeChar.doDie(null);
  218. }
  219. public void useCubicSkill(L2CubicInstance activeCubic, L2Skill skill, L2Object[] targets)
  220. {
  221. for (int index = 0; index < targets.length; index++)
  222. {
  223. L2Character target = (L2Character) targets[index];
  224. if (target instanceof L2PcInstance && target.isAlikeDead() && target.isFakeDeath())
  225. {
  226. target.stopFakeDeath(null);
  227. }
  228. else if (target.isAlikeDead())
  229. {
  230. continue;
  231. }
  232. boolean mcrit = Formulas.getInstance().calcMCrit(activeCubic.getMCriticalHit(target, skill));
  233. int damage = (int) Formulas.getInstance().calcMagicDam(activeCubic, target, skill, mcrit);
  234. // if target is reflecting the skill then no damage is done
  235. if(target.reflectSkill(skill))
  236. damage = 0;
  237. if (Config.DEBUG)
  238. _log.info("L2SkillMdam: useCubicSkill() -> damage = " + damage);
  239. if (damage > 0)
  240. {
  241. // Manage attack or cast break of the target (calculating rate, sending message...)
  242. if (!target.isRaid() && Formulas.getInstance().calcAtkBreak(target, damage))
  243. {
  244. target.breakAttack();
  245. target.breakCast();
  246. }
  247. activeCubic.getOwner().sendDamageMessage(target, damage, mcrit, false, false);
  248. if (skill.hasEffects())
  249. {
  250. // activate attacked effects, if any
  251. target.stopSkillEffects(skill.getId());
  252. if (target.getFirstEffect(skill) != null)
  253. target.removeEffect(target.getFirstEffect(skill));
  254. if (Formulas.getInstance().calcCubicSkillSuccess(activeCubic, target, skill))
  255. skill.getEffects(activeCubic, target);
  256. else
  257. {
  258. SystemMessage sm = new SystemMessage(SystemMessageId.S1_WAS_UNAFFECTED_BY_S2);
  259. sm.addCharName(target);
  260. sm.addSkillName(skill.getDisplayId());
  261. activeCubic.getOwner().sendPacket(sm);
  262. }
  263. }
  264. target.reduceCurrentHp(damage, activeCubic.getOwner());
  265. }
  266. }
  267. }
  268. public SkillType[] getSkillIds()
  269. {
  270. return SKILL_IDS;
  271. }
  272. }