Disablers.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.skillhandlers;
  20. import java.util.List;
  21. import java.util.logging.Logger;
  22. import com.l2jserver.gameserver.ai.CtrlEvent;
  23. import com.l2jserver.gameserver.ai.CtrlIntention;
  24. import com.l2jserver.gameserver.ai.L2AttackableAI;
  25. import com.l2jserver.gameserver.handler.ISkillHandler;
  26. import com.l2jserver.gameserver.model.L2Object;
  27. import com.l2jserver.gameserver.model.ShotType;
  28. import com.l2jserver.gameserver.model.actor.L2Attackable;
  29. import com.l2jserver.gameserver.model.actor.L2Character;
  30. import com.l2jserver.gameserver.model.actor.L2Summon;
  31. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  32. import com.l2jserver.gameserver.model.actor.instance.L2SiegeSummonInstance;
  33. import com.l2jserver.gameserver.model.effects.L2Effect;
  34. import com.l2jserver.gameserver.model.effects.L2EffectType;
  35. import com.l2jserver.gameserver.model.skills.L2Skill;
  36. import com.l2jserver.gameserver.model.skills.L2SkillType;
  37. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  38. import com.l2jserver.gameserver.model.stats.Env;
  39. import com.l2jserver.gameserver.model.stats.Formulas;
  40. import com.l2jserver.gameserver.model.stats.Stats;
  41. import com.l2jserver.gameserver.network.SystemMessageId;
  42. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  43. /**
  44. * This Handles Disabler skills
  45. * @author _drunk_
  46. */
  47. public class Disablers implements ISkillHandler
  48. {
  49. private static final L2SkillType[] SKILL_IDS =
  50. {
  51. L2SkillType.STUN,
  52. L2SkillType.ROOT,
  53. L2SkillType.SLEEP,
  54. L2SkillType.CONFUSION,
  55. L2SkillType.AGGDAMAGE,
  56. L2SkillType.AGGREDUCE,
  57. L2SkillType.AGGREDUCE_CHAR,
  58. L2SkillType.AGGREMOVE,
  59. L2SkillType.MUTE,
  60. L2SkillType.CONFUSE_MOB_ONLY,
  61. L2SkillType.PARALYZE,
  62. L2SkillType.ERASE,
  63. L2SkillType.BETRAY,
  64. L2SkillType.DISARM
  65. };
  66. protected static final Logger _log = Logger.getLogger(L2Skill.class.getName());
  67. @Override
  68. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  69. {
  70. L2SkillType type = skill.getSkillType();
  71. byte shld = 0;
  72. boolean ss = skill.useSoulShot() && activeChar.isChargedShot(ShotType.SOULSHOTS);
  73. boolean sps = skill.useSpiritShot() && activeChar.isChargedShot(ShotType.SPIRITSHOTS);
  74. boolean bss = skill.useSpiritShot() && activeChar.isChargedShot(ShotType.BLESSED_SPIRITSHOTS);
  75. for (L2Object obj : targets)
  76. {
  77. if (!(obj instanceof L2Character))
  78. {
  79. continue;
  80. }
  81. L2Character target = (L2Character) obj;
  82. if (target.isDead() || (target.isInvul() && !target.isParalyzed()))
  83. {
  84. continue;
  85. }
  86. shld = Formulas.calcShldUse(activeChar, target, skill);
  87. switch (type)
  88. {
  89. case BETRAY:
  90. {
  91. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  92. {
  93. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  94. }
  95. else
  96. {
  97. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  98. sm.addCharName(target);
  99. sm.addSkillName(skill);
  100. activeChar.sendPacket(sm);
  101. }
  102. break;
  103. }
  104. case ROOT:
  105. case DISARM:
  106. case STUN:
  107. case SLEEP:
  108. case PARALYZE:
  109. {
  110. if (Formulas.calcSkillReflect(target, skill) == Formulas.SKILL_REFLECT_SUCCEED)
  111. {
  112. target = activeChar;
  113. }
  114. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  115. {
  116. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  117. }
  118. else
  119. {
  120. if (activeChar.isPlayer())
  121. {
  122. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  123. sm.addCharName(target);
  124. sm.addSkillName(skill);
  125. activeChar.sendPacket(sm);
  126. }
  127. }
  128. break;
  129. }
  130. case CONFUSION:
  131. case MUTE:
  132. {
  133. if (Formulas.calcSkillReflect(target, skill) == Formulas.SKILL_REFLECT_SUCCEED)
  134. {
  135. target = activeChar;
  136. }
  137. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  138. {
  139. // stop same type effect if available
  140. List<L2Effect> effects = target.getAllEffects();
  141. for (L2Effect e : effects)
  142. {
  143. if ((e != null) && (e.getSkill() != null) && (e.getSkill().getSkillType() == type))
  144. {
  145. e.exit();
  146. }
  147. }
  148. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  149. }
  150. else
  151. {
  152. if (activeChar.isPlayer())
  153. {
  154. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  155. sm.addCharName(target);
  156. sm.addSkillName(skill);
  157. activeChar.sendPacket(sm);
  158. }
  159. }
  160. break;
  161. }
  162. case CONFUSE_MOB_ONLY:
  163. {
  164. // do nothing if not on mob
  165. if (target.isL2Attackable())
  166. {
  167. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  168. {
  169. List<L2Effect> effects = target.getAllEffects();
  170. for (L2Effect e : effects)
  171. {
  172. if (e.getSkill().getSkillType() == type)
  173. {
  174. e.exit();
  175. }
  176. }
  177. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  178. }
  179. else
  180. {
  181. if (activeChar.isPlayer())
  182. {
  183. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  184. sm.addCharName(target);
  185. sm.addSkillName(skill);
  186. activeChar.sendPacket(sm);
  187. }
  188. }
  189. }
  190. else
  191. {
  192. activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
  193. }
  194. break;
  195. }
  196. case AGGDAMAGE:
  197. {
  198. if (target.isL2Attackable())
  199. {
  200. target.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, activeChar, (int) ((150 * skill.getPower()) / (target.getLevel() + 7)));
  201. }
  202. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  203. // TODO: Remove this when lethal effect is done.
  204. Formulas.calcLethalHit(activeChar, target, skill);
  205. break;
  206. }
  207. case AGGREDUCE:
  208. {
  209. // these skills needs to be rechecked
  210. if (target.isL2Attackable())
  211. {
  212. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  213. double aggdiff = ((L2Attackable) target).getHating(activeChar) - target.calcStat(Stats.AGGRESSION, ((L2Attackable) target).getHating(activeChar), target, skill);
  214. if (skill.getPower() > 0)
  215. {
  216. ((L2Attackable) target).reduceHate(null, (int) skill.getPower());
  217. }
  218. else if (aggdiff > 0)
  219. {
  220. ((L2Attackable) target).reduceHate(null, (int) aggdiff);
  221. }
  222. }
  223. // when fail, target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, activeChar);
  224. break;
  225. }
  226. case AGGREDUCE_CHAR:
  227. {
  228. // these skills needs to be rechecked
  229. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  230. {
  231. if (target.isL2Attackable())
  232. {
  233. L2Attackable targ = (L2Attackable) target;
  234. targ.stopHating(activeChar);
  235. if ((targ.getMostHated() == null) && targ.hasAI() && (targ.getAI() instanceof L2AttackableAI))
  236. {
  237. ((L2AttackableAI) targ.getAI()).setGlobalAggro(-25);
  238. targ.clearAggroList();
  239. targ.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  240. targ.setWalking();
  241. }
  242. }
  243. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  244. }
  245. else
  246. {
  247. if (activeChar.isPlayer())
  248. {
  249. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  250. sm.addCharName(target);
  251. sm.addSkillName(skill);
  252. activeChar.sendPacket(sm);
  253. }
  254. target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, activeChar);
  255. }
  256. break;
  257. }
  258. case AGGREMOVE:
  259. {
  260. // these skills needs to be rechecked
  261. if (target.isL2Attackable() && !target.isRaid())
  262. {
  263. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  264. {
  265. if (skill.getTargetType() == L2TargetType.UNDEAD)
  266. {
  267. if (target.isUndead())
  268. {
  269. ((L2Attackable) target).reduceHate(null, ((L2Attackable) target).getHating(((L2Attackable) target).getMostHated()));
  270. }
  271. }
  272. else
  273. {
  274. ((L2Attackable) target).reduceHate(null, ((L2Attackable) target).getHating(((L2Attackable) target).getMostHated()));
  275. }
  276. }
  277. else
  278. {
  279. if (activeChar.isPlayer())
  280. {
  281. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  282. sm.addCharName(target);
  283. sm.addSkillName(skill);
  284. activeChar.sendPacket(sm);
  285. }
  286. target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, activeChar);
  287. }
  288. }
  289. else
  290. {
  291. target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, activeChar);
  292. }
  293. break;
  294. }
  295. case ERASE:
  296. {
  297. // Doesn't affect siege golem or wild hog cannon
  298. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss) && !(target instanceof L2SiegeSummonInstance))
  299. {
  300. final L2PcInstance summonOwner = ((L2Summon) target).getOwner();
  301. final L2Summon summon = summonOwner.getSummon();
  302. if (summon != null)
  303. {
  304. // TODO: Retail confirmation for Soul of the Phoenix required.
  305. if (summon.isPhoenixBlessed())
  306. {
  307. if (summon.isNoblesseBlessed())
  308. {
  309. summon.stopEffects(L2EffectType.NOBLESSE_BLESSING);
  310. }
  311. }
  312. else if (summon.isNoblesseBlessed())
  313. {
  314. summon.stopEffects(L2EffectType.NOBLESSE_BLESSING);
  315. }
  316. else
  317. {
  318. summon.stopAllEffectsExceptThoseThatLastThroughDeath();
  319. }
  320. summon.abortAttack();
  321. summon.abortCast();
  322. summon.unSummon(summonOwner);
  323. summonOwner.sendPacket(SystemMessageId.YOUR_SERVITOR_HAS_VANISHED);
  324. }
  325. }
  326. else
  327. {
  328. if (activeChar.isPlayer())
  329. {
  330. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  331. sm.addCharName(target);
  332. sm.addSkillName(skill);
  333. activeChar.sendPacket(sm);
  334. }
  335. }
  336. break;
  337. }
  338. }
  339. }
  340. // self Effect :]
  341. if (skill.hasSelfEffects())
  342. {
  343. final L2Effect effect = activeChar.getFirstEffect(skill.getId());
  344. if ((effect != null) && effect.isSelfEffect())
  345. {
  346. // Replace old effect with new one.
  347. effect.exit();
  348. }
  349. skill.getEffectsSelf(activeChar);
  350. }
  351. activeChar.setChargedShot(bss ? ShotType.BLESSED_SPIRITSHOTS : ShotType.SPIRITSHOTS, false);
  352. }
  353. @Override
  354. public L2SkillType[] getSkillIds()
  355. {
  356. return SKILL_IDS;
  357. }
  358. }