/* * 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 silentium.gameserver.skills.effects; import java.util.Collection; import java.util.List; import javolution.util.FastList; import silentium.commons.utils.Rnd; import silentium.gameserver.ai.CtrlIntention; import silentium.gameserver.model.CharEffectList; import silentium.gameserver.model.L2Effect; import silentium.gameserver.model.L2Object; import silentium.gameserver.model.actor.L2Attackable; import silentium.gameserver.model.actor.L2Character; import silentium.gameserver.model.actor.instance.L2ChestInstance; import silentium.gameserver.model.actor.instance.L2DoorInstance; import silentium.gameserver.skills.Env; import silentium.gameserver.templates.skills.L2EffectType; /** * This effect changes the target of the victim. It adds some random aggro aswell to force the monster to keep attacking. As the added aggro is * random, the victim can often change of target.<br> * <br> * Only others mobs can fill the aggroList of the victim. For a more generic use, consider using EffectConfusion. * * @author littlecrow, Tryskell */ public class EffectConfuseMob extends L2Effect { public EffectConfuseMob(Env env, EffectTemplate template) { super(env, template); } @Override public L2EffectType getEffectType() { return L2EffectType.CONFUSE_MOB_ONLY; } /** Notify started */ @Override public boolean onStart() { getEffected().startConfused(); onActionTime(); return true; } /** Notify exited */ @Override public void onExit() { getEffected().stopConfused(this); } @Override public boolean onActionTime() { List<L2Character> targetList = new FastList<>(); // Getting the possible targets Collection<L2Object> objs = getEffected().getKnownList().getKnownObjects().values(); for (L2Object obj : objs) { // Only attackable NPCs are put in the list. if ((obj instanceof L2Attackable) && (obj != getEffected())) // Don't put doors nor chests on it. if (!(obj instanceof L2DoorInstance || obj instanceof L2ChestInstance)) targetList.add((L2Character) obj); } // if there is no target, exit function if (targetList.isEmpty()) return true; // Choosing randomly a new target int nextTargetIdx = Rnd.nextInt(targetList.size()); L2Object target = targetList.get(nextTargetIdx); // Attacking the target getEffected().setTarget(target); getEffected().getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target); // Add aggro to that target aswell. The aggro power is random. int aggro = (5 + Rnd.get(5)) * getEffector().getLevel(); ((L2Attackable) getEffected()).addDamageHate((L2Character) target, 0, aggro); return true; } @Override public int getEffectFlags() { return CharEffectList.EFFECT_FLAG_CONFUSED; } }