From 7f4fc245cdebab90bc45973a661ef685afb22fb5 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 3 Jul 2016 21:43:12 +0200 Subject: [PATCH] * Fixed some cards that choose a subtype as entering the battlefield that did not work for copied permanents (e.g. Brass Herald for Mormir format). --- .../src/mage/sets/apocalypse/BrassHerald.java | 40 ++++++++++---- .../sets/magic2012/AdaptiveAutomaton.java | 16 +++--- Mage.Sets/src/mage/sets/mirage/Shimmer.java | 11 ++-- .../mage/sets/onslaught/SharedTriumph.java | 9 +--- .../sets/urzasdestiny/UrzasIncubator.java | 8 ++- .../sets/urzaslegacy/EngineeredPlague.java | 9 +--- .../common/continuous/BoostAllEffect.java | 30 +++++++++-- .../BoostAllOfChosenSubtypeEffect.java | 53 +++++++++++++++++++ .../continuous/GainAbilityAllEffect.java | 30 +++++++++-- .../GainAbilityAllOfChosenSubtypeEffect.java | 49 +++++++++++++++++ .../cost/SpellsCostReductionAllEffect.java | 32 +++++++++-- ...CostReductionAllOfChosenSubtypeEffect.java | 48 +++++++++++++++++ 12 files changed, 282 insertions(+), 53 deletions(-) create mode 100644 Mage/src/main/java/mage/abilities/effects/common/continuous/BoostAllOfChosenSubtypeEffect.java create mode 100644 Mage/src/main/java/mage/abilities/effects/common/continuous/GainAbilityAllOfChosenSubtypeEffect.java create mode 100644 Mage/src/main/java/mage/abilities/effects/common/cost/SpellsCostReductionAllOfChosenSubtypeEffect.java diff --git a/Mage.Sets/src/mage/sets/apocalypse/BrassHerald.java b/Mage.Sets/src/mage/sets/apocalypse/BrassHerald.java index a4050e666de..ff29d60b5a1 100644 --- a/Mage.Sets/src/mage/sets/apocalypse/BrassHerald.java +++ b/Mage.Sets/src/mage/sets/apocalypse/BrassHerald.java @@ -29,12 +29,14 @@ package mage.sets.apocalypse; import java.util.UUID; import mage.MageInt; +import mage.abilities.Ability; import mage.abilities.common.AsEntersBattlefieldAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.ChooseCreatureTypeEffect; import mage.abilities.effects.common.EnvoyEffect; -import mage.abilities.effects.common.continuous.BoostAllEffect; +import mage.abilities.effects.common.continuous.BoostAllOfChosenSubtypeEffect; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Duration; @@ -42,8 +44,8 @@ import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; import mage.filter.FilterCard; -import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.mageobject.ChosenSubtypePredicate; +import mage.game.Game; /** * @@ -60,16 +62,12 @@ public class BrassHerald extends CardImpl { // As Brass Herald enters the battlefield, choose a creature type. this.addAbility(new AsEntersBattlefieldAbility(new ChooseCreatureTypeEffect(Outcome.BoostCreature))); + // When Brass Herald enters the battlefield, reveal the top four cards of your library. Put all creature cards of the chosen type revealed this way into your hand and the rest on the bottom of your library in any order. - FilterCard filter = new FilterCard("creature cards of the chosen type"); - filter.add(new ChosenSubtypePredicate(this.getId())); - this.addAbility(new EntersBattlefieldTriggeredAbility(new EnvoyEffect(filter, 4))); + this.addAbility(new EntersBattlefieldTriggeredAbility(new BrassHeraldEntersEffect())); // Creatures of the chosen type get +1/+1. - FilterCreaturePermanent filter2 = new FilterCreaturePermanent("creatures of the chosen type"); - filter2.add(new ChosenSubtypePredicate(this.getId())); - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostAllEffect(1, 1, Duration.WhileOnBattlefield, - filter2, false))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostAllOfChosenSubtypeEffect(1, 1, Duration.WhileOnBattlefield, false))); } public BrassHerald(final BrassHerald card) { @@ -81,3 +79,27 @@ public class BrassHerald extends CardImpl { return new BrassHerald(this); } } + +class BrassHeraldEntersEffect extends OneShotEffect { + + public BrassHeraldEntersEffect() { + super(Outcome.Benefit); + this.staticText = "reveal the top four cards of your library. Put all creature cards of the chosen type revealed this way into your hand and the rest on the bottom of your library in any order"; + } + + public BrassHeraldEntersEffect(final BrassHeraldEntersEffect effect) { + super(effect); + } + + @Override + public BrassHeraldEntersEffect copy() { + return new BrassHeraldEntersEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + FilterCard filter = new FilterCard("creature cards of the chosen type"); + filter.add(new ChosenSubtypePredicate(source.getSourceId())); + return new EnvoyEffect(filter, 4).apply(game, source); + } +} diff --git a/Mage.Sets/src/mage/sets/magic2012/AdaptiveAutomaton.java b/Mage.Sets/src/mage/sets/magic2012/AdaptiveAutomaton.java index d7537242af3..60b4ad65cd1 100644 --- a/Mage.Sets/src/mage/sets/magic2012/AdaptiveAutomaton.java +++ b/Mage.Sets/src/mage/sets/magic2012/AdaptiveAutomaton.java @@ -34,7 +34,7 @@ import mage.abilities.common.AsEntersBattlefieldAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.common.ChooseCreatureTypeEffect; -import mage.abilities.effects.common.continuous.BoostAllEffect; +import mage.abilities.effects.common.continuous.BoostAllOfChosenSubtypeEffect; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Duration; @@ -45,8 +45,6 @@ import mage.constants.SubLayer; import mage.constants.TargetController; import mage.constants.Zone; import mage.filter.common.FilterCreaturePermanent; -import mage.filter.predicate.mageobject.ChosenSubtypePredicate; -import mage.filter.predicate.permanent.AnotherPredicate; import mage.filter.predicate.permanent.ControllerPredicate; import mage.game.Game; import mage.game.permanent.Permanent; @@ -56,6 +54,12 @@ import mage.game.permanent.Permanent; */ public class AdaptiveAutomaton extends CardImpl { + private final static FilterCreaturePermanent filter = new FilterCreaturePermanent("creatures you control of the chosen type"); + + static { + filter.add(new ControllerPredicate(TargetController.YOU)); + } + public AdaptiveAutomaton(UUID ownerId) { super(ownerId, 201, "Adaptive Automaton", Rarity.RARE, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{3}"); this.expansionSetCode = "M12"; @@ -69,11 +73,7 @@ public class AdaptiveAutomaton extends CardImpl { // Adaptive Automaton is the chosen type in addition to its other types. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new AdaptiveAutomatonAddSubtypeEffect())); // Other creatures you control of the chosen type get +1/+1. - FilterCreaturePermanent filter = new FilterCreaturePermanent("Other creatures you control of the chosen type"); - filter.add(new ChosenSubtypePredicate(this.getId())); - filter.add(new AnotherPredicate()); - filter.add(new ControllerPredicate(TargetController.YOU)); - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostAllEffect(1, 1, Duration.WhileOnBattlefield, filter, false))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostAllOfChosenSubtypeEffect(1, 1, Duration.WhileOnBattlefield, filter, true))); } public AdaptiveAutomaton(final AdaptiveAutomaton card) { diff --git a/Mage.Sets/src/mage/sets/mirage/Shimmer.java b/Mage.Sets/src/mage/sets/mirage/Shimmer.java index 0f17fa2768d..fa2d3f501fd 100644 --- a/Mage.Sets/src/mage/sets/mirage/Shimmer.java +++ b/Mage.Sets/src/mage/sets/mirage/Shimmer.java @@ -31,7 +31,7 @@ import java.util.UUID; import mage.abilities.common.AsEntersBattlefieldAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.common.ChooseLandTypeEffect; -import mage.abilities.effects.common.continuous.GainAbilityAllEffect; +import mage.abilities.effects.common.continuous.GainAbilityAllOfChosenSubtypeEffect; import mage.abilities.keyword.PhasingAbility; import mage.cards.CardImpl; import mage.constants.CardType; @@ -40,7 +40,6 @@ import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; import mage.filter.common.FilterLandPermanent; -import mage.filter.predicate.mageobject.ChosenSubtypePredicate; /** * @@ -54,11 +53,11 @@ public class Shimmer extends CardImpl { // As Shimmer enters the battlefield, choose a land type. this.addAbility(new AsEntersBattlefieldAbility(new ChooseLandTypeEffect(Outcome.Detriment))); - + // Each land of the chosen type has phasing. - FilterLandPermanent filter = new FilterLandPermanent("Each land of the chosen type"); - filter.add(new ChosenSubtypePredicate(this.getId())); - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAllEffect(PhasingAbility.getInstance(), Duration.WhileOnBattlefield, filter, false))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, + new GainAbilityAllOfChosenSubtypeEffect(PhasingAbility.getInstance(), Duration.WhileOnBattlefield, + new FilterLandPermanent("Each land of the chosen type")))); } public Shimmer(final Shimmer card) { diff --git a/Mage.Sets/src/mage/sets/onslaught/SharedTriumph.java b/Mage.Sets/src/mage/sets/onslaught/SharedTriumph.java index 124f5484b66..7809d932054 100644 --- a/Mage.Sets/src/mage/sets/onslaught/SharedTriumph.java +++ b/Mage.Sets/src/mage/sets/onslaught/SharedTriumph.java @@ -31,15 +31,13 @@ import java.util.UUID; import mage.abilities.common.AsEntersBattlefieldAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.common.ChooseCreatureTypeEffect; -import mage.abilities.effects.common.continuous.BoostAllEffect; +import mage.abilities.effects.common.continuous.BoostAllOfChosenSubtypeEffect; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; -import mage.filter.common.FilterCreaturePermanent; -import mage.filter.predicate.mageobject.ChosenSubtypePredicate; /** * @@ -51,13 +49,10 @@ public class SharedTriumph extends CardImpl { super(ownerId, 53, "Shared Triumph", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{1}{W}"); this.expansionSetCode = "ONS"; - // As Shared Triumph enters the battlefield, choose a creature type. this.addAbility(new AsEntersBattlefieldAbility(new ChooseCreatureTypeEffect(Outcome.BoostCreature))); // Creatures of the chosen type get +1/+1. - FilterCreaturePermanent filter = new FilterCreaturePermanent("Creatures of the chosen type"); - filter.add(new ChosenSubtypePredicate(this.getId())); - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostAllEffect(1, 1, Duration.WhileOnBattlefield, filter, false))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostAllOfChosenSubtypeEffect(1, 1, Duration.WhileOnBattlefield, false))); } public SharedTriumph(final SharedTriumph card) { diff --git a/Mage.Sets/src/mage/sets/urzasdestiny/UrzasIncubator.java b/Mage.Sets/src/mage/sets/urzasdestiny/UrzasIncubator.java index e91445dce38..8d653debba8 100644 --- a/Mage.Sets/src/mage/sets/urzasdestiny/UrzasIncubator.java +++ b/Mage.Sets/src/mage/sets/urzasdestiny/UrzasIncubator.java @@ -31,14 +31,13 @@ import java.util.UUID; import mage.abilities.common.AsEntersBattlefieldAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.common.ChooseCreatureTypeEffect; -import mage.abilities.effects.common.cost.SpellsCostReductionAllEffect; +import mage.abilities.effects.common.cost.SpellsCostReductionAllOfChosenSubtypeEffect; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; import mage.filter.common.FilterCreatureCard; -import mage.filter.predicate.mageobject.ChosenSubtypePredicate; /** * @@ -53,9 +52,8 @@ public class UrzasIncubator extends CardImpl { // As Urza's Incubator enters the battlefield, choose a creature type. this.addAbility(new AsEntersBattlefieldAbility(new ChooseCreatureTypeEffect(Outcome.BoostCreature))); // Creature spells of the chosen type cost {2} less to cast. - FilterCreatureCard filter = new FilterCreatureCard("creature spells of the chosen type"); - filter.add(new ChosenSubtypePredicate(this.getId())); - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SpellsCostReductionAllEffect(filter, 2))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, + new SpellsCostReductionAllOfChosenSubtypeEffect(new FilterCreatureCard("creature spells of the chosen type"), 2))); } public UrzasIncubator(final UrzasIncubator card) { diff --git a/Mage.Sets/src/mage/sets/urzaslegacy/EngineeredPlague.java b/Mage.Sets/src/mage/sets/urzaslegacy/EngineeredPlague.java index 185a236c3c3..f511bcc5b4c 100644 --- a/Mage.Sets/src/mage/sets/urzaslegacy/EngineeredPlague.java +++ b/Mage.Sets/src/mage/sets/urzaslegacy/EngineeredPlague.java @@ -31,15 +31,13 @@ import java.util.UUID; import mage.abilities.common.AsEntersBattlefieldAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.common.ChooseCreatureTypeEffect; -import mage.abilities.effects.common.continuous.BoostAllEffect; +import mage.abilities.effects.common.continuous.BoostAllOfChosenSubtypeEffect; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; -import mage.filter.common.FilterCreaturePermanent; -import mage.filter.predicate.mageobject.ChosenSubtypePredicate; /** * @@ -51,13 +49,10 @@ public class EngineeredPlague extends CardImpl { super(ownerId, 51, "Engineered Plague", Rarity.UNCOMMON, new CardType[]{CardType.ENCHANTMENT}, "{2}{B}"); this.expansionSetCode = "ULG"; - // As Engineered Plague enters the battlefield, choose a creature type. this.addAbility(new AsEntersBattlefieldAbility(new ChooseCreatureTypeEffect(Outcome.UnboostCreature))); // All creatures of the chosen type get -1/-1. - FilterCreaturePermanent filter = new FilterCreaturePermanent("All creatures of the chosen type"); - filter.add(new ChosenSubtypePredicate(this.getId())); - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostAllEffect(-1, -1, Duration.WhileOnBattlefield, filter, false))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostAllOfChosenSubtypeEffect(-1, -1, Duration.WhileOnBattlefield, false))); } public EngineeredPlague(final EngineeredPlague card) { diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/BoostAllEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/BoostAllEffect.java index 70622957cea..452bdc4ea15 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/continuous/BoostAllEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/BoostAllEffect.java @@ -109,9 +109,10 @@ public class BoostAllEffect extends ContinuousEffectImpl { @Override public void init(Ability source, Game game) { super.init(source, game); + setRuntimeData(source, game); if (this.affectedObjectsSet) { for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { - if (!(excludeSource && perm.getId().equals(source.getSourceId()))) { + if (!(excludeSource && perm.getId().equals(source.getSourceId())) && selectedByRuntimeData(perm, source, game)) { affectedObjectList.add(new MageObjectReference(perm, game)); } } @@ -135,8 +136,9 @@ public class BoostAllEffect extends ContinuousEffectImpl { } } } else { + setRuntimeData(source, game); for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { - if (!(excludeSource && perm.getId().equals(source.getSourceId()))) { + if (!(excludeSource && perm.getId().equals(source.getSourceId())) && selectedByRuntimeData(perm, source, game)) { perm.addPower(power.calculate(game, source, this)); perm.addToughness(toughness.calculate(game, source, this)); } @@ -146,7 +148,29 @@ public class BoostAllEffect extends ContinuousEffectImpl { return true; } - private void setText() { + /** + * Overwrite this in effect that inherits from this + * + * @param source + * @param game + */ + protected void setRuntimeData(Ability source, Game game) { + + } + + /** + * Overwrite this in effect that inherits from this + * + * @param permanent + * @param source + * @param game + * @return + */ + protected boolean selectedByRuntimeData(Permanent permanent, Ability source, Game game) { + return true; + } + + protected void setText() { StringBuilder sb = new StringBuilder(); if (excludeSource) { sb.append("Other "); diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/BoostAllOfChosenSubtypeEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/BoostAllOfChosenSubtypeEffect.java new file mode 100644 index 00000000000..57282f413e7 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/BoostAllOfChosenSubtypeEffect.java @@ -0,0 +1,53 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package mage.abilities.effects.common.continuous; + +import mage.abilities.Ability; +import mage.constants.Duration; +import mage.filter.common.FilterCreaturePermanent; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author LevelX2 + */ +public class BoostAllOfChosenSubtypeEffect extends BoostAllEffect { + + String subtype = null; + + public BoostAllOfChosenSubtypeEffect(int power, int toughness, Duration duration, boolean excludeSource) { + super(power, toughness, duration, new FilterCreaturePermanent("All creatures of the chosen type"), excludeSource); + } + + public BoostAllOfChosenSubtypeEffect(int power, int toughness, Duration duration, FilterCreaturePermanent filter, boolean excludeSource) { + super(power, toughness, duration, filter, excludeSource); + } + + public BoostAllOfChosenSubtypeEffect(final BoostAllOfChosenSubtypeEffect effect) { + super(effect); + this.subtype = effect.subtype; + } + + @Override + public BoostAllOfChosenSubtypeEffect copy() { + return new BoostAllOfChosenSubtypeEffect(this); + } + + @Override + protected boolean selectedByRuntimeData(Permanent permanent, Ability source, Game game) { + if (subtype != null) { + return permanent.hasSubtype(subtype); + } + return false; + } + + @Override + protected void setRuntimeData(Ability source, Game game) { + subtype = (String) game.getState().getValue(source.getSourceId() + "_type"); + } + +} diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/GainAbilityAllEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/GainAbilityAllEffect.java index 70ec50c9b2b..b7a948f2983 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/continuous/GainAbilityAllEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/GainAbilityAllEffect.java @@ -92,9 +92,10 @@ public class GainAbilityAllEffect extends ContinuousEffectImpl { @Override public void init(Ability source, Game game) { super.init(source, game); + setRuntimeData(source, game); if (this.affectedObjectsSet) { for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { - if (!(excludeSource && perm.getId().equals(source.getSourceId()))) { + if (!(excludeSource && perm.getId().equals(source.getSourceId())) && selectedByRuntimeData(perm, source, game)) { affectedObjectList.add(new MageObjectReference(perm, game)); } } @@ -121,8 +122,9 @@ public class GainAbilityAllEffect extends ContinuousEffectImpl { } } } else { + setRuntimeData(source, game); for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { - if (!(excludeSource && perm.getId().equals(source.getSourceId()))) { + if (!(excludeSource && perm.getId().equals(source.getSourceId())) && selectedByRuntimeData(perm, source, game)) { perm.addAbility(ability, source.getSourceId(), game, false); } } @@ -131,7 +133,7 @@ public class GainAbilityAllEffect extends ContinuousEffectImpl { if (LKIBattlefield != null) { for (MageObject mageObject : LKIBattlefield.values()) { Permanent perm = (Permanent) mageObject; - if (!(excludeSource && perm.getId().equals(source.getSourceId()))) { + if (!(excludeSource && perm.getId().equals(source.getSourceId())) && selectedByRuntimeData(perm, source, game)) { if (filter.match(perm, source.getSourceId(), source.getControllerId(), game)) { perm.addAbility(ability, source.getSourceId(), game, false); } @@ -142,6 +144,28 @@ public class GainAbilityAllEffect extends ContinuousEffectImpl { return true; } + /** + * Overwrite this in effect that inherits from this + * + * @param source + * @param game + */ + protected void setRuntimeData(Ability source, Game game) { + + } + + /** + * Overwrite this in effect that inherits from this + * + * @param permanent + * @param source + * @param game + * @return + */ + protected boolean selectedByRuntimeData(Permanent permanent, Ability source, Game game) { + return true; + } + @Override public String getText(Mode mode) { if (staticText != null && !staticText.isEmpty()) { diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/GainAbilityAllOfChosenSubtypeEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/GainAbilityAllOfChosenSubtypeEffect.java new file mode 100644 index 00000000000..66d8367dd7f --- /dev/null +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/GainAbilityAllOfChosenSubtypeEffect.java @@ -0,0 +1,49 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package mage.abilities.effects.common.continuous; + +import mage.abilities.Ability; +import mage.constants.Duration; +import mage.filter.FilterPermanent; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author LevelX2 + */ +public class GainAbilityAllOfChosenSubtypeEffect extends GainAbilityAllEffect { + + String subtype = null; + + public GainAbilityAllOfChosenSubtypeEffect(Ability ability, Duration duration, FilterPermanent filter) { + super(ability, duration, filter); + } + + public GainAbilityAllOfChosenSubtypeEffect(final GainAbilityAllOfChosenSubtypeEffect effect) { + super(effect); + this.subtype = effect.subtype; + } + + @Override + public GainAbilityAllOfChosenSubtypeEffect copy() { + return new GainAbilityAllOfChosenSubtypeEffect(this); + } + + @Override + protected boolean selectedByRuntimeData(Permanent permanent, Ability source, Game game) { + if (subtype != null) { + return permanent.hasSubtype(subtype); + } + return false; + } + + @Override + protected void setRuntimeData(Ability source, Game game) { + subtype = (String) game.getState().getValue(source.getSourceId() + "_type"); + } + +} diff --git a/Mage/src/main/java/mage/abilities/effects/common/cost/SpellsCostReductionAllEffect.java b/Mage/src/main/java/mage/abilities/effects/common/cost/SpellsCostReductionAllEffect.java index 78830fd4157..2a5bffac42d 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/cost/SpellsCostReductionAllEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/cost/SpellsCostReductionAllEffect.java @@ -60,14 +60,14 @@ public class SpellsCostReductionAllEffect extends CostModificationEffectImpl { public SpellsCostReductionAllEffect(FilterCard filter, int amount) { this(filter, amount, false); } - + public SpellsCostReductionAllEffect(FilterCard filter, int amount, boolean upTo) { super(Duration.WhileOnBattlefield, Outcome.Benefit, CostModificationType.REDUCE_COST); this.filter = filter; this.amount = amount; this.upTo = upTo; - - this.staticText = filter.getMessage() + " cost " + (upTo ?"up to " :"") + "{" +amount + "} less to cast"; + + this.staticText = filter.getMessage() + " cost " + (upTo ? "up to " : "") + "{" + amount + "} less to cast"; } protected SpellsCostReductionAllEffect(SpellsCostReductionAllEffect effect) { @@ -109,16 +109,38 @@ public class SpellsCostReductionAllEffect extends CostModificationEffectImpl { return true; } + /** + * Overwrite this in effect that inherits from this + * + * @param source + * @param game + */ + protected void setRuntimeData(Ability source, Game game) { + + } + + /** + * Overwrite this in effect that inherits from this + * + * @param card + * @param source + * @param game + * @return + */ + protected boolean selectedByRuntimeData(Card card, Ability source, Game game) { + return true; + } + @Override public boolean applies(Ability abilityToModify, Ability source, Game game) { if (abilityToModify instanceof SpellAbility) { Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId()); if (spell != null) { - return this.filter.match(spell, game); + return this.filter.match(spell, game) && selectedByRuntimeData(spell, source, game); } else { // used at least for flashback ability because Flashback ability doesn't use stack Card sourceCard = game.getCard(abilityToModify.getSourceId()); - return sourceCard != null && this.filter.match(sourceCard, game); + return sourceCard != null && this.filter.match(sourceCard, game) && selectedByRuntimeData(sourceCard, source, game); } } return false; diff --git a/Mage/src/main/java/mage/abilities/effects/common/cost/SpellsCostReductionAllOfChosenSubtypeEffect.java b/Mage/src/main/java/mage/abilities/effects/common/cost/SpellsCostReductionAllOfChosenSubtypeEffect.java new file mode 100644 index 00000000000..18fe9c1028c --- /dev/null +++ b/Mage/src/main/java/mage/abilities/effects/common/cost/SpellsCostReductionAllOfChosenSubtypeEffect.java @@ -0,0 +1,48 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package mage.abilities.effects.common.cost; + +import mage.abilities.Ability; +import mage.cards.Card; +import mage.filter.FilterCard; +import mage.game.Game; + +/** + * + * @author LevelX2 + */ +public class SpellsCostReductionAllOfChosenSubtypeEffect extends SpellsCostReductionAllEffect { + + String subtype = null; + + public SpellsCostReductionAllOfChosenSubtypeEffect(FilterCard filter, int amount) { + super(filter, amount); + } + + public SpellsCostReductionAllOfChosenSubtypeEffect(final SpellsCostReductionAllOfChosenSubtypeEffect effect) { + super(effect); + this.subtype = effect.subtype; + } + + @Override + public SpellsCostReductionAllOfChosenSubtypeEffect copy() { + return new SpellsCostReductionAllOfChosenSubtypeEffect(this); + } + + @Override + protected boolean selectedByRuntimeData(Card card, Ability source, Game game) { + if (subtype != null) { + return card.hasSubtype(subtype); + } + return false; + } + + @Override + protected void setRuntimeData(Ability source, Game game) { + subtype = (String) game.getState().getValue(source.getSourceId() + "_type"); + } + +}