Guest User

disablers.java

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