From 50b650bb7dffa74ab2e1d2d0e51103f32dc64435 Mon Sep 17 00:00:00 2001 From: North Date: Sun, 22 Jul 2012 14:15:00 +0300 Subject: [PATCH] [filters] added WasDealtDamageThisTurn Predicate --- .../championsofkamigawa/BushiTenderfoot.java | 4 +- .../championsofkamigawa/CrushingPain.java | 8 +-- .../championsofkamigawa/InitiateOfBlood.java | 7 ++- .../src/mage/sets/futuresight/WitchsMist.java | 6 ++- .../src/mage/sets/tempest/Opportunist.java | 4 +- .../common/FilterCreaturePermanent.java | 40 --------------- .../WasDealtDamageThisTurnPredicate.java | 49 +++++++++++++++++++ 7 files changed, 65 insertions(+), 53 deletions(-) create mode 100644 Mage/src/mage/filter/predicate/permanent/WasDealtDamageThisTurnPredicate.java diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/BushiTenderfoot.java b/Mage.Sets/src/mage/sets/championsofkamigawa/BushiTenderfoot.java index a6ef5c428b9..ae9046813a1 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/BushiTenderfoot.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/BushiTenderfoot.java @@ -42,6 +42,7 @@ import mage.abilities.keyword.BushidoAbility; import mage.abilities.keyword.DoubleStrikeAbility; import mage.cards.CardImpl; import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.permanent.WasDealtDamageThisTurnPredicate; import mage.game.permanent.token.Token; import java.util.UUID; @@ -54,8 +55,7 @@ public class BushiTenderfoot extends CardImpl { private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature that was dealt damage this turn"); static { - filter.setUseDamageDealt(true); - filter.setDamageDealt(true); + filter.add(new WasDealtDamageThisTurnPredicate()); } public BushiTenderfoot(UUID ownerId) { diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/CrushingPain.java b/Mage.Sets/src/mage/sets/championsofkamigawa/CrushingPain.java index 4cb59ee2117..230dcfa8170 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/CrushingPain.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/CrushingPain.java @@ -36,6 +36,7 @@ import mage.Constants.Rarity; import mage.abilities.effects.common.DamageTargetEffect; import mage.cards.CardImpl; import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.permanent.WasDealtDamageThisTurnPredicate; import mage.target.common.TargetCreaturePermanent; /** @@ -45,14 +46,15 @@ import mage.target.common.TargetCreaturePermanent; public class CrushingPain extends CardImpl { private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature that was dealt damage this turn"); + static { - filter.setUseDamageDealt(true); - filter.setDamageDealt(true); + filter.add(new WasDealtDamageThisTurnPredicate()); } + public CrushingPain (UUID ownerId) { super(ownerId, 162, "Crushing Pain", Rarity.COMMON, new CardType[]{CardType.INSTANT}, "{1}{R}"); this.expansionSetCode = "CHK"; - this.color.setRed(true); + this.color.setRed(true); // Crushing Pain deals 6 damage to target creature that was dealt damage this turn. this.getSpellAbility().addEffect(new DamageTargetEffect(6)); diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/InitiateOfBlood.java b/Mage.Sets/src/mage/sets/championsofkamigawa/InitiateOfBlood.java index 05eeeab92c2..ab85198933a 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/InitiateOfBlood.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/InitiateOfBlood.java @@ -44,6 +44,7 @@ import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.FlipSourceEffect; import mage.cards.CardImpl; import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.permanent.WasDealtDamageThisTurnPredicate; import mage.game.permanent.token.Token; import mage.target.common.TargetCreaturePermanent; @@ -57,8 +58,7 @@ public class InitiateOfBlood extends CardImpl { private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature that was dealt damage this turn"); static { - filter.setUseDamageDealt(true); - filter.setDamageDealt(true); + filter.add(new WasDealtDamageThisTurnPredicate()); } public InitiateOfBlood(UUID ownerId) { @@ -98,8 +98,7 @@ class GokaTheUnjust extends Token { private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature that was dealt damage this turn"); static { - filter.setUseDamageDealt(true); - filter.setDamageDealt(true); + filter.add(new WasDealtDamageThisTurnPredicate()); } GokaTheUnjust() { diff --git a/Mage.Sets/src/mage/sets/futuresight/WitchsMist.java b/Mage.Sets/src/mage/sets/futuresight/WitchsMist.java index cdeba01977f..e00c675349c 100644 --- a/Mage.Sets/src/mage/sets/futuresight/WitchsMist.java +++ b/Mage.Sets/src/mage/sets/futuresight/WitchsMist.java @@ -38,6 +38,7 @@ import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.common.DestroyTargetEffect; import mage.cards.CardImpl; import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.permanent.WasDealtDamageThisTurnPredicate; import mage.target.common.TargetCreaturePermanent; /** @@ -47,15 +48,16 @@ import mage.target.common.TargetCreaturePermanent; public class WitchsMist extends CardImpl { private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature that was dealt damage this turn"); + static { - filter.setUseDamageDealt(true); - filter.setDamageDealt(true); + filter.add(new WasDealtDamageThisTurnPredicate()); } public WitchsMist(UUID ownerId) { super(ownerId, 92, "Witch's Mist", Rarity.UNCOMMON, new CardType[]{CardType.ENCHANTMENT}, "{2}{B}"); this.expansionSetCode = "FUT"; this.color.setBlack(true); + // {2}{B}, {T}: Destroy target creature that was dealt damage this turn. Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new DestroyTargetEffect(),new ManaCostsImpl("{2}{B}")); ability.addTarget(new TargetCreaturePermanent(filter)); diff --git a/Mage.Sets/src/mage/sets/tempest/Opportunist.java b/Mage.Sets/src/mage/sets/tempest/Opportunist.java index 2b33308bc0f..e7842a29977 100644 --- a/Mage.Sets/src/mage/sets/tempest/Opportunist.java +++ b/Mage.Sets/src/mage/sets/tempest/Opportunist.java @@ -40,6 +40,7 @@ import mage.abilities.costs.common.TapSourceCost; import mage.abilities.effects.common.DamageTargetEffect; import mage.cards.CardImpl; import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.permanent.WasDealtDamageThisTurnPredicate; import mage.target.common.TargetCreaturePermanent; /** @@ -50,8 +51,7 @@ public class Opportunist extends CardImpl { private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature that was dealt damage this turn"); static { - filter.setUseDamageDealt(true); - filter.setDamageDealt(true); + filter.add(new WasDealtDamageThisTurnPredicate()); } public Opportunist(UUID ownerId) { diff --git a/Mage/src/mage/filter/common/FilterCreaturePermanent.java b/Mage/src/mage/filter/common/FilterCreaturePermanent.java index a9e7cd3cd27..959954b0d81 100644 --- a/Mage/src/mage/filter/common/FilterCreaturePermanent.java +++ b/Mage/src/mage/filter/common/FilterCreaturePermanent.java @@ -31,8 +31,6 @@ package mage.filter.common; import mage.Constants.CardType; import mage.filter.FilterPermanent; import mage.filter.predicate.mageobject.CardTypePredicate; -import mage.game.Game; -import mage.game.permanent.Permanent; /** * @@ -40,9 +38,6 @@ import mage.game.permanent.Permanent; */ public class FilterCreaturePermanent extends FilterPermanent { - protected boolean useDamageDealt; - protected boolean damageDealt; - public FilterCreaturePermanent() { this("creature"); } @@ -54,41 +49,6 @@ public class FilterCreaturePermanent extends FilterPermanent { public FilterCreaturePermanent(final FilterCreaturePermanent filter) { super(filter); - this.useDamageDealt = filter.useDamageDealt; - this.damageDealt = filter.damageDealt; - } - - @Override - public boolean match(Permanent permanent, Game game) { - if (!super.match(permanent, game)) - return notFilter; - - if (useDamageDealt) { - // use this instead of getDamage() because damage is reset in case of regeneration - if (permanent.getDealtDamageByThisTurn().isEmpty()) { - return notFilter; - } - } - return !notFilter; - } - - /** - * Select creatures dependant if they already got damage during the current turn. Works also if the creature was - * meanwhile regenerated during the turn. - * - * @param useDamageDealt - */ - public void setUseDamageDealt(boolean useDamageDealt) { - this.useDamageDealt = useDamageDealt; - } - - /** - * Select creatures that got damage dealt to this turn. - * - * @param damageDealt - */ - public void setDamageDealt(boolean damageDealt) { - this.damageDealt = damageDealt; } @Override diff --git a/Mage/src/mage/filter/predicate/permanent/WasDealtDamageThisTurnPredicate.java b/Mage/src/mage/filter/predicate/permanent/WasDealtDamageThisTurnPredicate.java new file mode 100644 index 00000000000..0fb6ffd3645 --- /dev/null +++ b/Mage/src/mage/filter/predicate/permanent/WasDealtDamageThisTurnPredicate.java @@ -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 WasDealtDamageThisTurnPredicate implements Predicate { + + @Override + public boolean apply(Permanent input, Game game) { + return !input.getDealtDamageByThisTurn().isEmpty(); + } + + @Override + public String toString() { + return "WasDealtDamageThisTurn"; + } +}