Disablers.java 22 KB

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