From 916209721311fa221a6d54630709707cc7742746 Mon Sep 17 00:00:00 2001 From: North Date: Fri, 7 Sep 2012 01:10:00 +0300 Subject: [PATCH] [refactoring] Exctracted common DefendingPlayerControlsCondition --- .../src/mage/sets/mirrodin/NeurokSpy.java | 32 ++--------- .../scarsofmirrodin/ScrapdiverSerpent.java | 31 ++--------- .../sets/urzasdestiny/BubblingBeebles.java | 25 +++------ .../sets/urzaslegacy/BouncingBeebles.java | 33 +++--------- .../DefendingPlayerControlsCondition.java | 53 +++++++++++++++++++ 5 files changed, 75 insertions(+), 99 deletions(-) create mode 100644 Mage/src/mage/abilities/condition/common/DefendingPlayerControlsCondition.java diff --git a/Mage.Sets/src/mage/sets/mirrodin/NeurokSpy.java b/Mage.Sets/src/mage/sets/mirrodin/NeurokSpy.java index 0d222cc413..9610320b21 100644 --- a/Mage.Sets/src/mage/sets/mirrodin/NeurokSpy.java +++ b/Mage.Sets/src/mage/sets/mirrodin/NeurokSpy.java @@ -28,23 +28,18 @@ package mage.sets.mirrodin; import java.util.UUID; -import mage.Constants; import mage.Constants.CardType; import mage.Constants.Rarity; import mage.Constants.Zone; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.condition.Condition; +import mage.abilities.condition.common.DefendingPlayerControlsCondition; import mage.abilities.decorator.ConditionalContinousEffect; import mage.abilities.effects.Effect; import mage.abilities.effects.common.UnblockableSourceEffect; import mage.cards.CardImpl; -import mage.filter.FilterPermanent; import mage.filter.common.FilterArtifactPermanent; -import mage.filter.predicate.mageobject.CardTypePredicate; -import mage.game.Game; /** * @@ -52,24 +47,6 @@ import mage.game.Game; */ public class NeurokSpy extends CardImpl { - private static final FilterPermanent filter = new FilterPermanent(); - - static { - filter.add(new CardTypePredicate(Constants.CardType.ARTIFACT)); - } - - private class DefendingPlayerControlsArtifact implements Condition { - - @Override - public boolean apply(Game game, Ability source) { - UUID defendingPlayer = game.getCombat().getDefendingPlayer(source.getSourceId()); - if (defendingPlayer != null) { - return game.getBattlefield().countAll(filter, defendingPlayer, game) > 0; - } - return false; - } - } - public NeurokSpy(UUID ownerId) { super(ownerId, 44, "Neurok Spy", Rarity.COMMON, new CardType[]{CardType.CREATURE}, "{2}{U}"); this.expansionSetCode = "MRD"; @@ -80,9 +57,10 @@ public class NeurokSpy extends CardImpl { this.toughness = new MageInt(2); //Neurok Spy is unblockable as long as defending player controls an artifact. - Effect effect = new ConditionalContinousEffect(new UnblockableSourceEffect(), - new DefendingPlayerControlsArtifact(), - "Neurok Spy is unblockable as long as defending player controls an artifact"); + Effect effect = new ConditionalContinousEffect( + new UnblockableSourceEffect(), + new DefendingPlayerControlsCondition(new FilterArtifactPermanent()), + "{this} is unblockable as long as defending player controls an artifact"); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect)); } diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/ScrapdiverSerpent.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/ScrapdiverSerpent.java index 73447b1d59..1e52865c29 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/ScrapdiverSerpent.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/ScrapdiverSerpent.java @@ -30,23 +30,18 @@ package mage.sets.scarsofmirrodin; import java.util.UUID; -import mage.Constants; import mage.Constants.CardType; import mage.Constants.Duration; import mage.Constants.Rarity; import mage.Constants.Zone; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.condition.Condition; +import mage.abilities.condition.common.DefendingPlayerControlsCondition; import mage.abilities.decorator.ConditionalContinousEffect; -import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.Effect; import mage.abilities.effects.common.UnblockableSourceEffect; import mage.cards.CardImpl; -import mage.filter.FilterPermanent; -import mage.filter.predicate.mageobject.CardTypePredicate; -import mage.game.Game; +import mage.filter.common.FilterArtifactPermanent; /** * @@ -54,23 +49,6 @@ import mage.game.Game; */ public class ScrapdiverSerpent extends CardImpl { - private static final FilterPermanent filter = new FilterPermanent(); - - static { - filter.add(new CardTypePredicate(Constants.CardType.ARTIFACT)); - } - - private class DefendingPlayerControlsArtifact implements Condition { - @Override - public boolean apply(Game game, Ability source) { - UUID defendingPlayer = game.getCombat().getDefendingPlayer(source.getSourceId()); - if (defendingPlayer != null) { - return game.getBattlefield().countAll(filter, defendingPlayer, game) > 0; - } - return false; - } - } - public ScrapdiverSerpent (UUID ownerId) { super(ownerId, 41, "Scrapdiver Serpent", Rarity.COMMON, new CardType[]{CardType.CREATURE}, "{5}{U}{U}"); this.expansionSetCode = "SOM"; @@ -80,8 +58,9 @@ public class ScrapdiverSerpent extends CardImpl { this.toughness = new MageInt(5); // Scrapdiver Serpent is unblockable as long as defending player controls an artifact - Effect effect = new ConditionalContinousEffect(new UnblockableSourceEffect(Duration.WhileOnBattlefield), - new DefendingPlayerControlsArtifact(), + Effect effect = new ConditionalContinousEffect( + new UnblockableSourceEffect(), + new DefendingPlayerControlsCondition(new FilterArtifactPermanent()), "{this} is unblockable as long as defending player controls an artifact"); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect)); } diff --git a/Mage.Sets/src/mage/sets/urzasdestiny/BubblingBeebles.java b/Mage.Sets/src/mage/sets/urzasdestiny/BubblingBeebles.java index 53b9e058eb..ce2313e5cc 100644 --- a/Mage.Sets/src/mage/sets/urzasdestiny/BubblingBeebles.java +++ b/Mage.Sets/src/mage/sets/urzasdestiny/BubblingBeebles.java @@ -28,20 +28,18 @@ package mage.sets.urzasdestiny; import java.util.UUID; -import mage.Constants; import mage.Constants.CardType; import mage.Constants.Rarity; +import mage.Constants.Zone; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.condition.Condition; +import mage.abilities.condition.common.DefendingPlayerControlsCondition; import mage.abilities.decorator.ConditionalContinousEffect; import mage.abilities.effects.Effect; import mage.abilities.effects.common.UnblockableSourceEffect; import mage.cards.CardImpl; import mage.filter.FilterPermanent; import mage.filter.predicate.mageobject.CardTypePredicate; -import mage.game.Game; /** * @@ -55,18 +53,6 @@ public class BubblingBeebles extends CardImpl { filter.add(new CardTypePredicate(CardType.ENCHANTMENT)); } - private class DefendingPlayerControlsEnchantment implements Condition { - - @Override - public boolean apply(Game game, Ability source) { - UUID defendingPlayer = game.getCombat().getDefendingPlayer(source.getSourceId()); - if (defendingPlayer != null) { - return game.getBattlefield().countAll(filter, defendingPlayer, game) > 0; - } - return false; - } - } - public BubblingBeebles(UUID ownerId) { super(ownerId, 29, "Bubbling Beebles", Rarity.COMMON, new CardType[]{CardType.CREATURE}, "{4}{U}"); this.expansionSetCode = "UDS"; @@ -76,10 +62,11 @@ public class BubblingBeebles extends CardImpl { this.toughness = new MageInt(3); // Bubbling Beebles is unblockable as long as defending player controls an enchantment. - Effect effect = new ConditionalContinousEffect(new UnblockableSourceEffect(Constants.Duration.WhileOnBattlefield), - new DefendingPlayerControlsEnchantment(), + Effect effect = new ConditionalContinousEffect( + new UnblockableSourceEffect(), + new DefendingPlayerControlsCondition(filter), "{this} is unblockable as long as defending player controls an enchantment"); - this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, effect)); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect)); } public BubblingBeebles(final BubblingBeebles card) { diff --git a/Mage.Sets/src/mage/sets/urzaslegacy/BouncingBeebles.java b/Mage.Sets/src/mage/sets/urzaslegacy/BouncingBeebles.java index eecd5f25c5..d457a89b1c 100644 --- a/Mage.Sets/src/mage/sets/urzaslegacy/BouncingBeebles.java +++ b/Mage.Sets/src/mage/sets/urzaslegacy/BouncingBeebles.java @@ -29,21 +29,17 @@ package mage.sets.urzaslegacy; import java.util.UUID; -import mage.Constants; import mage.Constants.CardType; import mage.Constants.Rarity; import mage.Constants.Zone; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.condition.Condition; +import mage.abilities.condition.common.DefendingPlayerControlsCondition; import mage.abilities.decorator.ConditionalContinousEffect; import mage.abilities.effects.Effect; import mage.abilities.effects.common.UnblockableSourceEffect; import mage.cards.CardImpl; -import mage.filter.FilterPermanent; -import mage.filter.predicate.mageobject.CardTypePredicate; -import mage.game.Game; +import mage.filter.common.FilterArtifactPermanent; /** * @@ -51,24 +47,6 @@ import mage.game.Game; */ public class BouncingBeebles extends CardImpl { - private static final FilterPermanent filter = new FilterPermanent(); - - static { - filter.add(new CardTypePredicate(Constants.CardType.ARTIFACT)); - } - - private class DefendingPlayerControlsArtifact implements Condition { - - @Override - public boolean apply(Game game, Ability source) { - UUID defendingPlayer = game.getCombat().getDefendingPlayer(source.getSourceId()); - if (defendingPlayer != null) { - return game.getBattlefield().countAll(filter, defendingPlayer, game) > 0; - } - return false; - } - } - public BouncingBeebles(UUID ownerId) { super(ownerId, 28, "Bouncing Beebles", Rarity.COMMON, new CardType[]{CardType.CREATURE}, "{2}{U}"); this.expansionSetCode = "ULG"; @@ -78,9 +56,10 @@ public class BouncingBeebles extends CardImpl { this.toughness = new MageInt(2); //Bouncing Beebles is unblockable as long as defending player controls an artifact. - Effect effect = new ConditionalContinousEffect(new UnblockableSourceEffect(), - new DefendingPlayerControlsArtifact(), - "Neurok Spy is unblockable as long as defending player controls an artifact"); + Effect effect = new ConditionalContinousEffect( + new UnblockableSourceEffect(), + new DefendingPlayerControlsCondition(new FilterArtifactPermanent()), + "{this} is unblockable as long as defending player controls an artifact"); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect)); } diff --git a/Mage/src/mage/abilities/condition/common/DefendingPlayerControlsCondition.java b/Mage/src/mage/abilities/condition/common/DefendingPlayerControlsCondition.java new file mode 100644 index 0000000000..ae71599abf --- /dev/null +++ b/Mage/src/mage/abilities/condition/common/DefendingPlayerControlsCondition.java @@ -0,0 +1,53 @@ +/* + * 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.condition.common; + +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.condition.Condition; +import mage.filter.FilterPermanent; +import mage.game.Game; + +/** + * + * @author North + */ +public class DefendingPlayerControlsCondition implements Condition { + + private FilterPermanent filter; + + public DefendingPlayerControlsCondition(FilterPermanent filter) { + this.filter = filter; + } + + @Override + public boolean apply(Game game, Ability source) { + UUID defendingPlayer = game.getCombat().getDefendingPlayer(source.getSourceId()); + return defendingPlayer != null && game.getBattlefield().countAll(filter, defendingPlayer, game) > 0; + } +}