CharEffectList.java 25 KB

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