Disablers.java 21 KB

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