Disablers.java 20 KB

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