Disablers.java 21 KB

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