CharEffectList.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  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 com.l2jserver.gameserver.model;
  16. import java.util.concurrent.LinkedBlockingQueue;
  17. import java.util.concurrent.atomic.AtomicBoolean;
  18. import java.util.Iterator;
  19. import java.util.List;
  20. import java.util.Map;
  21. import com.l2jserver.Config;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.actor.L2Playable;
  24. import com.l2jserver.gameserver.model.actor.L2Summon;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. import com.l2jserver.gameserver.network.serverpackets.AbnormalStatusUpdate;
  28. import com.l2jserver.gameserver.network.serverpackets.PartySpelled;
  29. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  30. import com.l2jserver.gameserver.templates.skills.L2EffectType;
  31. import javolution.util.FastList;
  32. import javolution.util.FastMap;
  33. public class CharEffectList
  34. {
  35. private static final L2Effect[] EMPTY_EFFECTS = new L2Effect[0];
  36. private FastList<L2Effect> _buffs;
  37. private FastList<L2Effect> _debuffs;
  38. // The table containing the List of all stacked effect in progress for each Stack group Identifier
  39. private Map<String, List<L2Effect>> _stackedEffects;
  40. private volatile boolean _hasEffectsRemovedOnAnyAction = false;
  41. private boolean _queuesInitialized = false;
  42. private LinkedBlockingQueue<L2Effect> _addQueue;
  43. private LinkedBlockingQueue<L2Effect> _removeQueue;
  44. private AtomicBoolean queueLock = new AtomicBoolean();
  45. // only party icons need to be updated
  46. private boolean _partyOnly = false;
  47. // Owner of this list
  48. private L2Character _owner;
  49. public CharEffectList(L2Character owner)
  50. {
  51. _owner = owner;
  52. }
  53. /**
  54. * Returns all effects affecting stored in this CharEffectList
  55. * @return
  56. */
  57. public final L2Effect[] getAllEffects()
  58. {
  59. // If no effect is active, return EMPTY_EFFECTS
  60. if ( (_buffs == null || _buffs.isEmpty()) && (_debuffs == null || _debuffs.isEmpty()) )
  61. {
  62. return EMPTY_EFFECTS;
  63. }
  64. // Create a copy of the effects
  65. FastList<L2Effect> temp = new FastList<L2Effect>();
  66. // Add all buffs and all debuffs
  67. if (_buffs != null)
  68. {
  69. synchronized (_buffs)
  70. {
  71. if (!_buffs.isEmpty())
  72. temp.addAll(_buffs);
  73. }
  74. }
  75. if (_debuffs != null)
  76. {
  77. synchronized (_debuffs)
  78. {
  79. if (!_debuffs.isEmpty())
  80. temp.addAll(_debuffs);
  81. }
  82. }
  83. // Return all effects in an array
  84. L2Effect[] tempArray = new L2Effect[temp.size()];
  85. temp.toArray(tempArray);
  86. return tempArray;
  87. }
  88. /**
  89. * Returns the first effect matching the given EffectType
  90. * @param tp
  91. * @return
  92. */
  93. public final L2Effect getFirstEffect(L2EffectType tp)
  94. {
  95. L2Effect effectNotInUse = null;
  96. if (_buffs != null)
  97. {
  98. synchronized (_buffs)
  99. {
  100. if (!_buffs.isEmpty())
  101. {
  102. for (L2Effect e: _buffs)
  103. {
  104. if (e == null)
  105. continue;
  106. if (e.getEffectType() == tp)
  107. {
  108. if (e.getInUse())
  109. return e;
  110. else
  111. effectNotInUse = e;
  112. }
  113. }
  114. }
  115. }
  116. }
  117. if (effectNotInUse == null && _debuffs != null)
  118. {
  119. synchronized (_debuffs)
  120. {
  121. if (!_debuffs.isEmpty())
  122. {
  123. for (L2Effect e: _debuffs)
  124. {
  125. if (e == null)
  126. continue;
  127. if (e.getEffectType() == tp)
  128. {
  129. if (e.getInUse())
  130. return e;
  131. else
  132. effectNotInUse = e;
  133. }
  134. }
  135. }
  136. }
  137. }
  138. return effectNotInUse;
  139. }
  140. /**
  141. * Returns the first effect matching the given L2Skill
  142. * @param skill
  143. * @return
  144. */
  145. public final L2Effect getFirstEffect(L2Skill skill)
  146. {
  147. L2Effect effectNotInUse = null;
  148. if (skill.isDebuff())
  149. {
  150. if (_debuffs == null)
  151. return null;
  152. synchronized (_debuffs)
  153. {
  154. if (_debuffs.isEmpty())
  155. return null;
  156. for (L2Effect e: _debuffs)
  157. {
  158. if (e == null)
  159. continue;
  160. if (e.getSkill() == skill)
  161. {
  162. if (e.getInUse())
  163. return e;
  164. else
  165. effectNotInUse = e;
  166. }
  167. }
  168. }
  169. return effectNotInUse;
  170. }
  171. else
  172. {
  173. if (_buffs == null)
  174. return null;
  175. synchronized (_buffs)
  176. {
  177. if (_buffs.isEmpty())
  178. return null;
  179. for (L2Effect e: _buffs)
  180. {
  181. if (e == null)
  182. continue;
  183. if (e.getSkill() == skill)
  184. {
  185. if (e.getInUse())
  186. return e;
  187. else
  188. effectNotInUse = e;
  189. }
  190. }
  191. }
  192. return effectNotInUse;
  193. }
  194. }
  195. /**
  196. * Returns the first effect matching the given skillId
  197. * @param index
  198. * @return
  199. */
  200. public final L2Effect getFirstEffect(int skillId)
  201. {
  202. L2Effect effectNotInUse = null;
  203. if (_buffs != null)
  204. {
  205. synchronized (_buffs)
  206. {
  207. if (!_buffs.isEmpty())
  208. {
  209. for (L2Effect e: _buffs)
  210. {
  211. if (e == null)
  212. continue;
  213. if (e.getSkill().getId() == skillId)
  214. {
  215. if (e.getInUse())
  216. return e;
  217. else
  218. effectNotInUse = e;
  219. }
  220. }
  221. }
  222. }
  223. }
  224. if (effectNotInUse == null && _debuffs != null)
  225. {
  226. synchronized (_debuffs)
  227. {
  228. if (!_debuffs.isEmpty())
  229. {
  230. for (L2Effect e: _debuffs)
  231. {
  232. if (e == null)
  233. continue;
  234. if (e.getSkill().getId() == skillId)
  235. {
  236. if (e.getInUse())
  237. return e;
  238. else
  239. effectNotInUse = e;
  240. }
  241. }
  242. }
  243. }
  244. }
  245. return effectNotInUse;
  246. }
  247. /**
  248. * Checks if the given skill stacks with an existing one.
  249. *
  250. * @param checkSkill the skill to be checked
  251. *
  252. * @return Returns whether or not this skill will stack
  253. */
  254. private boolean doesStack(L2Skill checkSkill)
  255. {
  256. if ( (_buffs == null || _buffs.isEmpty()) ||
  257. checkSkill._effectTemplates == null ||
  258. checkSkill._effectTemplates.length < 1 ||
  259. checkSkill._effectTemplates[0].stackType == null ||
  260. "none".equals(checkSkill._effectTemplates[0].stackType))
  261. {
  262. return false;
  263. }
  264. String stackType = checkSkill._effectTemplates[0].stackType;
  265. for (L2Effect e : _buffs)
  266. {
  267. if (e.getStackType() != null && e.getStackType().equals(stackType))
  268. {
  269. return true;
  270. }
  271. }
  272. return false;
  273. }
  274. /**
  275. * Return the number of buffs in this CharEffectList not counting Songs/Dances
  276. * @return
  277. */
  278. public int getBuffCount()
  279. {
  280. if (_buffs == null) return 0;
  281. int buffCount=0;
  282. synchronized(_buffs)
  283. {
  284. if (_buffs.isEmpty())
  285. return 0;
  286. for (L2Effect e : _buffs)
  287. {
  288. if (e != null && e.getShowIcon() && !e.getSkill().isDance() && !e.getSkill().is7Signs())
  289. {
  290. switch (e.getSkill().getSkillType())
  291. {
  292. case BUFF:
  293. case REFLECT:
  294. case HEAL_PERCENT:
  295. case MANAHEAL_PERCENT:
  296. buffCount++;
  297. }
  298. }
  299. }
  300. }
  301. return buffCount;
  302. }
  303. /**
  304. * Return the number of Songs/Dances in this CharEffectList
  305. * @return
  306. */
  307. public int getDanceCount()
  308. {
  309. if (_buffs == null) return 0;
  310. int danceCount = 0;
  311. synchronized(_buffs)
  312. {
  313. if (_buffs.isEmpty())
  314. return 0;
  315. for (L2Effect e : _buffs)
  316. {
  317. if (e != null && e.getSkill().isDance() && e.getInUse())
  318. danceCount++;
  319. }
  320. }
  321. return danceCount;
  322. }
  323. /**
  324. * Exits all effects in this CharEffectList
  325. */
  326. public final void stopAllEffects()
  327. {
  328. // Get all active skills effects from this list
  329. L2Effect[] effects = getAllEffects();
  330. // Exit them
  331. for (L2Effect e : effects)
  332. {
  333. if (e != null)
  334. e.exit(true);
  335. }
  336. }
  337. /**
  338. * Exits all effects in this CharEffectList
  339. */
  340. public final void stopAllEffectsExceptThoseThatLastThroughDeath()
  341. {
  342. // Get all active skills effects from this list
  343. L2Effect[] effects = getAllEffects();
  344. // Exit them
  345. for (L2Effect e : effects)
  346. {
  347. if (e != null && !e.getSkill().isStayAfterDeath())
  348. e.exit(true);
  349. }
  350. }
  351. /**
  352. * Exit all effects having a specified type
  353. * @param type
  354. */
  355. public final void stopEffects(L2EffectType type)
  356. {
  357. // Go through all active skills effects
  358. FastList<L2Effect> temp = new FastList<L2Effect>();
  359. if (_buffs != null)
  360. {
  361. synchronized (_buffs)
  362. {
  363. if (!_buffs.isEmpty())
  364. {
  365. for (L2Effect e : _buffs)
  366. // Get active skills effects of the selected type
  367. if (e != null && e.getEffectType() == type)
  368. temp.add(e);
  369. }
  370. }
  371. }
  372. if (_debuffs != null)
  373. {
  374. synchronized (_debuffs)
  375. {
  376. if (!_debuffs.isEmpty())
  377. {
  378. for (L2Effect e : _debuffs)
  379. // Get active skills effects of the selected type
  380. if (e != null && e.getEffectType() == type)
  381. temp.add(e);
  382. }
  383. }
  384. }
  385. if (temp != null && !temp.isEmpty())
  386. {
  387. for (L2Effect e : temp)
  388. if (e != null)
  389. e.exit();
  390. }
  391. }
  392. /**
  393. * Exits all effects created by a specific skillId
  394. * @param skillId
  395. */
  396. public final void stopSkillEffects(int skillId)
  397. {
  398. // Go through all active skills effects
  399. FastList<L2Effect> temp = new FastList<L2Effect>();
  400. if (_buffs != null)
  401. {
  402. synchronized (_buffs)
  403. {
  404. if (!_buffs.isEmpty())
  405. {
  406. for (L2Effect e : _buffs)
  407. if (e != null && e.getSkill().getId() == skillId)
  408. temp.add(e);
  409. }
  410. }
  411. }
  412. if (_debuffs != null)
  413. {
  414. synchronized (_debuffs)
  415. {
  416. if (!_debuffs.isEmpty())
  417. {
  418. for (L2Effect e : _debuffs)
  419. if (e != null && e.getSkill().getId() == skillId)
  420. temp.add(e);
  421. }
  422. }
  423. }
  424. if (temp != null && !temp.isEmpty())
  425. {
  426. for (L2Effect e : temp)
  427. if (e != null)
  428. e.exit();
  429. }
  430. }
  431. /**
  432. * Exits all buffs effects of the skills with "removedOnAnyAction" set.
  433. * Called on any action except movement (attack, cast).
  434. */
  435. public void stopEffectsOnAction()
  436. {
  437. if (_hasEffectsRemovedOnAnyAction)
  438. {
  439. if (_buffs != null)
  440. {
  441. synchronized (_buffs)
  442. {
  443. if (!_buffs.isEmpty())
  444. {
  445. for (L2Effect e : _buffs)
  446. if (e != null && e.getSkill().isRemovedOnAnyActionExceptMove())
  447. e.exit(true);
  448. }
  449. }
  450. }
  451. }
  452. }
  453. public void updateEffectIcons(boolean partyOnly)
  454. {
  455. if (_buffs == null && _debuffs == null)
  456. return;
  457. if (partyOnly)
  458. _partyOnly = true;
  459. queueRunner();
  460. }
  461. public void queueEffect(L2Effect effect, boolean remove)
  462. {
  463. if (effect == null) return;
  464. if (!_queuesInitialized)
  465. init();
  466. if (remove)
  467. _removeQueue.offer(effect);
  468. else
  469. _addQueue.offer(effect);
  470. queueRunner();
  471. }
  472. synchronized private void init()
  473. {
  474. _addQueue = new LinkedBlockingQueue<L2Effect>();
  475. _removeQueue = new LinkedBlockingQueue<L2Effect>();
  476. _queuesInitialized = true;
  477. }
  478. private void queueRunner()
  479. {
  480. if (!queueLock.compareAndSet(false, true))
  481. return;
  482. try
  483. {
  484. L2Effect effect;
  485. do
  486. {
  487. // remove has more priority than add
  488. // so removing all effects from queue first
  489. while ((effect = _removeQueue.poll()) != null)
  490. {
  491. removeEffectFromQueue(effect);
  492. _partyOnly = false;
  493. }
  494. if ((effect = _addQueue.poll()) != null)
  495. {
  496. addEffectFromQueue(effect);
  497. _partyOnly = false;
  498. }
  499. }
  500. while (!_addQueue.isEmpty() || !_removeQueue.isEmpty());
  501. updateEffectIcons();
  502. }
  503. finally
  504. {
  505. queueLock.set(false);
  506. }
  507. }
  508. protected void removeEffectFromQueue(L2Effect effect)
  509. {
  510. if (effect == null) return;
  511. FastList<L2Effect> effectList;
  512. if (effect.getSkill().isDebuff())
  513. {
  514. if (_debuffs == null)
  515. return;
  516. effectList = _debuffs;
  517. }
  518. else
  519. {
  520. if (_buffs == null)
  521. return;
  522. effectList = _buffs;
  523. }
  524. if ("none".equals(effect.getStackType()))
  525. {
  526. // Remove Func added by this effect from the L2Character Calculator
  527. _owner.removeStatsOwner(effect);
  528. }
  529. else
  530. {
  531. if(_stackedEffects == null) return;
  532. // Get the list of all stacked effects corresponding to the stack type of the L2Effect to add
  533. List<L2Effect> stackQueue = _stackedEffects.get(effect.getStackType());
  534. if (stackQueue == null || stackQueue.isEmpty()) return;
  535. int index = stackQueue.indexOf(effect);
  536. // Remove the effect from the stack group
  537. if (index >= 0)
  538. {
  539. stackQueue.remove(effect);
  540. // Check if the first stacked effect was the effect to remove
  541. if (index == 0)
  542. {
  543. // Remove all its Func objects from the L2Character calculator set
  544. _owner.removeStatsOwner(effect);
  545. // Check if there's another effect in the Stack Group
  546. if (!stackQueue.isEmpty())
  547. {
  548. L2Effect newStackedEffect = listsContains(stackQueue.get(0));
  549. if (newStackedEffect != null)
  550. {
  551. // Set the effect to In Use
  552. if (newStackedEffect.setInUse(true))
  553. // Add its list of Funcs to the Calculator set of the L2Character
  554. _owner.addStatFuncs(newStackedEffect.getStatFuncs());
  555. }
  556. }
  557. }
  558. if (stackQueue.isEmpty())
  559. _stackedEffects.remove(effect.getStackType());
  560. else
  561. // Update the Stack Group table _stackedEffects of the L2Character
  562. _stackedEffects.put(effect.getStackType(), stackQueue);
  563. }
  564. }
  565. // Remove the active skill L2effect from _effects of the L2Character
  566. if (effectList.remove(effect) && _owner instanceof L2PcInstance && effect.getShowIcon())
  567. {
  568. SystemMessage sm;
  569. if (effect.getSkill().isToggle())
  570. {
  571. sm = new SystemMessage(SystemMessageId.S1_HAS_BEEN_ABORTED);
  572. }
  573. else
  574. {
  575. sm = new SystemMessage(SystemMessageId.EFFECT_S1_DISAPPEARED);
  576. }
  577. sm.addSkillName(effect);
  578. _owner.sendPacket(sm);
  579. }
  580. }
  581. protected void addEffectFromQueue(L2Effect newEffect)
  582. {
  583. if (newEffect == null) return;
  584. L2Skill newSkill = newEffect.getSkill();
  585. if (newSkill.isDebuff())
  586. {
  587. if (_debuffs == null) _debuffs = new FastList<L2Effect>();
  588. for (L2Effect e : _debuffs)
  589. {
  590. if (e != null
  591. && e.getSkill().getId() == newEffect.getSkill().getId()
  592. && e.getEffectType() == newEffect.getEffectType()
  593. && e.getStackOrder() == newEffect.getStackOrder()
  594. && e.getStackType().equals(newEffect.getStackType()))
  595. {
  596. // Started scheduled timer needs to be canceled.
  597. newEffect.stopEffectTask();
  598. return;
  599. }
  600. }
  601. _debuffs.addLast(newEffect);
  602. }
  603. else
  604. {
  605. if (_buffs == null) _buffs = new FastList<L2Effect>();
  606. for (L2Effect e : _buffs)
  607. {
  608. if (e != null
  609. && e.getSkill().getId() == newEffect.getSkill().getId()
  610. && e.getEffectType() == newEffect.getEffectType()
  611. && e.getStackOrder() == newEffect.getStackOrder()
  612. && e.getStackType().equals(newEffect.getStackType()))
  613. {
  614. e.exit(); // exit this
  615. }
  616. }
  617. // if max buffs, no herb effects are used, even if they would replace one old
  618. if (newEffect.isHerbEffect() && getBuffCount() >= _owner.getMaxBuffCount())
  619. {
  620. newEffect.stopEffectTask();
  621. return;
  622. }
  623. // Remove first buff when buff list is full
  624. if (!doesStack(newSkill) && !newSkill.is7Signs())
  625. {
  626. int effectsToRemove;
  627. if (newSkill.isDance())
  628. {
  629. effectsToRemove = getDanceCount() - Config.DANCES_MAX_AMOUNT;
  630. if (effectsToRemove >= 0)
  631. {
  632. for (L2Effect e : _buffs)
  633. {
  634. if (e == null || !e.getSkill().isDance())
  635. continue;
  636. // get first dance
  637. e.exit();
  638. effectsToRemove--;
  639. if (effectsToRemove < 0)
  640. break;
  641. }
  642. }
  643. }
  644. else
  645. {
  646. effectsToRemove = getBuffCount() - _owner.getMaxBuffCount();
  647. if (effectsToRemove >= 0)
  648. {
  649. switch (newSkill.getSkillType())
  650. {
  651. case BUFF:
  652. case REFLECT:
  653. case HEAL_PERCENT:
  654. case MANAHEAL_PERCENT:
  655. for (L2Effect e : _buffs)
  656. {
  657. if (e == null || e.getSkill().isDance())
  658. continue;
  659. switch (e.getSkill().getSkillType())
  660. {
  661. case BUFF:
  662. case REFLECT:
  663. case HEAL_PERCENT:
  664. case MANAHEAL_PERCENT:
  665. e.exit();
  666. effectsToRemove--;
  667. break; // break switch()
  668. default:
  669. continue; // continue for()
  670. }
  671. if (effectsToRemove < 0)
  672. break; // break for()
  673. }
  674. }
  675. }
  676. }
  677. }
  678. // Icons order: buffs, 7s, toggles, dances
  679. if (newSkill.isDance())
  680. _buffs.addLast(newEffect);
  681. else
  682. {
  683. int pos=0;
  684. if (newSkill.isToggle())
  685. {
  686. // toggle skill - before all dances
  687. for (L2Effect e : _buffs)
  688. {
  689. if (e == null)
  690. continue;
  691. if (e.getSkill().isDance())
  692. break;
  693. pos++;
  694. }
  695. }
  696. else
  697. {
  698. // normal buff - before toggles and 7s and dances
  699. for (L2Effect e : _buffs)
  700. {
  701. if (e == null)
  702. continue;
  703. if (e.getSkill().isToggle() || e.getSkill().is7Signs()
  704. || e.getSkill().isDance())
  705. break;
  706. pos++;
  707. }
  708. }
  709. _buffs.add(pos, newEffect);
  710. }
  711. }
  712. // Check if a stack group is defined for this effect
  713. if ("none".equals(newEffect.getStackType()))
  714. {
  715. // Set this L2Effect to In Use
  716. if (newEffect.setInUse(true))
  717. // Add Funcs of this effect to the Calculator set of the L2Character
  718. _owner.addStatFuncs(newEffect.getStatFuncs());
  719. return;
  720. }
  721. List<L2Effect> stackQueue;
  722. L2Effect effectToAdd = null;
  723. L2Effect effectToRemove = null;
  724. if (_stackedEffects == null) _stackedEffects = new FastMap<String, List<L2Effect>>();
  725. // Get the list of all stacked effects corresponding to the stack type of the L2Effect to add
  726. stackQueue = _stackedEffects.get(newEffect.getStackType());
  727. if (stackQueue != null)
  728. {
  729. int pos = 0;
  730. if (!stackQueue.isEmpty())
  731. {
  732. // Get the first stacked effect of the Stack group selected
  733. effectToRemove = listsContains(stackQueue.get(0));
  734. // Create an Iterator to go through the list of stacked effects in progress on the L2Character
  735. Iterator<L2Effect> queueIterator = stackQueue.iterator();
  736. while (queueIterator.hasNext())
  737. {
  738. if (newEffect.getStackOrder() < queueIterator.next().getStackOrder())
  739. pos++;
  740. else break;
  741. }
  742. // Add the new effect to the Stack list in function of its position in the Stack group
  743. stackQueue.add(pos, newEffect);
  744. // skill.exit() could be used, if the users don't wish to see "effect
  745. // removed" always when a timer goes off, even if the buff isn't active
  746. // any more (has been replaced). but then check e.g. npc hold and raid petrification.
  747. if (Config.EFFECT_CANCELING && !newEffect.isHerbEffect() && stackQueue.size() > 1)
  748. {
  749. if (newSkill.isDebuff())
  750. {
  751. _debuffs.remove(stackQueue.remove(1));
  752. }
  753. else
  754. {
  755. _buffs.remove(stackQueue.remove(1));
  756. }
  757. }
  758. }
  759. else
  760. stackQueue.add(0, newEffect);
  761. }
  762. else
  763. {
  764. stackQueue = new FastList<L2Effect>();
  765. stackQueue.add(0, newEffect);
  766. }
  767. // Update the Stack Group table _stackedEffects of the L2Character
  768. _stackedEffects.put(newEffect.getStackType(), stackQueue);
  769. // Get the first stacked effect of the Stack group selected
  770. if (stackQueue != null && !stackQueue.isEmpty())
  771. {
  772. effectToAdd = listsContains(stackQueue.get(0));
  773. }
  774. if (effectToRemove != effectToAdd)
  775. {
  776. if (effectToRemove != null)
  777. {
  778. // Remove all Func objects corresponding to this stacked effect from the Calculator set of the L2Character
  779. _owner.removeStatsOwner(effectToRemove);
  780. // Set the L2Effect to Not In Use
  781. effectToRemove.setInUse(false);
  782. }
  783. if (effectToAdd != null)
  784. {
  785. // Set this L2Effect to In Use
  786. if (effectToAdd.setInUse(true))
  787. // Add all Func objects corresponding to this stacked effect to the Calculator set of the L2Character
  788. _owner.addStatFuncs(effectToAdd.getStatFuncs());
  789. }
  790. }
  791. }
  792. protected void updateEffectIcons()
  793. {
  794. if (_owner == null || !(_owner instanceof L2Playable))
  795. return;
  796. AbnormalStatusUpdate mi = null;
  797. PartySpelled ps = null;
  798. if (_owner instanceof L2PcInstance)
  799. {
  800. if (_partyOnly)
  801. _partyOnly = false;
  802. else
  803. mi = new AbnormalStatusUpdate();
  804. if (_owner.isInParty())
  805. ps = new PartySpelled(_owner);
  806. }
  807. else
  808. if (_owner instanceof L2Summon)
  809. ps = new PartySpelled(_owner);
  810. boolean found = false;
  811. if (_buffs != null && !_buffs.isEmpty())
  812. {
  813. synchronized (_buffs)
  814. {
  815. for (L2Effect e : _buffs)
  816. {
  817. if (e == null)
  818. continue;
  819. if (e.getSkill().isRemovedOnAnyActionExceptMove())
  820. found = true;
  821. if (!e.getShowIcon())
  822. continue;
  823. switch (e.getEffectType())
  824. {
  825. case CHARGE: // handled by EtcStatusUpdate
  826. case SIGNET_GROUND:
  827. continue;
  828. }
  829. if (e.getInUse())
  830. {
  831. if (mi != null)
  832. e.addIcon(mi);
  833. if (ps != null)
  834. e.addPartySpelledIcon(ps);
  835. }
  836. }
  837. }
  838. }
  839. if (_debuffs != null && !_debuffs.isEmpty())
  840. {
  841. synchronized (_debuffs)
  842. {
  843. for (L2Effect e : _debuffs)
  844. {
  845. if (e == null)
  846. continue;
  847. if (e.getSkill().isRemovedOnAnyActionExceptMove())
  848. found = true;
  849. if (!e.getShowIcon())
  850. continue;
  851. switch (e.getEffectType())
  852. {
  853. case SIGNET_GROUND:
  854. continue;
  855. }
  856. if (e.getInUse())
  857. {
  858. if (mi != null)
  859. e.addIcon(mi);
  860. if (ps != null)
  861. e.addPartySpelledIcon(ps);
  862. }
  863. }
  864. }
  865. }
  866. _hasEffectsRemovedOnAnyAction = found;
  867. if (mi != null)
  868. _owner.sendPacket(mi);
  869. if (ps != null)
  870. {
  871. if (_owner instanceof L2Summon)
  872. {
  873. L2PcInstance summonOwner = ((L2Summon)_owner).getOwner();
  874. if (summonOwner != null)
  875. {
  876. if (summonOwner.isInParty())
  877. summonOwner.getParty().broadcastToPartyMembers(ps);
  878. else
  879. summonOwner.sendPacket(ps);
  880. }
  881. }
  882. else
  883. if (_owner instanceof L2PcInstance && _owner.isInParty())
  884. _owner.getParty().broadcastToPartyMembers(ps);
  885. }
  886. }
  887. /**
  888. * Returns effect if contains in _buffs or _debuffs and null if not found
  889. * @param effect
  890. * @return
  891. */
  892. private L2Effect listsContains(L2Effect effect)
  893. {
  894. if (_buffs != null && !_buffs.isEmpty()&& _buffs.contains(effect))
  895. return effect;
  896. if (_debuffs != null && !_debuffs.isEmpty() && _debuffs.contains(effect))
  897. return effect;
  898. return null;
  899. }
  900. /**
  901. * Clear and null all queues and lists
  902. * Use only during delete character from the world.
  903. */
  904. public void clear()
  905. {
  906. try
  907. {
  908. if (_addQueue != null)
  909. {
  910. _addQueue.clear();
  911. _addQueue = null;
  912. }
  913. if (_removeQueue != null)
  914. {
  915. _removeQueue.clear();
  916. _removeQueue = null;
  917. }
  918. _queuesInitialized = false;
  919. if (_buffs != null)
  920. {
  921. _buffs.clear();
  922. _buffs = null;
  923. }
  924. if (_debuffs != null)
  925. {
  926. _debuffs.clear();
  927. _debuffs = null;
  928. }
  929. if (_stackedEffects != null)
  930. {
  931. _stackedEffects.clear();
  932. _stackedEffects = null;
  933. }
  934. }
  935. catch (Exception e)
  936. {
  937. e.printStackTrace();
  938. }
  939. }
  940. }