CharEffectList.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  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 toggle-type effects
  353. */
  354. public void stopAllToggles()
  355. {
  356. if (_buffs != null)
  357. {
  358. synchronized (_buffs)
  359. {
  360. if (!_buffs.isEmpty())
  361. {
  362. for (L2Effect e : _buffs)
  363. if (e != null && e.getSkill().isToggle())
  364. e.exit();
  365. }
  366. }
  367. }
  368. }
  369. /**
  370. * Exit all effects having a specified type
  371. * @param type
  372. */
  373. public final void stopEffects(L2EffectType type)
  374. {
  375. // Go through all active skills effects
  376. FastList<L2Effect> temp = new FastList<L2Effect>();
  377. if (_buffs != null)
  378. {
  379. synchronized (_buffs)
  380. {
  381. if (!_buffs.isEmpty())
  382. {
  383. for (L2Effect e : _buffs)
  384. // Get active skills effects of the selected type
  385. if (e != null && e.getEffectType() == type)
  386. temp.add(e);
  387. }
  388. }
  389. }
  390. if (_debuffs != null)
  391. {
  392. synchronized (_debuffs)
  393. {
  394. if (!_debuffs.isEmpty())
  395. {
  396. for (L2Effect e : _debuffs)
  397. // Get active skills effects of the selected type
  398. if (e != null && e.getEffectType() == type)
  399. temp.add(e);
  400. }
  401. }
  402. }
  403. if (!temp.isEmpty())
  404. {
  405. for (L2Effect e : temp)
  406. if (e != null)
  407. e.exit();
  408. temp.clear();
  409. }
  410. }
  411. /**
  412. * Exits all effects created by a specific skillId
  413. * @param skillId
  414. */
  415. public final void stopSkillEffects(int skillId)
  416. {
  417. // Go through all active skills effects
  418. FastList<L2Effect> temp = new FastList<L2Effect>();
  419. if (_buffs != null)
  420. {
  421. synchronized (_buffs)
  422. {
  423. if (!_buffs.isEmpty())
  424. {
  425. for (L2Effect e : _buffs)
  426. if (e != null && e.getSkill().getId() == skillId)
  427. temp.add(e);
  428. }
  429. }
  430. }
  431. if (_debuffs != null)
  432. {
  433. synchronized (_debuffs)
  434. {
  435. if (!_debuffs.isEmpty())
  436. {
  437. for (L2Effect e : _debuffs)
  438. if (e != null && e.getSkill().getId() == skillId)
  439. temp.add(e);
  440. }
  441. }
  442. }
  443. if (!temp.isEmpty())
  444. {
  445. for (L2Effect e : temp)
  446. if (e != null)
  447. e.exit();
  448. temp.clear();
  449. }
  450. }
  451. /**
  452. * Exits all buffs effects of the skills with "removedOnAnyAction" set.
  453. * Called on any action except movement (attack, cast).
  454. */
  455. public void stopEffectsOnAction()
  456. {
  457. if (_hasEffectsRemovedOnAnyAction)
  458. {
  459. if (_buffs != null)
  460. {
  461. synchronized (_buffs)
  462. {
  463. if (!_buffs.isEmpty())
  464. {
  465. for (L2Effect e : _buffs)
  466. if (e != null && e.getSkill().isRemovedOnAnyActionExceptMove())
  467. e.exit(true);
  468. }
  469. }
  470. }
  471. }
  472. }
  473. public void updateEffectIcons(boolean partyOnly)
  474. {
  475. if (_buffs == null && _debuffs == null)
  476. return;
  477. if (partyOnly)
  478. _partyOnly = true;
  479. queueRunner();
  480. }
  481. public void queueEffect(L2Effect effect, boolean remove)
  482. {
  483. if (effect == null) return;
  484. if (!_queuesInitialized)
  485. init();
  486. if (remove)
  487. _removeQueue.offer(effect);
  488. else
  489. _addQueue.offer(effect);
  490. queueRunner();
  491. }
  492. synchronized private void init()
  493. {
  494. _addQueue = new LinkedBlockingQueue<L2Effect>();
  495. _removeQueue = new LinkedBlockingQueue<L2Effect>();
  496. _queuesInitialized = true;
  497. }
  498. private void queueRunner()
  499. {
  500. if (!queueLock.compareAndSet(false, true))
  501. return;
  502. try
  503. {
  504. L2Effect effect;
  505. do
  506. {
  507. // remove has more priority than add
  508. // so removing all effects from queue first
  509. while ((effect = _removeQueue.poll()) != null)
  510. {
  511. removeEffectFromQueue(effect);
  512. _partyOnly = false;
  513. }
  514. if ((effect = _addQueue.poll()) != null)
  515. {
  516. addEffectFromQueue(effect);
  517. _partyOnly = false;
  518. }
  519. }
  520. while (!_addQueue.isEmpty() || !_removeQueue.isEmpty());
  521. updateEffectIcons();
  522. }
  523. finally
  524. {
  525. queueLock.set(false);
  526. }
  527. }
  528. protected void removeEffectFromQueue(L2Effect effect)
  529. {
  530. if (effect == null) return;
  531. FastList<L2Effect> effectList;
  532. if (effect.getSkill().isDebuff())
  533. {
  534. if (_debuffs == null)
  535. return;
  536. effectList = _debuffs;
  537. }
  538. else
  539. {
  540. if (_buffs == null)
  541. return;
  542. effectList = _buffs;
  543. }
  544. if ("none".equals(effect.getStackType()))
  545. {
  546. // Remove Func added by this effect from the L2Character Calculator
  547. _owner.removeStatsOwner(effect);
  548. }
  549. else
  550. {
  551. if(_stackedEffects == null) return;
  552. // Get the list of all stacked effects corresponding to the stack type of the L2Effect to add
  553. List<L2Effect> stackQueue = _stackedEffects.get(effect.getStackType());
  554. if (stackQueue == null || stackQueue.isEmpty()) return;
  555. int index = stackQueue.indexOf(effect);
  556. // Remove the effect from the stack group
  557. if (index >= 0)
  558. {
  559. stackQueue.remove(effect);
  560. // Check if the first stacked effect was the effect to remove
  561. if (index == 0)
  562. {
  563. // Remove all its Func objects from the L2Character calculator set
  564. _owner.removeStatsOwner(effect);
  565. // Check if there's another effect in the Stack Group
  566. if (!stackQueue.isEmpty())
  567. {
  568. L2Effect newStackedEffect = listsContains(stackQueue.get(0));
  569. if (newStackedEffect != null)
  570. {
  571. // Set the effect to In Use
  572. if (newStackedEffect.setInUse(true))
  573. // Add its list of Funcs to the Calculator set of the L2Character
  574. _owner.addStatFuncs(newStackedEffect.getStatFuncs());
  575. }
  576. }
  577. }
  578. if (stackQueue.isEmpty())
  579. _stackedEffects.remove(effect.getStackType());
  580. else
  581. // Update the Stack Group table _stackedEffects of the L2Character
  582. _stackedEffects.put(effect.getStackType(), stackQueue);
  583. }
  584. }
  585. // Remove the active skill L2effect from _effects of the L2Character
  586. if (effectList.remove(effect) && _owner instanceof L2PcInstance && effect.getShowIcon())
  587. {
  588. SystemMessage sm;
  589. if (effect.getSkill().isToggle())
  590. {
  591. sm = new SystemMessage(SystemMessageId.S1_HAS_BEEN_ABORTED);
  592. }
  593. else
  594. {
  595. sm = new SystemMessage(SystemMessageId.EFFECT_S1_DISAPPEARED);
  596. }
  597. sm.addSkillName(effect);
  598. _owner.sendPacket(sm);
  599. }
  600. }
  601. protected void addEffectFromQueue(L2Effect newEffect)
  602. {
  603. if (newEffect == null) return;
  604. L2Skill newSkill = newEffect.getSkill();
  605. if (newSkill.isDebuff())
  606. {
  607. if (_debuffs == null) _debuffs = new FastList<L2Effect>();
  608. for (L2Effect e : _debuffs)
  609. {
  610. if (e != null
  611. && e.getSkill().getId() == newEffect.getSkill().getId()
  612. && e.getEffectType() == newEffect.getEffectType()
  613. && e.getStackOrder() == newEffect.getStackOrder()
  614. && e.getStackType().equals(newEffect.getStackType()))
  615. {
  616. // Started scheduled timer needs to be canceled.
  617. newEffect.stopEffectTask();
  618. return;
  619. }
  620. }
  621. _debuffs.addLast(newEffect);
  622. }
  623. else
  624. {
  625. if (_buffs == null) _buffs = new FastList<L2Effect>();
  626. for (L2Effect e : _buffs)
  627. {
  628. if (e != null
  629. && e.getSkill().getId() == newEffect.getSkill().getId()
  630. && e.getEffectType() == newEffect.getEffectType()
  631. && e.getStackOrder() == newEffect.getStackOrder()
  632. && e.getStackType().equals(newEffect.getStackType()))
  633. {
  634. e.exit(); // exit this
  635. }
  636. }
  637. // if max buffs, no herb effects are used, even if they would replace one old
  638. if (newEffect.isHerbEffect() && getBuffCount() >= _owner.getMaxBuffCount())
  639. {
  640. newEffect.stopEffectTask();
  641. return;
  642. }
  643. // Remove first buff when buff list is full
  644. if (!doesStack(newSkill) && !newSkill.is7Signs())
  645. {
  646. int effectsToRemove;
  647. if (newSkill.isDance())
  648. {
  649. effectsToRemove = getDanceCount() - Config.DANCES_MAX_AMOUNT;
  650. if (effectsToRemove >= 0)
  651. {
  652. for (L2Effect e : _buffs)
  653. {
  654. if (e == null || !e.getSkill().isDance())
  655. continue;
  656. // get first dance
  657. e.exit();
  658. effectsToRemove--;
  659. if (effectsToRemove < 0)
  660. break;
  661. }
  662. }
  663. }
  664. else
  665. {
  666. effectsToRemove = getBuffCount() - _owner.getMaxBuffCount();
  667. if (effectsToRemove >= 0)
  668. {
  669. switch (newSkill.getSkillType())
  670. {
  671. case BUFF:
  672. case REFLECT:
  673. case HEAL_PERCENT:
  674. case MANAHEAL_PERCENT:
  675. for (L2Effect e : _buffs)
  676. {
  677. if (e == null || e.getSkill().isDance())
  678. continue;
  679. switch (e.getSkill().getSkillType())
  680. {
  681. case BUFF:
  682. case REFLECT:
  683. case HEAL_PERCENT:
  684. case MANAHEAL_PERCENT:
  685. e.exit();
  686. effectsToRemove--;
  687. break; // break switch()
  688. default:
  689. continue; // continue for()
  690. }
  691. if (effectsToRemove < 0)
  692. break; // break for()
  693. }
  694. }
  695. }
  696. }
  697. }
  698. // Icons order: buffs, 7s, toggles, dances
  699. if (newSkill.isDance())
  700. _buffs.addLast(newEffect);
  701. else
  702. {
  703. int pos=0;
  704. if (newSkill.isToggle())
  705. {
  706. // toggle skill - before all dances
  707. for (L2Effect e : _buffs)
  708. {
  709. if (e == null)
  710. continue;
  711. if (e.getSkill().isDance())
  712. break;
  713. pos++;
  714. }
  715. }
  716. else
  717. {
  718. // normal buff - before toggles and 7s and dances
  719. for (L2Effect e : _buffs)
  720. {
  721. if (e == null)
  722. continue;
  723. if (e.getSkill().isToggle() || e.getSkill().is7Signs()
  724. || e.getSkill().isDance())
  725. break;
  726. pos++;
  727. }
  728. }
  729. _buffs.add(pos, newEffect);
  730. }
  731. }
  732. // Check if a stack group is defined for this effect
  733. if ("none".equals(newEffect.getStackType()))
  734. {
  735. // Set this L2Effect to In Use
  736. if (newEffect.setInUse(true))
  737. // Add Funcs of this effect to the Calculator set of the L2Character
  738. _owner.addStatFuncs(newEffect.getStatFuncs());
  739. return;
  740. }
  741. List<L2Effect> stackQueue;
  742. L2Effect effectToAdd = null;
  743. L2Effect effectToRemove = null;
  744. if (_stackedEffects == null) _stackedEffects = new FastMap<String, List<L2Effect>>();
  745. // Get the list of all stacked effects corresponding to the stack type of the L2Effect to add
  746. stackQueue = _stackedEffects.get(newEffect.getStackType());
  747. if (stackQueue != null)
  748. {
  749. int pos = 0;
  750. if (!stackQueue.isEmpty())
  751. {
  752. // Get the first stacked effect of the Stack group selected
  753. effectToRemove = listsContains(stackQueue.get(0));
  754. // Create an Iterator to go through the list of stacked effects in progress on the L2Character
  755. Iterator<L2Effect> queueIterator = stackQueue.iterator();
  756. while (queueIterator.hasNext())
  757. {
  758. if (newEffect.getStackOrder() < queueIterator.next().getStackOrder())
  759. pos++;
  760. else break;
  761. }
  762. // Add the new effect to the Stack list in function of its position in the Stack group
  763. stackQueue.add(pos, newEffect);
  764. // skill.exit() could be used, if the users don't wish to see "effect
  765. // removed" always when a timer goes off, even if the buff isn't active
  766. // any more (has been replaced). but then check e.g. npc hold and raid petrification.
  767. if (Config.EFFECT_CANCELING && !newEffect.isHerbEffect() && stackQueue.size() > 1)
  768. {
  769. if (newSkill.isDebuff())
  770. {
  771. _debuffs.remove(stackQueue.remove(1));
  772. }
  773. else
  774. {
  775. _buffs.remove(stackQueue.remove(1));
  776. }
  777. }
  778. }
  779. else
  780. stackQueue.add(0, newEffect);
  781. }
  782. else
  783. {
  784. stackQueue = new FastList<L2Effect>();
  785. stackQueue.add(0, newEffect);
  786. }
  787. // Update the Stack Group table _stackedEffects of the L2Character
  788. _stackedEffects.put(newEffect.getStackType(), stackQueue);
  789. // Get the first stacked effect of the Stack group selected
  790. if (stackQueue != null && !stackQueue.isEmpty())
  791. {
  792. effectToAdd = listsContains(stackQueue.get(0));
  793. }
  794. if (effectToRemove != effectToAdd)
  795. {
  796. if (effectToRemove != null)
  797. {
  798. // Remove all Func objects corresponding to this stacked effect from the Calculator set of the L2Character
  799. _owner.removeStatsOwner(effectToRemove);
  800. // Set the L2Effect to Not In Use
  801. effectToRemove.setInUse(false);
  802. }
  803. if (effectToAdd != null)
  804. {
  805. // Set this L2Effect to In Use
  806. if (effectToAdd.setInUse(true))
  807. // Add all Func objects corresponding to this stacked effect to the Calculator set of the L2Character
  808. _owner.addStatFuncs(effectToAdd.getStatFuncs());
  809. }
  810. }
  811. }
  812. protected void updateEffectIcons()
  813. {
  814. if (_owner == null || !(_owner instanceof L2Playable))
  815. return;
  816. AbnormalStatusUpdate mi = null;
  817. PartySpelled ps = null;
  818. if (_owner instanceof L2PcInstance)
  819. {
  820. if (_partyOnly)
  821. _partyOnly = false;
  822. else
  823. mi = new AbnormalStatusUpdate();
  824. if (_owner.isInParty())
  825. ps = new PartySpelled(_owner);
  826. }
  827. else
  828. if (_owner instanceof L2Summon)
  829. ps = new PartySpelled(_owner);
  830. boolean found = false;
  831. if (_buffs != null && !_buffs.isEmpty())
  832. {
  833. synchronized (_buffs)
  834. {
  835. for (L2Effect e : _buffs)
  836. {
  837. if (e == null)
  838. continue;
  839. if (e.getSkill().isRemovedOnAnyActionExceptMove())
  840. found = true;
  841. if (!e.getShowIcon())
  842. continue;
  843. switch (e.getEffectType())
  844. {
  845. case CHARGE: // handled by EtcStatusUpdate
  846. case SIGNET_GROUND:
  847. continue;
  848. }
  849. if (e.getInUse())
  850. {
  851. if (mi != null)
  852. e.addIcon(mi);
  853. if (ps != null)
  854. e.addPartySpelledIcon(ps);
  855. }
  856. }
  857. }
  858. }
  859. if (_debuffs != null && !_debuffs.isEmpty())
  860. {
  861. synchronized (_debuffs)
  862. {
  863. for (L2Effect e : _debuffs)
  864. {
  865. if (e == null)
  866. continue;
  867. if (e.getSkill().isRemovedOnAnyActionExceptMove())
  868. found = true;
  869. if (!e.getShowIcon())
  870. continue;
  871. switch (e.getEffectType())
  872. {
  873. case SIGNET_GROUND:
  874. continue;
  875. }
  876. if (e.getInUse())
  877. {
  878. if (mi != null)
  879. e.addIcon(mi);
  880. if (ps != null)
  881. e.addPartySpelledIcon(ps);
  882. }
  883. }
  884. }
  885. }
  886. _hasEffectsRemovedOnAnyAction = found;
  887. if (mi != null)
  888. _owner.sendPacket(mi);
  889. if (ps != null)
  890. {
  891. if (_owner instanceof L2Summon)
  892. {
  893. L2PcInstance summonOwner = ((L2Summon)_owner).getOwner();
  894. if (summonOwner != null)
  895. {
  896. if (summonOwner.isInParty())
  897. summonOwner.getParty().broadcastToPartyMembers(ps);
  898. else
  899. summonOwner.sendPacket(ps);
  900. }
  901. }
  902. else
  903. if (_owner instanceof L2PcInstance && _owner.isInParty())
  904. _owner.getParty().broadcastToPartyMembers(ps);
  905. }
  906. }
  907. /**
  908. * Returns effect if contains in _buffs or _debuffs and null if not found
  909. * @param effect
  910. * @return
  911. */
  912. private L2Effect listsContains(L2Effect effect)
  913. {
  914. if (_buffs != null && !_buffs.isEmpty()&& _buffs.contains(effect))
  915. return effect;
  916. if (_debuffs != null && !_debuffs.isEmpty() && _debuffs.contains(effect))
  917. return effect;
  918. return null;
  919. }
  920. /**
  921. * Clear and null all queues and lists
  922. * Use only during delete character from the world.
  923. */
  924. public void clear()
  925. {
  926. try
  927. {
  928. if (_addQueue != null)
  929. {
  930. _addQueue.clear();
  931. _addQueue = null;
  932. }
  933. if (_removeQueue != null)
  934. {
  935. _removeQueue.clear();
  936. _removeQueue = null;
  937. }
  938. _queuesInitialized = false;
  939. if (_buffs != null)
  940. {
  941. _buffs.clear();
  942. _buffs = null;
  943. }
  944. if (_debuffs != null)
  945. {
  946. _debuffs.clear();
  947. _debuffs = null;
  948. }
  949. if (_stackedEffects != null)
  950. {
  951. _stackedEffects.clear();
  952. _stackedEffects = null;
  953. }
  954. }
  955. catch (Exception e)
  956. {
  957. e.printStackTrace();
  958. }
  959. }
  960. }