[filters] added Attacking and Blocking predicates

This commit is contained in:
North 2012-07-22 13:48:14 +03:00
parent 61b5f8555e
commit badb0ede21
15 changed files with 139 additions and 130 deletions

View file

@ -42,7 +42,7 @@ import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.continious.GainAbilitySourceEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.common.FilterAttackingOrBlockingCreature;
import mage.target.common.TargetCreaturePermanent;
/**
@ -51,15 +51,6 @@ import mage.target.common.TargetCreaturePermanent;
*/
public class FreewindEquenaut extends CardImpl<FreewindEquenaut> {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("attacking or blocking creature");
static {
filter.setAttacking(true);
filter.setUseAttacking(true);
filter.setBlocking(true);
filter.setUseBlocking(true);
}
public FreewindEquenaut(UUID ownerId) {
super(ownerId, 9, "Freewind Equenaut", Rarity.COMMON, new CardType[]{CardType.CREATURE}, "{2}{W}");
this.expansionSetCode = "DIS";
@ -74,7 +65,7 @@ public class FreewindEquenaut extends CardImpl<FreewindEquenaut> {
SimpleActivatedAbility ability = new SimpleActivatedAbility(Zone.BATTLEFIELD,
new DamageTargetEffect(2),
new TapSourceCost());
ability.addTarget(new TargetCreaturePermanent(filter));
ability.addTarget(new TargetCreaturePermanent(new FilterAttackingOrBlockingCreature()));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD,
new ConditionalContinousEffect(
new GainAbilitySourceEffect(ability, Duration.WhileOnBattlefield),

View file

@ -33,7 +33,6 @@ import mage.Constants.Rarity;
import mage.abilities.effects.common.DestroyTargetEffect;
import mage.cards.CardImpl;
import mage.filter.common.FilterAttackingOrBlockingCreature;
import mage.filter.common.FilterCreaturePermanent;
import mage.target.common.TargetCreaturePermanent;
/**
@ -42,15 +41,6 @@ import mage.target.common.TargetCreaturePermanent;
*/
public class DivineVerdict extends CardImpl<DivineVerdict> {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("attacking or blocking creature");
static {
filter.setAttacking(true);
filter.setUseAttacking(true);
filter.setBlocking(true);
filter.setUseBlocking(true);
}
public DivineVerdict(UUID ownerId) {
super(ownerId, 8, "Divine Verdict", Rarity.COMMON, new CardType[]{CardType.INSTANT}, "{3}{W}");
this.expansionSetCode = "M10";

View file

@ -39,7 +39,7 @@ import mage.abilities.costs.common.SacrificeSourceCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.common.FilterAttackingOrBlockingCreature;
import mage.target.common.TargetCreaturePermanent;
/**
@ -48,13 +48,6 @@ import mage.target.common.TargetCreaturePermanent;
*/
public class SoldierReplica extends CardImpl<SoldierReplica> {
private final static FilterCreaturePermanent filter = new FilterCreaturePermanent("attacking or blocking creature");
static {
filter.setBlocking(true);
filter.setAttacking(true);
}
public SoldierReplica(UUID ownerId) {
super(ownerId, 244, "Soldier Replica", Rarity.COMMON, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{3}");
this.expansionSetCode = "MRD";
@ -63,7 +56,7 @@ public class SoldierReplica extends CardImpl<SoldierReplica> {
this.toughness = new MageInt(3);
Ability ability = new SimpleActivatedAbility(Constants.Zone.BATTLEFIELD, new DamageTargetEffect(3), new ManaCostsImpl("{1}{W}"));
ability.addCost(new SacrificeSourceCost());
ability.addTarget(new TargetCreaturePermanent(filter));
ability.addTarget(new TargetCreaturePermanent(new FilterAttackingOrBlockingCreature()));
this.addAbility(ability);
}

View file

@ -33,7 +33,7 @@ import mage.Constants.Duration;
import mage.Constants.Rarity;
import mage.abilities.effects.common.PreventAllDamageEffect;
import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.common.FilterAttackingCreature;
/**
*
@ -41,13 +41,6 @@ import mage.filter.common.FilterCreaturePermanent;
*/
public class HarmlessAssault extends CardImpl<HarmlessAssault> {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("attacking creatures");
static {
filter.setAttacking(true);
filter.setUseAttacking(true);
}
public HarmlessAssault(UUID ownerId) {
super(ownerId, 24, "Harmless Assault", Rarity.COMMON,
new CardType[] { CardType.INSTANT }, "{2}{W}{W}");
@ -58,7 +51,7 @@ public class HarmlessAssault extends CardImpl<HarmlessAssault> {
// Prevent all combat damage that would be dealt this turn by attacking
// creatures.
this.getSpellAbility().addEffect(
new PreventAllDamageEffect(filter, Duration.EndOfTurn, true));
new PreventAllDamageEffect(new FilterAttackingCreature(), Duration.EndOfTurn, true));
}
public HarmlessAssault(final HarmlessAssault card) {

View file

@ -33,6 +33,7 @@ import mage.Constants.Rarity;
import mage.abilities.effects.common.DestroyTargetEffect;
import mage.cards.CardImpl;
import mage.filter.Filter.ComparisonType;
import mage.filter.common.FilterAttackingOrBlockingCreature;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.PowerPredicate;
import mage.target.common.TargetCreaturePermanent;
@ -43,13 +44,9 @@ import mage.target.common.TargetCreaturePermanent;
*/
public class PuncturingLight extends CardImpl<PuncturingLight> {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("attacking or blocking creature with power 3 or less");
private static final FilterCreaturePermanent filter = new FilterAttackingOrBlockingCreature("attacking or blocking creature with power 3 or less");
static {
filter.setAttacking(true);
filter.setUseAttacking(true);
filter.setBlocking(true);
filter.setUseBlocking(true);
filter.add(new PowerPredicate(ComparisonType.LessThan, 4));
}

View file

@ -37,7 +37,7 @@ import mage.abilities.condition.common.MetalcraftCondition;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.SacrificeEffect;
import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.common.FilterAttackingCreature;
import mage.game.Game;
import mage.target.TargetPlayer;
@ -73,13 +73,7 @@ class DispenseJusticeEffect extends OneShotEffect<DispenseJusticeEffect> {
private static final String effectText = "Target player sacrifices an attacking creature.\r\n\r\n"
+ "Metalcraft - That player sacrifices two attacking creatures instead if you control three or more artifacts";
private static final FilterCreaturePermanent filter;
static {
filter = new FilterCreaturePermanent();
filter.setUseAttacking(true);
filter.setAttacking(true);
}
private static final FilterAttackingCreature filter = new FilterAttackingCreature();
DispenseJusticeEffect ( ) {
super(Outcome.Sacrifice);

View file

@ -39,7 +39,7 @@ import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.common.continious.BoostTargetEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.common.FilterAttackingOrBlockingCreature;
import mage.target.common.TargetCreaturePermanent;
/**
@ -48,15 +48,6 @@ import mage.target.common.TargetCreaturePermanent;
*/
public class AngelicPage extends CardImpl<AngelicPage> {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("attacking or blocking creature");
static {
filter.setAttacking(true);
filter.setUseAttacking(true);
filter.setBlocking(true);
filter.setUseBlocking(true);
}
public AngelicPage(UUID ownerId) {
super(ownerId, 4, "Angelic Page", Rarity.COMMON, new CardType[]{CardType.CREATURE}, "{1}{W}");
this.expansionSetCode = "USG";
@ -70,7 +61,7 @@ public class AngelicPage extends CardImpl<AngelicPage> {
//{T}: Target attacking or blocking creature gets +1/+1 until end of turn.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new BoostTargetEffect(1, 1, Duration.EndOfTurn), new TapSourceCost());
ability.addTarget(new TargetCreaturePermanent(filter));
ability.addTarget(new TargetCreaturePermanent(new FilterAttackingOrBlockingCreature()));
this.addAbility(ability);
}

View file

@ -28,6 +28,8 @@
package mage.filter.common;
import mage.filter.predicate.permanent.AttackingPredicate;
/**
*
* @author BetaSteward_at_googlemail.com
@ -40,8 +42,7 @@ public class FilterAttackingCreature extends FilterCreaturePermanent {
public FilterAttackingCreature(String name) {
super(name);
this.attacking = true;
this.useAttacking = true;
this.add(new AttackingPredicate());
}
public FilterAttackingCreature(final FilterAttackingCreature filter) {

View file

@ -28,6 +28,10 @@
package mage.filter.common;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.permanent.AttackingPredicate;
import mage.filter.predicate.permanent.BlockingPredicate;
/**
*
* @author nantuko
@ -40,10 +44,9 @@ public class FilterAttackingOrBlockingCreature extends FilterCreaturePermanent {
public FilterAttackingOrBlockingCreature(String name) {
super(name);
this.attacking = true;
this.useAttacking = true;
this.blocking = true;
this.useBlocking = true;
this.add(Predicates.or(
new AttackingPredicate(),
new BlockingPredicate()));
}
public FilterAttackingOrBlockingCreature(final FilterAttackingOrBlockingCreature filter) {

View file

@ -28,6 +28,8 @@
package mage.filter.common;
import mage.filter.predicate.permanent.BlockedPredicate;
/**
*
* @author BetaSteward_at_googlemail.com
@ -40,8 +42,7 @@ public class FilterBlockingCreature extends FilterCreaturePermanent {
public FilterBlockingCreature(String name) {
super(name);
this.blocking = true;
this.useBlocking = true;
this.add(new BlockedPredicate());
}
public FilterBlockingCreature(final FilterBlockingCreature filter) {

View file

@ -31,6 +31,8 @@ package mage.filter.common;
import mage.abilities.keyword.DefenderAbility;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.AbilityPredicate;
import mage.filter.predicate.permanent.AttackingPredicate;
import mage.filter.predicate.permanent.BlockingPredicate;
import mage.filter.predicate.permanent.TappedPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -47,10 +49,8 @@ public class FilterCreatureForAttack extends FilterCreaturePermanent {
public FilterCreatureForAttack(String name) {
super(name);
this.attacking = false;
this.useAttacking = true;
this.blocking = false;
this.useBlocking = true;
this.add(Predicates.not(new AttackingPredicate()));
this.add(Predicates.not(new BlockingPredicate()));
this.add(Predicates.not(new TappedPredicate()));
this.add(Predicates.not(new AbilityPredicate(DefenderAbility.class)));
}

View file

@ -30,6 +30,7 @@ package mage.filter.common;
import mage.filter.predicate.Predicate;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.permanent.AttackingPredicate;
import mage.filter.predicate.permanent.TappedPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -46,10 +47,9 @@ public class FilterCreatureForCombat extends FilterCreaturePermanent {
public FilterCreatureForCombat(String name) {
super(name);
this.attacking = false;
this.useAttacking = true;
this.add(new PhasedInPredicate());
this.add(Predicates.not(new AttackingPredicate()));
this.add(Predicates.not(new TappedPredicate()));
this.add(new PhasedInPredicate());
}
public FilterCreatureForCombat(final FilterCreatureForCombat filter) {
@ -68,17 +68,17 @@ public class FilterCreatureForCombat extends FilterCreaturePermanent {
public FilterCreatureForCombat copy() {
return new FilterCreatureForCombat(this);
}
}
private static final class PhasedInPredicate implements Predicate<Permanent>{
class PhasedInPredicate implements Predicate<Permanent> {
@Override
public boolean apply(Permanent input, Game game) {
return input.isPhasedIn();
}
@Override
public boolean apply(Permanent input, Game game) {
return input.isPhasedIn();
}
@Override
public String toString() {
return "PhasedIn";
}
@Override
public String toString() {
return "PhasedIn";
}
}

View file

@ -40,10 +40,6 @@ import mage.game.permanent.Permanent;
*/
public class FilterCreaturePermanent extends FilterPermanent {
protected boolean useAttacking;
protected boolean attacking;
protected boolean useBlocking;
protected boolean blocking;
protected boolean useDamageDealt;
protected boolean damageDealt;
@ -58,10 +54,6 @@ public class FilterCreaturePermanent extends FilterPermanent {
public FilterCreaturePermanent(final FilterCreaturePermanent filter) {
super(filter);
this.useAttacking = filter.useAttacking;
this.attacking = filter.attacking;
this.useBlocking = filter.useBlocking;
this.blocking = filter.blocking;
this.useDamageDealt = filter.useDamageDealt;
this.damageDealt = filter.damageDealt;
}
@ -71,25 +63,6 @@ public class FilterCreaturePermanent extends FilterPermanent {
if (!super.match(permanent, game))
return notFilter;
if (useAttacking) {
if (permanent.isAttacking() != attacking) { // failed checking
// for "target attacking OR blocking" filters
// we have to make sure it is not blocking before returning false
if (useBlocking) {
if ((permanent.getBlocking() > 0) != blocking) {
return notFilter;
}
} else {
// filter doesn't use 'blocking', so as checking for attacking failed return false
return notFilter;
}
}
return !notFilter;
}
if (useBlocking && (permanent.getBlocking() > 0) != blocking)
return notFilter;
if (useDamageDealt) {
// use this instead of getDamage() because damage is reset in case of regeneration
if (permanent.getDealtDamageByThisTurn().isEmpty()) {
@ -99,22 +72,6 @@ public class FilterCreaturePermanent extends FilterPermanent {
return !notFilter;
}
public void setUseAttacking ( boolean useAttacking ) {
this.useAttacking = useAttacking;
}
public void setAttacking ( boolean attacking ) {
this.attacking = attacking;
}
public void setUseBlocking ( boolean useBlocking ) {
this.useBlocking = useBlocking;
}
public void setBlocking ( boolean blocking ) {
this.blocking = blocking;
}
/**
* Select creatures dependant if they already got damage during the current turn. Works also if the creature was
* meanwhile regenerated during the turn.

View file

@ -0,0 +1,49 @@
/*
* 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.filter.predicate.permanent;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author North
*/
public class AttackingPredicate implements Predicate<Permanent> {
@Override
public boolean apply(Permanent input, Game game) {
return input.isAttacking();
}
@Override
public String toString() {
return "Attacking";
}
}

View file

@ -0,0 +1,49 @@
/*
* 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.filter.predicate.permanent;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author North
*/
public class BlockingPredicate implements Predicate<Permanent> {
@Override
public boolean apply(Permanent input, Game game) {
return input.getBlocking() > 0;
}
@Override
public String toString() {
return "Blocking";
}
}