123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- /*
- * Copyright (C) 2004-2013 L2J Server
- *
- * This file is part of L2J Server.
- *
- * L2J Server 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.
- *
- * L2J Server 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.effects;
- import java.lang.reflect.Constructor;
- import java.lang.reflect.InvocationTargetException;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import java.util.logging.Logger;
- import com.l2jserver.gameserver.handler.EffectHandler;
- import com.l2jserver.gameserver.model.ChanceCondition;
- import com.l2jserver.gameserver.model.StatsSet;
- import com.l2jserver.gameserver.model.conditions.Condition;
- import com.l2jserver.gameserver.model.interfaces.IChanceSkillTrigger;
- import com.l2jserver.gameserver.model.skills.AbnormalVisualEffect;
- import com.l2jserver.gameserver.model.skills.BuffInfo;
- import com.l2jserver.gameserver.model.skills.funcs.Func;
- import com.l2jserver.gameserver.model.skills.funcs.FuncTemplate;
- import com.l2jserver.gameserver.model.stats.Env;
- /**
- * Abstract effect implementation.<br>
- * Instant effects should not override {@link #onExit(BuffInfo)}.<br>
- * Instant effects should not override {@link #canStart(BuffInfo)}, all checks should be done {@link #onStart(BuffInfo)}. Do not call super class methods {@link #onStart(BuffInfo)} nor {@link #onExit(BuffInfo)}.<br>
- * @since <a href="http://trac.l2jserver.com/changeset/6249">Changeset 6249</a> the "effect steal constructor" is deprecated.
- * @author Zoey76
- */
- public abstract class AbstractEffect implements IChanceSkillTrigger
- {
- protected static final Logger _log = Logger.getLogger(AbstractEffect.class.getName());
-
- // Conditions
- private final Condition _attachCond;
- // private final Condition _applyCond; // TODO: Use or cleanup.
- // Abnormal visual effect
- private final AbnormalVisualEffect _abnormalEffect;
- private final AbnormalVisualEffect[] _specialEffect;
- private final AbnormalVisualEffect _eventEffect;
- private List<FuncTemplate> _funcTemplates;
- private final String _name;
- private final double _val;
- private final boolean _isSelfEffect;
- /** Ticks. */
- private final int _ticks;
- private final int _triggeredId;
- private final int _triggeredLevel;
- private final ChanceCondition _chanceCondition;
- private final StatsSet _parameters;
-
- /**
- * Abstract effect constructor.
- * @param attachCond
- * @param applyCond
- * @param set
- * @param params
- */
- protected AbstractEffect(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
- {
- _attachCond = attachCond;
- // _applyCond = applyCond;
- _name = set.getString("name");
- _val = set.getDouble("val", 0);
- _isSelfEffect = set.getInt("self", 0) == 1;
- _ticks = set.getInt("ticks", 0);
- _abnormalEffect = AbnormalVisualEffect.getByName(set.getString("abnormalVisualEffect", ""));
- final String[] specialEffects = set.getString("special", "").split(",");
- _specialEffect = new AbnormalVisualEffect[specialEffects.length];
- for (int i = 0; i < specialEffects.length; i++)
- {
- _specialEffect[i] = AbnormalVisualEffect.getByName(specialEffects[i]);
- }
- _eventEffect = AbnormalVisualEffect.getByName(set.getString("event", ""));
- _triggeredId = set.getInt("triggeredId", 0);
- _triggeredLevel = set.getInt("triggeredLevel", 1);
- _chanceCondition = ChanceCondition.parse(set.getString("chanceType", null), set.getInt("activationChance", -1), set.getInt("activationMinDamage", -1), set.getString("activationElements", null), set.getString("activationSkills", null), set.getBoolean("pvpChanceOnly", false));
- _parameters = params;
- }
-
- public static final AbstractEffect createEffect(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
- {
- final String name = set.getString("name");
- final Class<? extends AbstractEffect> handler = EffectHandler.getInstance().getHandler(name);
- if (handler == null)
- {
- _log.warning(AbstractEffect.class.getSimpleName() + ": Requested unexistent effect handler: " + name);
- return null;
- }
-
- final Constructor<?> constructor;
- try
- {
- constructor = handler.getConstructor(Condition.class, Condition.class, StatsSet.class, StatsSet.class);
- }
- catch (NoSuchMethodException | SecurityException e1)
- {
- _log.warning(AbstractEffect.class.getSimpleName() + ": Requested unexistent constructor for effect handler: " + name);
- e1.printStackTrace();
- return null;
- }
-
- try
- {
- return (AbstractEffect) constructor.newInstance(attachCond, applyCond, set, params);
- }
- catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e)
- {
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * Tests the attach condition.
- * @param env the data
- * @return {@code true} if there isn't a condition to test or it's passed, {@code false} otherwise
- */
- public boolean testConditions(Env env)
- {
- return (_attachCond == null) || _attachCond.test(env);
- }
-
- /**
- * Attachs a function template.
- * @param f the function
- */
- public void attach(FuncTemplate f)
- {
- if (_funcTemplates == null)
- {
- _funcTemplates = new ArrayList<>(1);
- }
- _funcTemplates.add(f);
- }
-
- /**
- * Gets the effect name.
- * @return the name
- */
- public String getName()
- {
- return _name;
- }
-
- /**
- * Verify if this is a self-effect.
- * @return {@code true} if it is a self-effect, {@code false} otherwise
- */
- public boolean isSelfEffect()
- {
- return _isSelfEffect;
- }
-
- /**
- * Gets the generic value.
- * @return the value
- */
- public double getValue()
- {
- return _val;
- }
-
- /**
- * Gets the effect ticks
- * @return the ticks
- */
- public int getTicks()
- {
- return _ticks;
- }
-
- public AbnormalVisualEffect getAbnormalEffect()
- {
- return _abnormalEffect;
- }
-
- public AbnormalVisualEffect[] getSpecialEffect()
- {
- return _specialEffect;
- }
-
- public AbnormalVisualEffect getEventEffect()
- {
- return _eventEffect;
- }
-
- public List<FuncTemplate> getFuncTemplates()
- {
- return _funcTemplates;
- }
-
- @Override
- public int getTriggeredChanceId()
- {
- return _triggeredId;
- }
-
- @Override
- public int getTriggeredChanceLevel()
- {
- return _triggeredLevel;
- }
-
- @Override
- public ChanceCondition getTriggeredChanceCondition()
- {
- return _chanceCondition;
- }
-
- /**
- * Verify if this effect template has parameters.
- * @return {@code true} if this effect template has parameters, {@code false} otherwise
- */
- public boolean hasParameters()
- {
- return _parameters != null;
- }
-
- /**
- * Get the parameters.
- * @return the parameters of this effect template
- */
- public StatsSet getParameters()
- {
- return _parameters;
- }
-
- /**
- * Calculates whether this effects land or not.<br>
- * If it lands will be scheduled and added to the character effect list.<br>
- * Override in effect implementation to change behavior. <br>
- * <b>Warning:</b> Must be used only for instant effects continuous effects will not call this they have their success handled by activate_rate.
- * @param info the buff info
- * @return {@code true} if this effect land, {@code false} otherwise
- */
- public boolean calcSuccess(BuffInfo info)
- {
- return true;
- }
-
- /**
- * Get this effect's type.<br>
- * TODO: Remove.
- * @return the effect type
- */
- public L2EffectType getEffectType()
- {
- return L2EffectType.NONE;
- }
-
- /**
- * Verify if the buff can start.<br>
- * Used for continuous effects.
- * @param info the buff info
- * @return {@code true} if all the start conditions are meet, {@code false} otherwise
- */
- public boolean canStart(BuffInfo info)
- {
- return true;
- }
-
- /**
- * Called on effect start.
- * @param info the buff info
- */
- public void onStart(BuffInfo info)
- {
-
- }
-
- /**
- * Called on each tick.<br>
- * If the abnormal time is lesser than zero it will last forever.
- * @param info the buff info
- * @return if {@code true} this effect will continue forever, if {@code false} it will stop after abnormal time has passed
- */
- public boolean onActionTime(BuffInfo info)
- {
- return false;
- }
-
- /**
- * Called when the effect is exited.
- * @param info the buff info
- */
- public void onExit(BuffInfo info)
- {
-
- }
-
- /**
- * Get this effect's stats functions.
- * @param env the data
- * @return a list of stat functions.
- */
- public List<Func> getStatFuncs(Env env)
- {
- if (getFuncTemplates() == null)
- {
- return Collections.<Func> emptyList();
- }
-
- final List<Func> funcs = new ArrayList<>(getFuncTemplates().size());
- for (FuncTemplate t : getFuncTemplates())
- {
- final Func f = t.getFunc(env, this);
- if (f != null)
- {
- funcs.add(f);
- }
- }
- return funcs;
- }
-
- /**
- * Get the effect flags.
- * @return bit flag for current effect
- */
- public int getEffectFlags()
- {
- return EffectFlag.NONE.getMask();
- }
-
- @Override
- public String toString()
- {
- return "Effect " + _name;
- }
-
- public void decreaseForce()
- {
-
- }
-
- public void increaseEffect()
- {
-
- }
-
- public boolean checkCondition(Object obj)
- {
- return true;
- }
-
- @Override
- public boolean triggersChanceSkill()
- {
- return _triggeredId > 0;
- }
-
- /**
- * Verify if this effect is an instant effect.
- * @return {@code true} if this effect is instant, {@code false} otherwise
- */
- public boolean isInstant()
- {
- return false;
- }
- }
|