Disablers.java 21 KB

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