From d542bffbff04162d907a67ea71340f2126f02f49 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 4 Oct 2012 18:20:10 +0200 Subject: [PATCH] ExchangeControlTargetEffect will now be removed from effects if it don't applies for a target. --- .../ExchangeControlTargetEffect.java | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/Mage/src/mage/abilities/effects/common/continious/ExchangeControlTargetEffect.java b/Mage/src/mage/abilities/effects/common/continious/ExchangeControlTargetEffect.java index 72f17ff6183..fa922a79bf1 100644 --- a/Mage/src/mage/abilities/effects/common/continious/ExchangeControlTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/continious/ExchangeControlTargetEffect.java @@ -25,9 +25,9 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ - + package mage.abilities.effects.common.continious; - + import java.util.*; import mage.Constants.Duration; import mage.Constants.Layer; @@ -38,38 +38,44 @@ import mage.abilities.Mode; import mage.abilities.effects.ContinuousEffectImpl; import mage.game.Game; import mage.game.permanent.Permanent; - + /** * @author magenoxx_at_googlemail.com */ public class ExchangeControlTargetEffect extends ContinuousEffectImpl { - + private String rule; private Boolean withSource; private Map lockedControllers; - + public ExchangeControlTargetEffect(Duration duration, String rule) { this(duration, rule, false); } - + public ExchangeControlTargetEffect(Duration duration, String rule, Boolean withSource) { super(duration, Layer.ControlChangingEffects_2, SubLayer.NA, Outcome.GainControl); this.withSource = withSource; this.rule = rule; } - + public ExchangeControlTargetEffect(final ExchangeControlTargetEffect effect) { super(effect); this.rule = effect.rule; this.withSource = effect.withSource; this.lockedControllers = effect.lockedControllers; } - + @Override public ExchangeControlTargetEffect copy() { return new ExchangeControlTargetEffect(this); } - + + @Override + public boolean isInactive(Ability source, Game game) { + // if there are no more creatures that are effected, the effect can be removed + return this.lockedControllers != null && this.lockedControllers.size() > 0; + } + @Override public void init(Ability source, Game game) { Set controllers = new HashSet(); @@ -88,13 +94,13 @@ public class ExchangeControlTargetEffect extends ContinuousEffectImpl(); - + Iterator it = controllers.iterator(); UUID firstController = it.next(); UUID secondController = it.next(); - + if (withSource) { Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source)); Permanent sourcePermanent = game.getPermanent(source.getSourceId()); @@ -112,7 +118,7 @@ public class ExchangeControlTargetEffect extends ContinuousEffectImpl