Disablers.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  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.Logger;
  17. import com.l2jserver.gameserver.ai.CtrlEvent;
  18. import com.l2jserver.gameserver.ai.CtrlIntention;
  19. import com.l2jserver.gameserver.ai.L2AttackableAI;
  20. import com.l2jserver.gameserver.datatables.ExperienceTable;
  21. import com.l2jserver.gameserver.handler.ISkillHandler;
  22. import com.l2jserver.gameserver.handler.SkillHandler;
  23. import com.l2jserver.gameserver.model.L2Effect;
  24. import com.l2jserver.gameserver.model.L2Object;
  25. import com.l2jserver.gameserver.model.L2Skill;
  26. import com.l2jserver.gameserver.model.actor.L2Attackable;
  27. import com.l2jserver.gameserver.model.actor.L2Character;
  28. import com.l2jserver.gameserver.model.actor.L2Npc;
  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.item.instance.L2ItemInstance;
  33. import com.l2jserver.gameserver.network.SystemMessageId;
  34. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  35. import com.l2jserver.gameserver.skills.Env;
  36. import com.l2jserver.gameserver.skills.Formulas;
  37. import com.l2jserver.gameserver.skills.Stats;
  38. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  39. import com.l2jserver.gameserver.templates.skills.L2TargetType;
  40. import com.l2jserver.util.Rnd;
  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.FAKE_DEATH,
  59. L2SkillType.CONFUSE_MOB_ONLY,
  60. L2SkillType.NEGATE,
  61. L2SkillType.CANCEL_DEBUFF,
  62. L2SkillType.PARALYZE,
  63. L2SkillType.ERASE,
  64. L2SkillType.BETRAY,
  65. L2SkillType.DISARM
  66. };
  67. protected static final Logger _log = Logger.getLogger(L2Skill.class.getName());
  68. /**
  69. *
  70. * @see com.l2jserver.gameserver.handler.ISkillHandler#useSkill(com.l2jserver.gameserver.model.actor.L2Character, com.l2jserver.gameserver.model.L2Skill, com.l2jserver.gameserver.model.L2Object[])
  71. */
  72. @Override
  73. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  74. {
  75. L2SkillType type = skill.getSkillType();
  76. byte shld = 0;
  77. boolean ss = false;
  78. boolean sps = false;
  79. boolean bss = false;
  80. L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  81. if (weaponInst != null)
  82. {
  83. if (skill.isMagic())
  84. {
  85. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  86. {
  87. bss = true;
  88. if (skill.getId() != 1020) // vitalize
  89. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  90. }
  91. else if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  92. {
  93. sps = true;
  94. if (skill.getId() != 1020) // vitalize
  95. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  96. }
  97. }
  98. else
  99. ss = true;
  100. }
  101. // If there is no weapon equipped, check for an active summon.
  102. else if (activeChar instanceof L2Summon)
  103. {
  104. L2Summon activeSummon = (L2Summon) activeChar;
  105. if (skill.isMagic())
  106. {
  107. if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  108. {
  109. bss = true;
  110. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  111. }
  112. else if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  113. {
  114. sps = true;
  115. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  116. }
  117. }
  118. else
  119. ss = true;
  120. }
  121. else if (activeChar instanceof L2Npc)
  122. {
  123. ss = ((L2Npc) activeChar)._soulshotcharged;
  124. ((L2Npc) activeChar)._soulshotcharged = false;
  125. bss = ((L2Npc) activeChar)._spiritshotcharged;
  126. ((L2Npc) activeChar)._spiritshotcharged = false;
  127. }
  128. for (L2Object obj: targets)
  129. {
  130. if (!(obj instanceof L2Character))
  131. continue;
  132. L2Character target = (L2Character) obj;
  133. if (target.isDead() || ((target.isInvul() && type != L2SkillType.NEGATE) && !target.isParalyzed())) // bypass if target is null, dead or invul (excluding invul from Petrification)
  134. continue;
  135. shld = Formulas.calcShldUse(activeChar, target, skill);
  136. switch (type)
  137. {
  138. case BETRAY:
  139. {
  140. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  141. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  142. else
  143. {
  144. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  145. sm.addCharName(target);
  146. sm.addSkillName(skill);
  147. activeChar.sendPacket(sm);
  148. }
  149. break;
  150. }
  151. case FAKE_DEATH:
  152. {
  153. // stun/fakedeath is not mdef dependant, it depends on lvl difference, target CON and power of stun
  154. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  155. break;
  156. }
  157. case ROOT:
  158. case DISARM:
  159. case STUN:
  160. {
  161. if (Formulas.calcSkillReflect(target, skill) == Formulas.SKILL_REFLECT_SUCCEED)
  162. target = activeChar;
  163. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  164. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  165. else
  166. {
  167. if (activeChar instanceof L2PcInstance)
  168. {
  169. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  170. sm.addCharName(target);
  171. sm.addSkillName(skill);
  172. activeChar.sendPacket(sm);
  173. }
  174. }
  175. break;
  176. }
  177. case SLEEP:
  178. case PARALYZE: //use same as root for now
  179. {
  180. if (Formulas.calcSkillReflect(target, skill) == Formulas.SKILL_REFLECT_SUCCEED)
  181. target = activeChar;
  182. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  183. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  184. else
  185. {
  186. if (activeChar instanceof L2PcInstance)
  187. {
  188. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  189. sm.addCharName(target);
  190. sm.addSkillName(skill);
  191. activeChar.sendPacket(sm);
  192. }
  193. }
  194. break;
  195. }
  196. case CONFUSION:
  197. case MUTE:
  198. {
  199. if (Formulas.calcSkillReflect(target, skill) == Formulas.SKILL_REFLECT_SUCCEED)
  200. target = activeChar;
  201. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  202. {
  203. // stop same type effect if available
  204. L2Effect[] effects = target.getAllEffects();
  205. for (L2Effect e : effects)
  206. {
  207. if (e.getSkill().getSkillType() == type)
  208. e.exit();
  209. }
  210. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  211. }
  212. else
  213. {
  214. if (activeChar instanceof L2PcInstance)
  215. {
  216. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  217. sm.addCharName(target);
  218. sm.addSkillName(skill);
  219. activeChar.sendPacket(sm);
  220. }
  221. }
  222. break;
  223. }
  224. case CONFUSE_MOB_ONLY:
  225. {
  226. // do nothing if not on mob
  227. if (target instanceof L2Attackable)
  228. {
  229. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  230. {
  231. L2Effect[] effects = target.getAllEffects();
  232. for (L2Effect e : effects)
  233. {
  234. if (e.getSkill().getSkillType() == type)
  235. e.exit();
  236. }
  237. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  238. }
  239. else
  240. {
  241. if (activeChar instanceof L2PcInstance)
  242. {
  243. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  244. sm.addCharName(target);
  245. sm.addSkillName(skill);
  246. activeChar.sendPacket(sm);
  247. }
  248. }
  249. }
  250. else
  251. activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
  252. break;
  253. }
  254. case AGGDAMAGE:
  255. {
  256. if (target instanceof L2Attackable)
  257. target.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, activeChar, (int) ((150 * skill.getPower()) / (target.getLevel() + 7)));
  258. // TODO [Nemesiss] should this have 100% chance?
  259. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  260. break;
  261. }
  262. case AGGREDUCE:
  263. {
  264. // these skills needs to be rechecked
  265. if (target instanceof L2Attackable)
  266. {
  267. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  268. double aggdiff = ((L2Attackable) target).getHating(activeChar) - target.calcStat(Stats.AGGRESSION, ((L2Attackable) target).getHating(activeChar), target, skill);
  269. if (skill.getPower() > 0)
  270. ((L2Attackable) target).reduceHate(null, (int) skill.getPower());
  271. else if (aggdiff > 0)
  272. ((L2Attackable) target).reduceHate(null, (int) aggdiff);
  273. }
  274. // when fail, target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, activeChar);
  275. break;
  276. }
  277. case AGGREDUCE_CHAR:
  278. {
  279. // these skills needs to be rechecked
  280. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  281. {
  282. if (target instanceof L2Attackable)
  283. {
  284. L2Attackable targ = (L2Attackable) target;
  285. targ.stopHating(activeChar);
  286. if (targ.getMostHated() == null && targ.hasAI() && targ.getAI() instanceof L2AttackableAI)
  287. {
  288. ((L2AttackableAI) targ.getAI()).setGlobalAggro(-25);
  289. targ.clearAggroList();
  290. targ.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  291. targ.setWalking();
  292. }
  293. }
  294. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  295. }
  296. else
  297. {
  298. if (activeChar instanceof L2PcInstance)
  299. {
  300. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  301. sm.addCharName(target);
  302. sm.addSkillName(skill);
  303. activeChar.sendPacket(sm);
  304. }
  305. target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, activeChar);
  306. }
  307. break;
  308. }
  309. case AGGREMOVE:
  310. {
  311. // these skills needs to be rechecked
  312. if (target instanceof L2Attackable && !target.isRaid())
  313. {
  314. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  315. {
  316. if (skill.getTargetType() == L2TargetType.TARGET_UNDEAD)
  317. {
  318. if (target.isUndead())
  319. ((L2Attackable) target).reduceHate(null, ((L2Attackable) target).getHating(((L2Attackable) target).getMostHated()));
  320. }
  321. else
  322. ((L2Attackable) target).reduceHate(null, ((L2Attackable) target).getHating(((L2Attackable) target).getMostHated()));
  323. }
  324. else
  325. {
  326. if (activeChar instanceof L2PcInstance)
  327. {
  328. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  329. sm.addCharName(target);
  330. sm.addSkillName(skill);
  331. activeChar.sendPacket(sm);
  332. }
  333. target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, activeChar);
  334. }
  335. }
  336. else
  337. target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, activeChar);
  338. break;
  339. }
  340. case ERASE:
  341. {
  342. // Doesn't affect siege golem or wild hog cannon
  343. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss) && !(target instanceof L2SiegeSummonInstance))
  344. {
  345. final L2PcInstance summonOwner = ((L2Summon) target).getOwner();
  346. final L2Summon summon = summonOwner.getPet();
  347. if (summon != null)
  348. {
  349. // TODO: Retail confirmation for Soul of the Phoenix required.
  350. if (summon.isPhoenixBlessed())
  351. {
  352. if (summon.isNoblesseBlessed())
  353. {
  354. summon.stopNoblesseBlessing(null);
  355. }
  356. }
  357. else if (summon.isNoblesseBlessed())
  358. {
  359. summon.stopNoblesseBlessing(null);
  360. }
  361. else
  362. {
  363. summon.stopAllEffectsExceptThoseThatLastThroughDeath();
  364. }
  365. summon.unSummon(summonOwner);
  366. summonOwner.sendPacket(SystemMessageId.YOUR_SERVITOR_HAS_VANISHED);
  367. }
  368. }
  369. else
  370. {
  371. if (activeChar instanceof L2PcInstance)
  372. {
  373. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  374. sm.addCharName(target);
  375. sm.addSkillName(skill);
  376. activeChar.sendPacket(sm);
  377. }
  378. }
  379. break;
  380. }
  381. case CANCEL_DEBUFF:
  382. {
  383. L2Effect[] effects = target.getAllEffects();
  384. if (effects == null || effects.length == 0)
  385. break;
  386. int count = (skill.getMaxNegatedEffects() > 0) ? 0 : -2;
  387. for (L2Effect e : effects)
  388. {
  389. if (e == null
  390. || !e.getSkill().isDebuff()
  391. || !e.getSkill().canBeDispeled())
  392. continue;
  393. e.exit();
  394. if (count > -1)
  395. {
  396. count++;
  397. if (count >= skill.getMaxNegatedEffects())
  398. break;
  399. }
  400. }
  401. break;
  402. }
  403. case CANCEL_STATS: // same than CANCEL but
  404. {
  405. if (Formulas.calcSkillReflect(target, skill) == Formulas.SKILL_REFLECT_SUCCEED)
  406. target = activeChar;
  407. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  408. {
  409. L2Effect[] effects = target.getAllEffects();
  410. int max = skill.getMaxNegatedEffects();
  411. if (max == 0)
  412. max = Integer.MAX_VALUE; //this is for RBcancells and stuff...
  413. if (effects.length >= max)
  414. effects = SortEffects(effects);
  415. //for(int i = 0; i < effects.length;i++)
  416. // activeChar.sendMessage(Integer.toString(effects[i].getSkill().getMagicLevel()));
  417. int count = 1;
  418. for (L2Effect e : effects)
  419. {
  420. // do not delete signet effects!
  421. switch (e.getEffectType())
  422. {
  423. case SIGNET_GROUND:
  424. case SIGNET_EFFECT:
  425. continue;
  426. }
  427. switch(e.getSkill().getId())
  428. {
  429. case 4082:
  430. case 4215:
  431. case 4515:
  432. case 5182:
  433. case 110:
  434. case 111:
  435. case 1323:
  436. case 1325:
  437. continue;
  438. }
  439. switch (e.getSkill().getSkillType())
  440. {
  441. case BUFF:
  442. case HEAL_PERCENT:
  443. case COMBATPOINTHEAL:
  444. break;
  445. default:
  446. continue;
  447. }
  448. double rate = 1 - (count / max);
  449. if (rate < 0.33)
  450. rate = 0.33;
  451. else if (rate > 0.95)
  452. rate = 0.95;
  453. if (Rnd.get(1000) < (rate * 1000))
  454. {
  455. boolean exit = false;
  456. for (L2SkillType skillType : skill.getNegateStats())
  457. {
  458. if (skillType == e.getSkillType())
  459. {
  460. exit = true;
  461. break;
  462. }
  463. }
  464. if (exit)
  465. {
  466. e.exit();
  467. if (count == max)
  468. break;
  469. count++;
  470. }
  471. }
  472. }
  473. }
  474. else
  475. {
  476. if (activeChar instanceof L2PcInstance)
  477. {
  478. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  479. sm.addCharName(target);
  480. sm.addSkillName(skill);
  481. activeChar.sendPacket(sm);
  482. }
  483. }
  484. break;
  485. }
  486. case NEGATE:
  487. {
  488. if (Formulas.calcSkillReflect(target, skill) == Formulas.SKILL_REFLECT_SUCCEED)
  489. target = activeChar;
  490. if (skill.getNegateId().length != 0)
  491. {
  492. for (int i = 0; i < skill.getNegateId().length; i++)
  493. {
  494. if (skill.getNegateId()[i] != 0)
  495. target.stopSkillEffects(skill.getNegateId()[i]);
  496. }
  497. }
  498. else if (skill.getNegateAbnormals() != null)
  499. {
  500. for (L2Effect effect : target.getAllEffects())
  501. {
  502. if (effect == null)
  503. continue;
  504. for (String negateAbnormalType : skill.getNegateAbnormals().keySet())
  505. {
  506. if (negateAbnormalType.equalsIgnoreCase(effect.getAbnormalType()) && skill.getNegateAbnormals().get(negateAbnormalType) >= effect.getAbnormalLvl())
  507. effect.exit();
  508. }
  509. }
  510. }
  511. else // all others negate type skills
  512. {
  513. int removedBuffs = (skill.getMaxNegatedEffects() > 0) ? 0 : -2;
  514. for (L2SkillType skillType : skill.getNegateStats())
  515. {
  516. if (removedBuffs > skill.getMaxNegatedEffects())
  517. break;
  518. switch(skillType)
  519. {
  520. case BUFF:
  521. int lvlmodifier = 52 + skill.getMagicLevel() * 2;
  522. if (skill.getMagicLevel() == 12)
  523. lvlmodifier = (ExperienceTable.getInstance().getMaxLevel()-1);
  524. int landrate = 90;
  525. if ((target.getLevel() - lvlmodifier) > 0)
  526. landrate = 90 - 4 * (target.getLevel() - lvlmodifier);
  527. landrate = (int) activeChar.calcStat(Stats.CANCEL_VULN, landrate, target, null);
  528. if (Rnd.get(100) < landrate)
  529. removedBuffs += negateEffect(target, L2SkillType.BUFF, -1, skill.getMaxNegatedEffects());
  530. break;
  531. case HEAL:
  532. ISkillHandler Healhandler = SkillHandler.getInstance().getHandler(L2SkillType.HEAL);
  533. if (Healhandler == null)
  534. {
  535. _log.severe("Couldn't find skill handler for HEAL.");
  536. continue;
  537. }
  538. L2Character tgts[] = new L2Character[]{target};
  539. Healhandler.useSkill(activeChar, skill, tgts);
  540. break;
  541. default:
  542. removedBuffs += negateEffect(target, skillType, skill.getNegateLvl(), skill.getMaxNegatedEffects());
  543. break;
  544. }//end switch
  545. }//end for
  546. }//end else
  547. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  548. {
  549. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  550. }
  551. }// end case
  552. }//end switch
  553. //Possibility of a lethal strike
  554. Formulas.calcLethalHit(activeChar, target, skill);
  555. }//end for
  556. // self Effect :]
  557. if (skill.hasSelfEffects())
  558. {
  559. final L2Effect effect = activeChar.getFirstEffect(skill.getId());
  560. if (effect != null && effect.isSelfEffect())
  561. {
  562. //Replace old effect with new one.
  563. effect.exit();
  564. }
  565. skill.getEffectsSelf(activeChar);
  566. }
  567. } //end void
  568. /**
  569. *
  570. * @param target
  571. * @param type
  572. * @param power
  573. * @param maxRemoved
  574. * @return
  575. */
  576. private int negateEffect(L2Character target, L2SkillType type, int negateLvl, int maxRemoved)
  577. {
  578. return negateEffect(target, type, negateLvl, 0, maxRemoved);
  579. }
  580. /**
  581. *
  582. * @param target
  583. * @param type
  584. * @param power
  585. * @param skillId
  586. * @param maxRemoved
  587. * @return
  588. */
  589. private int negateEffect(L2Character target, L2SkillType type, int negateLvl, int skillId, int maxRemoved)
  590. {
  591. L2Effect[] effects = target.getAllEffects();
  592. int count = (maxRemoved <= 0) ? -2 : 0;
  593. for (L2Effect e : effects)
  594. {
  595. if (negateLvl == -1) // if power is -1 the effect is always removed without power/lvl check ^^
  596. {
  597. if (e.getSkill().getSkillType() == type || (e.getSkill().getEffectType() != null && e.getSkill().getEffectType() == type))
  598. {
  599. if (skillId != 0)
  600. {
  601. if (skillId == e.getSkill().getId() && count < maxRemoved)
  602. {
  603. e.exit();
  604. if (count > -1)
  605. count++;
  606. }
  607. }
  608. else if (count < maxRemoved)
  609. {
  610. e.exit();
  611. if (count > -1)
  612. count++;
  613. }
  614. }
  615. }
  616. else
  617. {
  618. boolean cancel = false;
  619. if (e.getSkill().getEffectType() != null && e.getSkill().getEffectAbnormalLvl() >= 0)
  620. {
  621. if (e.getSkill().getEffectType() == type && e.getSkill().getEffectAbnormalLvl() <= negateLvl)
  622. cancel = true;
  623. }
  624. else if (e.getSkill().getSkillType() == type && e.getSkill().getAbnormalLvl() <= negateLvl)
  625. cancel = true;
  626. if (cancel)
  627. {
  628. if (skillId != 0)
  629. {
  630. if (skillId == e.getSkill().getId() && count < maxRemoved)
  631. {
  632. e.exit();
  633. if (count > -1)
  634. count++;
  635. }
  636. }
  637. else if (count < maxRemoved)
  638. {
  639. e.exit();
  640. if (count > -1)
  641. count++;
  642. }
  643. }
  644. }
  645. }
  646. return (maxRemoved <= 0) ? count + 2 : count;
  647. }
  648. private L2Effect[] SortEffects(L2Effect[] initial)
  649. {
  650. //this is just classic insert sort
  651. //If u can find better sort for max 20-30 units, rewrite this... :)
  652. int min, index = 0;
  653. L2Effect pom;
  654. for (int i = 0; i < initial.length; i++)
  655. {
  656. min = initial[i].getSkill().getMagicLevel();
  657. for (int j = i; j < initial.length; j++)
  658. {
  659. if (initial[j].getSkill().getMagicLevel() <= min)
  660. {
  661. min = initial[j].getSkill().getMagicLevel();
  662. index = j;
  663. }
  664. }
  665. pom = initial[i];
  666. initial[i] = initial[index];
  667. initial[index] = pom;
  668. }
  669. return initial;
  670. }
  671. /**
  672. *
  673. * @see com.l2jserver.gameserver.handler.ISkillHandler#getSkillIds()
  674. */
  675. @Override
  676. public L2SkillType[] getSkillIds()
  677. {
  678. return SKILL_IDS;
  679. }
  680. }