[refactoring] Exctracted common DefendingPlayerControlsCondition

This commit is contained in:
North 2012-09-07 01:10:00 +03:00
parent 7e5b677647
commit 9162097213
5 changed files with 75 additions and 99 deletions

View file

@ -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<NeurokSpy> {
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<NeurokSpy> {
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));
}

View file

@ -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<ScrapdiverSerpent> {
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<ScrapdiverSerpent> {
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));
}

View file

@ -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<BubblingBeebles> {
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<BubblingBeebles> {
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) {

View file

@ -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<BouncingBeebles> {
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<BouncingBeebles> {
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));
}

View file

@ -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;
}
}