12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145 |
- /*
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package com.l2jserver.gameserver.model;
- import java.util.concurrent.LinkedBlockingQueue;
- import java.util.concurrent.atomic.AtomicBoolean;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import com.l2jserver.Config;
- import com.l2jserver.gameserver.model.actor.L2Character;
- import com.l2jserver.gameserver.model.actor.L2Playable;
- import com.l2jserver.gameserver.model.actor.L2Summon;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.model.olympiad.Olympiad;
- import com.l2jserver.gameserver.network.SystemMessageId;
- import com.l2jserver.gameserver.network.serverpackets.AbnormalStatusUpdate;
- import com.l2jserver.gameserver.network.serverpackets.ExOlympiadSpelledInfo;
- import com.l2jserver.gameserver.network.serverpackets.PartySpelled;
- import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
- import com.l2jserver.gameserver.templates.skills.L2EffectType;
- import com.l2jserver.gameserver.templates.skills.L2SkillType;
- import javolution.util.FastList;
- import javolution.util.FastMap;
- public class CharEffectList
- {
- private static final L2Effect[] EMPTY_EFFECTS = new L2Effect[0];
- private FastList<L2Effect> _buffs;
- private FastList<L2Effect> _debuffs;
- // The table containing the List of all stacked effect in progress for each Stack group Identifier
- private Map<String, List<L2Effect>> _stackedEffects;
- private volatile boolean _hasEffectsRemovedOnAnyAction = false;
- private boolean _queuesInitialized = false;
- private LinkedBlockingQueue<L2Effect> _addQueue;
- private LinkedBlockingQueue<L2Effect> _removeQueue;
- private AtomicBoolean queueLock = new AtomicBoolean();
- // only party icons need to be updated
- private boolean _partyOnly = false;
- // Owner of this list
- private L2Character _owner;
- public CharEffectList(L2Character owner)
- {
- _owner = owner;
- }
- /**
- * Returns all effects affecting stored in this CharEffectList
- * @return
- */
- public final L2Effect[] getAllEffects()
- {
- // If no effect is active, return EMPTY_EFFECTS
- if ( (_buffs == null || _buffs.isEmpty()) && (_debuffs == null || _debuffs.isEmpty()) )
- {
- return EMPTY_EFFECTS;
- }
- // Create a copy of the effects
- FastList<L2Effect> temp = FastList.newInstance();
- // Add all buffs and all debuffs
- if (_buffs != null)
- {
- synchronized (_buffs)
- {
- if (!_buffs.isEmpty())
- temp.addAll(_buffs);
- }
- }
- if (_debuffs != null)
- {
- synchronized (_debuffs)
- {
- if (!_debuffs.isEmpty())
- temp.addAll(_debuffs);
- }
- }
- // Return all effects in an array
- L2Effect[] tempArray = new L2Effect[temp.size()];
- temp.toArray(tempArray);
- FastList.recycle(temp);
- return tempArray;
- }
- /**
- * Returns the first effect matching the given EffectType
- * @param tp
- * @return
- */
- public final L2Effect getFirstEffect(L2EffectType tp)
- {
- L2Effect effectNotInUse = null;
- if (_buffs != null)
- {
- synchronized (_buffs)
- {
- if (!_buffs.isEmpty())
- {
- for (L2Effect e: _buffs)
- {
- if (e == null)
- continue;
- if (e.getEffectType() == tp)
- {
- if (e.getInUse())
- return e;
- else
- effectNotInUse = e;
- }
- }
- }
- }
- }
- if (effectNotInUse == null && _debuffs != null)
- {
- synchronized (_debuffs)
- {
- if (!_debuffs.isEmpty())
- {
- for (L2Effect e: _debuffs)
- {
- if (e == null)
- continue;
- if (e.getEffectType() == tp)
- {
- if (e.getInUse())
- return e;
- else
- effectNotInUse = e;
- }
- }
- }
- }
- }
- return effectNotInUse;
- }
- /**
- * Returns the first effect matching the given L2Skill
- * @param skill
- * @return
- */
- public final L2Effect getFirstEffect(L2Skill skill)
- {
- L2Effect effectNotInUse = null;
- if (skill.isDebuff())
- {
- if (_debuffs == null)
- return null;
- synchronized (_debuffs)
- {
- if (_debuffs.isEmpty())
- return null;
- for (L2Effect e: _debuffs)
- {
- if (e == null)
- continue;
- if (e.getSkill() == skill)
- {
- if (e.getInUse())
- return e;
- else
- effectNotInUse = e;
- }
- }
- }
- return effectNotInUse;
- }
- else
- {
- if (_buffs == null)
- return null;
- synchronized (_buffs)
- {
- if (_buffs.isEmpty())
- return null;
- for (L2Effect e: _buffs)
- {
- if (e == null)
- continue;
- if (e.getSkill() == skill)
- {
- if (e.getInUse())
- return e;
- else
- effectNotInUse = e;
- }
- }
- }
- return effectNotInUse;
- }
- }
- /**
- * Returns the first effect matching the given skillId
- * @param index
- * @return
- */
- public final L2Effect getFirstEffect(int skillId)
- {
- L2Effect effectNotInUse = null;
- if (_buffs != null)
- {
- synchronized (_buffs)
- {
- if (!_buffs.isEmpty())
- {
- for (L2Effect e: _buffs)
- {
- if (e == null)
- continue;
- if (e.getSkill().getId() == skillId)
- {
- if (e.getInUse())
- return e;
- else
- effectNotInUse = e;
- }
- }
- }
- }
- }
-
- if (effectNotInUse == null && _debuffs != null)
- {
- synchronized (_debuffs)
- {
- if (!_debuffs.isEmpty())
- {
- for (L2Effect e: _debuffs)
- {
- if (e == null)
- continue;
- if (e.getSkill().getId() == skillId)
- {
- if (e.getInUse())
- return e;
- else
- effectNotInUse = e;
- }
- }
- }
- }
- }
-
- return effectNotInUse;
- }
- /**
- * Checks if the given skill stacks with an existing one.
- *
- * @param checkSkill the skill to be checked
- *
- * @return Returns whether or not this skill will stack
- */
- private boolean doesStack(L2Skill checkSkill)
- {
- if ( (_buffs == null || _buffs.isEmpty()) ||
- checkSkill._effectTemplates == null ||
- checkSkill._effectTemplates.length < 1 ||
- checkSkill._effectTemplates[0].stackType == null ||
- "none".equals(checkSkill._effectTemplates[0].stackType))
- {
- return false;
- }
- String stackType = checkSkill._effectTemplates[0].stackType;
- for (L2Effect e : _buffs)
- {
- if (e.getStackType() != null && e.getStackType().equals(stackType))
- {
- return true;
- }
- }
- return false;
- }
- /**
- * Return the number of buffs in this CharEffectList not counting Songs/Dances
- * @return
- */
- public int getBuffCount()
- {
- if (_buffs == null) return 0;
- int buffCount=0;
-
- synchronized(_buffs)
- {
- if (_buffs.isEmpty())
- return 0;
- for (L2Effect e : _buffs)
- {
- if (e != null && e.getShowIcon() && !e.getSkill().isDance() && !e.getSkill().is7Signs())
- {
- switch (e.getSkill().getSkillType())
- {
- case BUFF:
- case REFLECT:
- case HEAL_PERCENT:
- case MANAHEAL_PERCENT:
- buffCount++;
- }
- }
- }
- }
- return buffCount;
- }
- /**
- * Return the number of Songs/Dances in this CharEffectList
- * @return
- */
- public int getDanceCount()
- {
- if (_buffs == null) return 0;
- int danceCount = 0;
- synchronized(_buffs)
- {
- if (_buffs.isEmpty())
- return 0;
- for (L2Effect e : _buffs)
- {
- if (e != null && e.getSkill().isDance() && e.getInUse())
- danceCount++;
- }
- }
- return danceCount;
- }
- /**
- * Exits all effects in this CharEffectList
- */
- public final void stopAllEffects()
- {
- // Get all active skills effects from this list
- L2Effect[] effects = getAllEffects();
- // Exit them
- for (L2Effect e : effects)
- {
- if (e != null)
- e.exit(true);
- }
- }
-
- /**
- * Exits all effects in this CharEffectList
- */
- public final void stopAllEffectsExceptThoseThatLastThroughDeath()
- {
- // Get all active skills effects from this list
- L2Effect[] effects = getAllEffects();
- // Exit them
- for (L2Effect e : effects)
- {
- if (e != null && !e.getSkill().isStayAfterDeath())
- e.exit(true);
- }
- }
- /**
- * Exit all toggle-type effects
- */
- public void stopAllToggles()
- {
- if (_buffs != null)
- {
- synchronized (_buffs)
- {
- if (!_buffs.isEmpty())
- {
- for (L2Effect e : _buffs)
- if (e != null && e.getSkill().isToggle())
- e.exit();
- }
- }
- }
- }
- /**
- * Exit all effects having a specified type
- * @param type
- */
- public final void stopEffects(L2EffectType type)
- {
- // Go through all active skills effects
- FastList<L2Effect> temp = FastList.newInstance();
- if (_buffs != null)
- {
- synchronized (_buffs)
- {
- if (!_buffs.isEmpty())
- {
- for (L2Effect e : _buffs)
- // Get active skills effects of the selected type
- if (e != null && e.getEffectType() == type)
- temp.add(e);
- }
- }
- }
- if (_debuffs != null)
- {
- synchronized (_debuffs)
- {
- if (!_debuffs.isEmpty())
- {
- for (L2Effect e : _debuffs)
- // Get active skills effects of the selected type
- if (e != null && e.getEffectType() == type)
- temp.add(e);
- }
- }
- }
- if (!temp.isEmpty())
- {
- for (L2Effect e : temp)
- if (e != null)
- e.exit();
- }
- FastList.recycle(temp);
- }
- /**
- * Exits all effects created by a specific skillId
- * @param skillId
- */
- public final void stopSkillEffects(int skillId)
- {
- // Go through all active skills effects
- FastList<L2Effect> temp = FastList.newInstance();
- if (_buffs != null)
- {
- synchronized (_buffs)
- {
- if (!_buffs.isEmpty())
- {
- for (L2Effect e : _buffs)
- if (e != null && e.getSkill().getId() == skillId)
- temp.add(e);
- }
- }
- }
- if (_debuffs != null)
- {
- synchronized (_debuffs)
- {
- if (!_debuffs.isEmpty())
- {
- for (L2Effect e : _debuffs)
- if (e != null && e.getSkill().getId() == skillId)
- temp.add(e);
- }
- }
- }
- if (!temp.isEmpty())
- {
- for (L2Effect e : temp)
- if (e != null)
- e.exit();
- }
- FastList.recycle(temp);
- }
-
- /**
- * Exits all effects created by a specific skill type
- * @param skillType skill type
- */
- public final void stopSkillEffects(L2SkillType skillType, int negateLvl)
- {
- // Go through all active skills effects
- FastList<L2Effect> temp = FastList.newInstance();
- if (_buffs != null)
- {
- synchronized (_buffs)
- {
- if (!_buffs.isEmpty())
- {
- for (L2Effect e : _buffs)
- {
- if (e != null && (e.getSkill().getSkillType() == skillType || (e.getSkill().getEffectType() != null && e.getSkill().getEffectType() == skillType))
- && (negateLvl == -1 || (e.getSkill().getEffectType() != null && e.getSkill().getEffectAbnormalLvl() >= 0 && e.getSkill().getEffectAbnormalLvl() <= negateLvl) || (e.getSkill().getAbnormalLvl() >= 0 && e.getSkill().getAbnormalLvl() <= negateLvl)))
- temp.add(e);
- }
- }
- }
- }
- if (_debuffs != null)
- {
- synchronized (_debuffs)
- {
- if (!_debuffs.isEmpty())
- {
- for (L2Effect e : _debuffs)
- {
- if (e != null && (e.getSkill().getSkillType() == skillType || (e.getSkill().getEffectType() != null && e.getSkill().getEffectType() == skillType))
- && (negateLvl == -1 || (e.getSkill().getEffectType() != null && e.getSkill().getEffectAbnormalLvl() >= 0 && e.getSkill().getEffectAbnormalLvl() <= negateLvl) || (e.getSkill().getAbnormalLvl() >= 0 && e.getSkill().getAbnormalLvl() <= negateLvl)))
- temp.add(e);
- }
- }
- }
- }
- if (!temp.isEmpty())
- {
- for (L2Effect e : temp)
- if (e != null)
- e.exit();
- }
- FastList.recycle(temp);
- }
- /**
- * Exits all buffs effects of the skills with "removedOnAnyAction" set.
- * Called on any action except movement (attack, cast).
- */
- public void stopEffectsOnAction()
- {
- if (_hasEffectsRemovedOnAnyAction)
- {
- if (_buffs != null)
- {
- synchronized (_buffs)
- {
- if (!_buffs.isEmpty())
- {
- for (L2Effect e : _buffs)
- if (e != null && e.getSkill().isRemovedOnAnyActionExceptMove())
- e.exit(true);
- }
- }
- }
- }
- }
- public void updateEffectIcons(boolean partyOnly)
- {
- if (_buffs == null && _debuffs == null)
- return;
- if (partyOnly)
- _partyOnly = true;
-
- queueRunner();
- }
- public void queueEffect(L2Effect effect, boolean remove)
- {
- if (effect == null) return;
- if (!_queuesInitialized)
- init();
- if (remove)
- _removeQueue.offer(effect);
- else
- _addQueue.offer(effect);
- queueRunner();
- }
- synchronized private void init()
- {
- _addQueue = new LinkedBlockingQueue<L2Effect>();
- _removeQueue = new LinkedBlockingQueue<L2Effect>();
- _queuesInitialized = true;
- }
- private void queueRunner()
- {
- if (!queueLock.compareAndSet(false, true))
- return;
- try
- {
- L2Effect effect;
- do
- {
- // remove has more priority than add
- // so removing all effects from queue first
- while ((effect = _removeQueue.poll()) != null)
- {
- removeEffectFromQueue(effect);
- _partyOnly = false;
- }
- if ((effect = _addQueue.poll()) != null)
- {
- addEffectFromQueue(effect);
- _partyOnly = false;
- }
- }
- while (!_addQueue.isEmpty() || !_removeQueue.isEmpty());
-
- updateEffectIcons();
- }
- finally
- {
- queueLock.set(false);
- }
- }
-
- protected void removeEffectFromQueue(L2Effect effect)
- {
- if (effect == null) return;
- FastList<L2Effect> effectList;
-
- if (effect.getSkill().isDebuff())
- {
- if (_debuffs == null)
- return;
- effectList = _debuffs;
- }
- else
- {
- if (_buffs == null)
- return;
- effectList = _buffs;
- }
- if ("none".equals(effect.getStackType()))
- {
- // Remove Func added by this effect from the L2Character Calculator
- _owner.removeStatsOwner(effect);
- }
- else
- {
- if(_stackedEffects == null) return;
- // Get the list of all stacked effects corresponding to the stack type of the L2Effect to add
- List<L2Effect> stackQueue = _stackedEffects.get(effect.getStackType());
- if (stackQueue == null || stackQueue.isEmpty()) return;
- int index = stackQueue.indexOf(effect);
- // Remove the effect from the stack group
- if (index >= 0)
- {
- stackQueue.remove(effect);
- // Check if the first stacked effect was the effect to remove
- if (index == 0)
- {
- // Remove all its Func objects from the L2Character calculator set
- _owner.removeStatsOwner(effect);
- // Check if there's another effect in the Stack Group
- if (!stackQueue.isEmpty())
- {
- L2Effect newStackedEffect = listsContains(stackQueue.get(0));
- if (newStackedEffect != null)
- {
- // Set the effect to In Use
- if (newStackedEffect.setInUse(true))
- // Add its list of Funcs to the Calculator set of the L2Character
- _owner.addStatFuncs(newStackedEffect.getStatFuncs());
- }
- }
- }
- if (stackQueue.isEmpty())
- _stackedEffects.remove(effect.getStackType());
- else
- // Update the Stack Group table _stackedEffects of the L2Character
- _stackedEffects.put(effect.getStackType(), stackQueue);
- }
- }
- // Remove the active skill L2effect from _effects of the L2Character
- if (effectList.remove(effect) && _owner instanceof L2PcInstance && effect.getShowIcon())
- {
- SystemMessage sm;
- if (effect.getSkill().isToggle())
- {
- sm = new SystemMessage(SystemMessageId.S1_HAS_BEEN_ABORTED);
- }
- else
- {
- sm = new SystemMessage(SystemMessageId.EFFECT_S1_DISAPPEARED);
- }
- sm.addSkillName(effect);
- _owner.sendPacket(sm);
- }
- }
- protected void addEffectFromQueue(L2Effect newEffect)
- {
- if (newEffect == null) return;
- L2Skill newSkill = newEffect.getSkill();
- if (newSkill.isDebuff())
- {
- if (_debuffs == null) _debuffs = new FastList<L2Effect>().shared();
- for (L2Effect e : _debuffs)
- {
- if (e != null
- && e.getSkill().getId() == newEffect.getSkill().getId()
- && e.getEffectType() == newEffect.getEffectType()
- && e.getStackOrder() == newEffect.getStackOrder()
- && e.getStackType().equals(newEffect.getStackType()))
- {
- // Started scheduled timer needs to be canceled.
- newEffect.stopEffectTask();
- return;
- }
- }
- _debuffs.addLast(newEffect);
- }
- else
- {
- if (_buffs == null) _buffs = new FastList<L2Effect>().shared();
- for (L2Effect e : _buffs)
- {
- if (e != null
- && e.getSkill().getId() == newEffect.getSkill().getId()
- && e.getEffectType() == newEffect.getEffectType()
- && e.getStackOrder() == newEffect.getStackOrder()
- && e.getStackType().equals(newEffect.getStackType()))
- {
- e.exit(); // exit this
- }
- }
- // if max buffs, no herb effects are used, even if they would replace one old
- if (newEffect.isHerbEffect() && getBuffCount() >= _owner.getMaxBuffCount())
- {
- newEffect.stopEffectTask();
- return;
- }
- // Remove first buff when buff list is full
- if (!doesStack(newSkill) && !newSkill.is7Signs())
- {
- int effectsToRemove;
- if (newSkill.isDance())
- {
- effectsToRemove = getDanceCount() - Config.DANCES_MAX_AMOUNT;
- if (effectsToRemove >= 0)
- {
- for (L2Effect e : _buffs)
- {
- if (e == null || !e.getSkill().isDance())
- continue;
-
- // get first dance
- e.exit();
- effectsToRemove--;
- if (effectsToRemove < 0)
- break;
- }
- }
- }
- else
- {
- effectsToRemove = getBuffCount() - _owner.getMaxBuffCount();
- if (effectsToRemove >= 0)
- {
- switch (newSkill.getSkillType())
- {
- case BUFF:
- case REFLECT:
- case HEAL_PERCENT:
- case MANAHEAL_PERCENT:
- for (L2Effect e : _buffs)
- {
- if (e == null || e.getSkill().isDance())
- continue;
- switch (e.getSkill().getSkillType())
- {
- case BUFF:
- case REFLECT:
- case HEAL_PERCENT:
- case MANAHEAL_PERCENT:
- e.exit();
- effectsToRemove--;
- break; // break switch()
- default:
- continue; // continue for()
- }
- if (effectsToRemove < 0)
- break; // break for()
- }
- }
- }
- }
- }
- // Icons order: buffs, 7s, toggles, dances
- if (newSkill.isDance())
- _buffs.addLast(newEffect);
- else
- {
- int pos=0;
- if (newSkill.isToggle())
- {
- // toggle skill - before all dances
- for (L2Effect e : _buffs)
- {
- if (e == null)
- continue;
- if (e.getSkill().isDance())
- break;
- pos++;
- }
- }
- else
- {
- // normal buff - before toggles and 7s and dances
- for (L2Effect e : _buffs)
- {
- if (e == null)
- continue;
- if (e.getSkill().isToggle() || e.getSkill().is7Signs()
- || e.getSkill().isDance())
- break;
- pos++;
- }
- }
- _buffs.add(pos, newEffect);
- }
- }
- // Check if a stack group is defined for this effect
- if ("none".equals(newEffect.getStackType()))
- {
- // Set this L2Effect to In Use
- if (newEffect.setInUse(true))
- // Add Funcs of this effect to the Calculator set of the L2Character
- _owner.addStatFuncs(newEffect.getStatFuncs());
- return;
- }
- List<L2Effect> stackQueue;
- L2Effect effectToAdd = null;
- L2Effect effectToRemove = null;
- if (_stackedEffects == null) _stackedEffects = new FastMap<String, List<L2Effect>>();
-
- // Get the list of all stacked effects corresponding to the stack type of the L2Effect to add
- stackQueue = _stackedEffects.get(newEffect.getStackType());
-
- if (stackQueue != null)
- {
- int pos = 0;
- if (!stackQueue.isEmpty())
- {
- // Get the first stacked effect of the Stack group selected
- effectToRemove = listsContains(stackQueue.get(0));
- // Create an Iterator to go through the list of stacked effects in progress on the L2Character
- Iterator<L2Effect> queueIterator = stackQueue.iterator();
- while (queueIterator.hasNext())
- {
- if (newEffect.getStackOrder() < queueIterator.next().getStackOrder())
- pos++;
- else break;
- }
- // Add the new effect to the Stack list in function of its position in the Stack group
- stackQueue.add(pos, newEffect);
- // skill.exit() could be used, if the users don't wish to see "effect
- // removed" always when a timer goes off, even if the buff isn't active
- // any more (has been replaced). but then check e.g. npc hold and raid petrification.
- if (Config.EFFECT_CANCELING && !newEffect.isHerbEffect() && stackQueue.size() > 1)
- {
- if (newSkill.isDebuff())
- {
- _debuffs.remove(stackQueue.remove(1));
- }
- else
- {
- _buffs.remove(stackQueue.remove(1));
- }
- }
- }
- else
- stackQueue.add(0, newEffect);
- }
- else
- {
- stackQueue = new FastList<L2Effect>();
- stackQueue.add(0, newEffect);
- }
- // Update the Stack Group table _stackedEffects of the L2Character
- _stackedEffects.put(newEffect.getStackType(), stackQueue);
- // Get the first stacked effect of the Stack group selected
- if (!stackQueue.isEmpty())
- {
- effectToAdd = listsContains(stackQueue.get(0));
- }
- if (effectToRemove != effectToAdd)
- {
- if (effectToRemove != null)
- {
- // Remove all Func objects corresponding to this stacked effect from the Calculator set of the L2Character
- _owner.removeStatsOwner(effectToRemove);
- // Set the L2Effect to Not In Use
- effectToRemove.setInUse(false);
- }
- if (effectToAdd != null)
- {
- // Set this L2Effect to In Use
- if (effectToAdd.setInUse(true))
- // Add all Func objects corresponding to this stacked effect to the Calculator set of the L2Character
- _owner.addStatFuncs(effectToAdd.getStatFuncs());
- }
- }
- }
- protected void updateEffectIcons()
- {
- if (_owner == null || !(_owner instanceof L2Playable))
- return;
- AbnormalStatusUpdate mi = null;
- PartySpelled ps = null;
- ExOlympiadSpelledInfo os = null;
-
- if (_owner instanceof L2PcInstance)
- {
- if (_partyOnly)
- _partyOnly = false;
- else
- mi = new AbnormalStatusUpdate();
- if (_owner.isInParty())
- ps = new PartySpelled(_owner);
- if (((L2PcInstance)_owner).isInOlympiadMode() && ((L2PcInstance)_owner).isOlympiadStart())
- os = new ExOlympiadSpelledInfo((L2PcInstance)_owner);
- }
- else
- if (_owner instanceof L2Summon)
- ps = new PartySpelled(_owner);
- boolean found = false;
- if (_buffs != null && !_buffs.isEmpty())
- {
- synchronized (_buffs)
- {
- for (L2Effect e : _buffs)
- {
- if (e == null)
- continue;
- if (e.getSkill().isRemovedOnAnyActionExceptMove())
- found = true;
- if (!e.getShowIcon())
- continue;
- switch (e.getEffectType())
- {
- case CHARGE: // handled by EtcStatusUpdate
- case SIGNET_GROUND:
- continue;
- }
-
- if (e.getInUse())
- {
- if (mi != null)
- e.addIcon(mi);
-
- if (ps != null)
- e.addPartySpelledIcon(ps);
- if (os != null)
- e.addOlympiadSpelledIcon(os);
- }
- }
- }
- }
- if (_debuffs != null && !_debuffs.isEmpty())
- {
- synchronized (_debuffs)
- {
- for (L2Effect e : _debuffs)
- {
- if (e == null)
- continue;
- if (e.getSkill().isRemovedOnAnyActionExceptMove())
- found = true;
- if (!e.getShowIcon())
- continue;
- switch (e.getEffectType())
- {
- case SIGNET_GROUND:
- continue;
- }
- if (e.getInUse())
- {
- if (mi != null)
- e.addIcon(mi);
-
- if (ps != null)
- e.addPartySpelledIcon(ps);
- if (os != null)
- e.addOlympiadSpelledIcon(os);
- }
- }
- }
- }
- _hasEffectsRemovedOnAnyAction = found;
- if (mi != null)
- _owner.sendPacket(mi);
- if (ps != null)
- {
- if (_owner instanceof L2Summon)
- {
- L2PcInstance summonOwner = ((L2Summon)_owner).getOwner();
- if (summonOwner != null)
- {
- if (summonOwner.isInParty())
- summonOwner.getParty().broadcastToPartyMembers(ps);
- else
- summonOwner.sendPacket(ps);
- }
- }
- else
- if (_owner instanceof L2PcInstance && _owner.isInParty())
- _owner.getParty().broadcastToPartyMembers(ps);
- }
- if (os != null)
- {
- final List<L2PcInstance> specs = Olympiad.getInstance().getSpectators(((L2PcInstance)_owner).getOlympiadGameId());
- if (specs != null && !specs.isEmpty())
- {
- for (L2PcInstance spec : specs)
- {
- if (spec != null)
- spec.sendPacket(os);
- }
- }
- }
- }
- /**
- * Returns effect if contains in _buffs or _debuffs and null if not found
- * @param effect
- * @return
- */
- private L2Effect listsContains(L2Effect effect)
- {
- if (_buffs != null && !_buffs.isEmpty()&& _buffs.contains(effect))
- return effect;
- if (_debuffs != null && !_debuffs.isEmpty() && _debuffs.contains(effect))
- return effect;
- return null;
- }
- /**
- * Clear and null all queues and lists
- * Use only during delete character from the world.
- */
- public void clear()
- {
- try
- {
- if (_addQueue != null)
- {
- _addQueue.clear();
- _addQueue = null;
- }
- if (_removeQueue != null)
- {
- _removeQueue.clear();
- _removeQueue = null;
- }
- _queuesInitialized = false;
- if (_buffs != null)
- {
- _buffs.clear();
- _buffs = null;
- }
- if (_debuffs != null)
- {
- _debuffs.clear();
- _debuffs = null;
- }
- if (_stackedEffects != null)
- {
- _stackedEffects.clear();
- _stackedEffects = null;
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- }
|