Disablers.java 11 KB

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