diff --git a/Mage.Sets/src/mage/sets/betrayersofkamigawa/HokoriDustDrinker.java b/Mage.Sets/src/mage/sets/betrayersofkamigawa/HokoriDustDrinker.java index d83ecf7cd47..e4c71f5231f 100644 --- a/Mage.Sets/src/mage/sets/betrayersofkamigawa/HokoriDustDrinker.java +++ b/Mage.Sets/src/mage/sets/betrayersofkamigawa/HokoriDustDrinker.java @@ -38,15 +38,13 @@ import mage.abilities.Ability; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.OneShotEffect; -import mage.abilities.effects.ReplacementEffectImpl; +import mage.abilities.effects.common.SkipUntapAllEffect; import mage.cards.CardImpl; import mage.constants.Duration; -import mage.constants.PhaseStep; import mage.constants.TargetController; import mage.filter.common.FilterLandPermanent; import mage.filter.predicate.permanent.ControllerIdPredicate; import mage.game.Game; -import mage.game.events.GameEvent; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.Target; @@ -67,7 +65,7 @@ public class HokoriDustDrinker extends CardImpl { this.toughness = new MageInt(1); // Lands don't untap during their controllers' untap steps. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new HokoriDustDrinkerReplacementEffect())); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SkipUntapAllEffect(Duration.WhileOnBattlefield, TargetController.ANY, new FilterLandPermanent("Lands")))); // At the beginning of each player's upkeep, that player untaps a land he or she controls. this.addAbility(new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, new HokoriDustDrinkerUntapEffect(), TargetController.ANY, false)); @@ -85,47 +83,6 @@ public class HokoriDustDrinker extends CardImpl { } } -class HokoriDustDrinkerReplacementEffect extends ReplacementEffectImpl { - - public HokoriDustDrinkerReplacementEffect() { - super(Duration.OneUse, Outcome.Detriment); - } - - public HokoriDustDrinkerReplacementEffect(final HokoriDustDrinkerReplacementEffect effect) { - super(effect); - staticText = "Lands don't untap during their controllers' untap steps"; - } - - @Override - public HokoriDustDrinkerReplacementEffect copy() { - return new HokoriDustDrinkerReplacementEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - return false; - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - return true; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (game.getTurn().getStepType() == PhaseStep.UNTAP && - event.getType() == GameEvent.EventType.UNTAP) { - Permanent permanent = game.getPermanent(event.getTargetId()); - if (permanent.getCardType().contains(CardType.LAND)) { - return true; - } - } - return false; - } - -} - - class HokoriDustDrinkerUntapEffect extends OneShotEffect { public HokoriDustDrinkerUntapEffect() { diff --git a/Mage.Sets/src/mage/sets/iceage/WrathOfMaritLage.java b/Mage.Sets/src/mage/sets/iceage/WrathOfMaritLage.java index 5bde861e128..50a7234c509 100644 --- a/Mage.Sets/src/mage/sets/iceage/WrathOfMaritLage.java +++ b/Mage.Sets/src/mage/sets/iceage/WrathOfMaritLage.java @@ -29,20 +29,22 @@ package mage.sets.iceage; import java.util.List; import java.util.UUID; - -import mage.constants.*; import mage.ObjectColor; import mage.abilities.Ability; -import mage.abilities.Mode; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.OneShotEffect; -import mage.abilities.effects.ReplacementEffectImpl; +import mage.abilities.effects.common.SkipUntapAllEffect; import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.TargetController; +import mage.constants.Zone; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.mageobject.ColorPredicate; import mage.game.Game; -import mage.game.events.GameEvent; import mage.game.permanent.Permanent; /** @@ -51,7 +53,12 @@ import mage.game.permanent.Permanent; */ public class WrathOfMaritLage extends CardImpl { - + public static final FilterCreaturePermanent filter = new FilterCreaturePermanent("red creatures"); + + static { + filter.add(new ColorPredicate(ObjectColor.RED)); + } + public WrathOfMaritLage(UUID ownerId) { super(ownerId, 109, "Wrath of Marit Lage", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{3}{U}{U}"); @@ -62,7 +69,7 @@ public class WrathOfMaritLage extends CardImpl { // When Wrath of Marit Lage enters the battlefield, tap all red creatures. this.addAbility(new EntersBattlefieldTriggeredAbility(new TapAllEffect())); // Red creatures don't untap during their controllers' untap steps. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new DontUntapEffect())); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SkipUntapAllEffect(Duration.WhileOnBattlefield, TargetController.ANY, filter))); } public WrathOfMaritLage(final WrathOfMaritLage card) { @@ -76,12 +83,7 @@ public class WrathOfMaritLage extends CardImpl { } class TapAllEffect extends OneShotEffect { - - private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("Red creature"); - static{ - filter.add(new ColorPredicate(ObjectColor.RED)); - } - + public TapAllEffect() { super(Outcome.Tap); staticText = "tap all red creatures"; @@ -94,7 +96,7 @@ class TapAllEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - List creatures = game.getBattlefield().getActivePermanents(filter, source.getSourceId(), game); + List creatures = game.getBattlefield().getActivePermanents(WrathOfMaritLage.filter, source.getSourceId(), game); for (Permanent creature : creatures) { creature.tap(game); } @@ -106,48 +108,3 @@ class TapAllEffect extends OneShotEffect { return new TapAllEffect(this); } } - - -class DontUntapEffect extends ReplacementEffectImpl { - - - public DontUntapEffect() { - super(Duration.WhileOnBattlefield, Outcome.Detriment); - } - - public DontUntapEffect(final DontUntapEffect effect) { - super(effect); - } - - @Override - public DontUntapEffect copy() { - return new DontUntapEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - return false; - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - used = false; - return true; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - Permanent creature = game.getPermanent(event.getTargetId()); - if (game.getTurn().getStepType() == PhaseStep.UNTAP && event.getType() == GameEvent.EventType.UNTAP - && creature != null && creature.getCardType().contains(CardType.CREATURE) && creature.getColor().isRed() && creature.getControllerId() == event.getPlayerId()) { - return true; - } - return false; - } - - @Override - public String getText(Mode mode) { - return "Red creatures don't untap during their controllers' untap steps"; - } - -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/stronghold/IntruderAlarm.java b/Mage.Sets/src/mage/sets/stronghold/IntruderAlarm.java index 619aff17882..0efe8701908 100644 --- a/Mage.Sets/src/mage/sets/stronghold/IntruderAlarm.java +++ b/Mage.Sets/src/mage/sets/stronghold/IntruderAlarm.java @@ -31,16 +31,13 @@ import java.util.UUID; import mage.constants.*; import mage.abilities.Ability; -import mage.abilities.Mode; import mage.abilities.common.EntersBattlefieldAllTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.OneShotEffect; -import mage.abilities.effects.ReplacementEffectImpl; +import mage.abilities.effects.common.SkipUntapAllEffect; import mage.cards.CardImpl; import mage.filter.common.FilterCreaturePermanent; import mage.game.Game; -import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; import mage.players.Player; @@ -57,7 +54,7 @@ public class IntruderAlarm extends CardImpl { this.color.setBlue(true); // Creatures don't untap during their controllers' untap steps. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new IntruderAlarmEffect())); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SkipUntapAllEffect(Duration.WhileOnBattlefield, TargetController.ANY, new FilterCreaturePermanent("Creatures")))); // Whenever a creature enters the battlefield, untap all creatures. this.addAbility(new EntersBattlefieldAllTriggeredAbility(new UntapAllCreatureEffect(), new FilterCreaturePermanent())); } @@ -72,51 +69,6 @@ public class IntruderAlarm extends CardImpl { } } - -class IntruderAlarmEffect extends ReplacementEffectImpl { - - - public IntruderAlarmEffect() { - super(Duration.WhileOnBattlefield, Outcome.Detriment); - } - - public IntruderAlarmEffect(final IntruderAlarmEffect effect) { - super(effect); - } - - @Override - public IntruderAlarmEffect copy() { - return new IntruderAlarmEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - return false; - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - used = false; - return true; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - Permanent creature = game.getPermanent(event.getTargetId()); - if (game.getTurn().getStepType() == PhaseStep.UNTAP && event.getType() == EventType.UNTAP - && creature != null && creature.getCardType().contains(CardType.CREATURE) && creature.getControllerId() == event.getPlayerId()) { - return true; - } - return false; - } - - @Override - public String getText(Mode mode) { - return "Creatures don't untap during their controllers' untap steps"; - } - -} - class UntapAllCreatureEffect extends OneShotEffect { public UntapAllCreatureEffect() { diff --git a/Mage/src/mage/abilities/effects/common/SkipUntapAllEffect.java b/Mage/src/mage/abilities/effects/common/SkipUntapAllEffect.java new file mode 100644 index 00000000000..377026fd309 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/SkipUntapAllEffect.java @@ -0,0 +1,140 @@ +/* +* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are +* permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, this list of +* conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, this list +* of conditions and the following disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +* The views and conclusions contained in the software and documentation are those of the +* authors and should not be interpreted as representing official policies, either expressed +* or implied, of BetaSteward_at_googlemail.com. +*/ + +package mage.abilities.effects.common; + +import mage.abilities.Ability; +import mage.abilities.Mode; +import mage.abilities.effects.ReplacementEffectImpl; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.PhaseStep; +import mage.constants.TargetController; +import static mage.constants.TargetController.ANY; +import static mage.constants.TargetController.OPPONENT; +import static mage.constants.TargetController.YOU; +import mage.filter.FilterPermanent; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; +import mage.game.permanent.Permanent; +import mage.players.Player; + +/** + * + * + * @author LevelX2 + */ + +public class SkipUntapAllEffect extends ReplacementEffectImpl { + + TargetController targetController; + FilterPermanent filter; + + public SkipUntapAllEffect(Duration duration, TargetController targetController, FilterPermanent filter) { + super(duration, Outcome.Detriment); + this.targetController = targetController; + this.filter = filter; + } + + public SkipUntapAllEffect(final SkipUntapAllEffect effect) { + super(effect); + this.targetController = effect.targetController; + this.filter = effect.filter; + } + + @Override + public SkipUntapAllEffect copy() { + return new SkipUntapAllEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + return false; + } + + @Override + public boolean replaceEvent(GameEvent event, Ability source, Game game) { + return true; + } + + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + if (game.getTurn().getStepType() == PhaseStep.UNTAP && event.getType() == EventType.UNTAP) { + Permanent permanent = game.getPermanent(event.getTargetId()); + if (permanent != null) { + switch(targetController) { + case YOU: + if (!permanent.getControllerId().equals(source.getControllerId())) { + return false; + } + break; + case OPPONENT: + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null && !game.isOpponent(controller, permanent.getControllerId())) { + return false; + } + break; + case ANY: + break; + default: + throw new RuntimeException("Type of TargetController not supported!"); + } + if (filter.match(permanent, source.getSourceId(), source.getControllerId(), game)) { + return true; + } + } + } + return false; + } + + @Override + public String getText(Mode mode) { + if (!staticText.isEmpty()) { + return staticText; + } + StringBuilder sb = new StringBuilder(filter.getMessage()).append(" don't untap during "); + switch(targetController) { + case YOU: + sb.append("your "); + break; + case OPPONENT: + sb.append("your opponents' "); + break; + case ANY: + sb.append("their controllers' "); + break; + default: + throw new RuntimeException("Type of TargetController not supported!"); + } + sb.append("untap steps"); + return sb.toString(); + } + +}