From ff85b56cad1236960dc793ffb7b80677b45448a3 Mon Sep 17 00:00:00 2001 From: North Date: Tue, 4 Sep 2012 10:35:33 +0300 Subject: [PATCH] [refactoring] Added SpellsCostReductionEffect and replaced existing effects --- .../LongForgottenGohei.java | 54 ++---------- .../sets/innistrad/HeartlessSummoning.java | 50 +---------- .../src/mage/sets/innistrad/RooftopStorm.java | 28 ------ .../src/mage/sets/scourge/GoblinWarchief.java | 48 ++--------- .../sets/shardsofalara/EtheriumSculptor.java | 47 +--------- .../mage/sets/tempest/EmeraldMedallion.java | 18 ++-- .../src/mage/sets/tempest/JetMedallion.java | 17 ++-- .../src/mage/sets/tempest/PearlMedallion.java | 17 ++-- .../src/mage/sets/tempest/RubyMedallion.java | 17 ++-- .../mage/sets/tempest/SapphireMedallion.java | 17 ++-- .../src/mage/sets/worldwake/EyeOfUgin.java | 61 ++----------- .../common/cost/ColorCostReductionEffect.java | 56 ------------ .../cost/SpellsCostReductionEffect.java | 86 +++++++++++++++++++ 13 files changed, 168 insertions(+), 348 deletions(-) delete mode 100644 Mage/src/mage/abilities/effects/common/cost/ColorCostReductionEffect.java create mode 100644 Mage/src/mage/abilities/effects/common/cost/SpellsCostReductionEffect.java diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/LongForgottenGohei.java b/Mage.Sets/src/mage/sets/championsofkamigawa/LongForgottenGohei.java index 6a0d2254a3..04cda14514 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/LongForgottenGohei.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/LongForgottenGohei.java @@ -33,20 +33,15 @@ import java.util.UUID; import mage.Constants.CardType; import mage.Constants.Duration; -import mage.Constants.Outcome; import mage.Constants.Rarity; import mage.Constants.Zone; -import mage.abilities.Ability; -import mage.abilities.SpellAbility; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.CostModificationEffectImpl; import mage.abilities.effects.common.continious.BoostControlledEffect; -import mage.cards.Card; +import mage.abilities.effects.common.cost.SpellsCostReductionEffect; import mage.cards.CardImpl; +import mage.filter.FilterCard; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.mageobject.SubtypePredicate; -import mage.game.Game; -import mage.util.CardUtil; /** * @@ -55,8 +50,11 @@ import mage.util.CardUtil; public class LongForgottenGohei extends CardImpl { - private final static FilterCreaturePermanent spiritFilter = new FilterCreaturePermanent("Spirits"); + private static final FilterCard arcaneFilter = new FilterCard("Arcane spells"); + private static final FilterCreaturePermanent spiritFilter = new FilterCreaturePermanent("Spirit creatures"); + static { + arcaneFilter.add(new SubtypePredicate("Arcane")); spiritFilter.add(new SubtypePredicate("Spirit")); } @@ -64,7 +62,7 @@ public class LongForgottenGohei extends CardImpl { super(ownerId, 261, "Long-Forgotten Gohei", Rarity.RARE, new CardType[]{CardType.ARTIFACT}, "{3}"); this.expansionSetCode = "CHK"; // Arcane spells you cast cost {1} less to cast. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new LongForgottenGoheiCostReductionEffect())); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SpellsCostReductionEffect(arcaneFilter, 1))); // Spirit creatures you control get +1/+1. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostControlledEffect(1, 1, Duration.WhileOnBattlefield, spiritFilter, false))); } @@ -77,41 +75,3 @@ public class LongForgottenGohei extends CardImpl { return new LongForgottenGohei(this); } } - -class LongForgottenGoheiCostReductionEffect extends CostModificationEffectImpl { - - LongForgottenGoheiCostReductionEffect ( ) { - super(Duration.WhileOnBattlefield, Outcome.Benefit); - staticText = "Arcane spells you cast cost {1} less to cast."; - } - - LongForgottenGoheiCostReductionEffect(LongForgottenGoheiCostReductionEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source, Ability abilityToModify) { - SpellAbility spellAbility = (SpellAbility) abilityToModify; - CardUtil.adjustCost(spellAbility, 1); - return true; - } - - @Override - public boolean applies(Ability abilityToModify, Ability source, Game game) { - if ( abilityToModify instanceof SpellAbility ) { - Card sourceCard = game.getCard(((SpellAbility)abilityToModify).getSourceId()); - if ( sourceCard != null && - sourceCard.getSubtype().contains("Arcane") && - sourceCard.getOwnerId().equals(source.getControllerId()) ) { - return true; - } - } - return false; - } - - @Override - public LongForgottenGoheiCostReductionEffect copy() { - return new LongForgottenGoheiCostReductionEffect(this); - } - -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/innistrad/HeartlessSummoning.java b/Mage.Sets/src/mage/sets/innistrad/HeartlessSummoning.java index 27ad47fa60..4d7cecc321 100644 --- a/Mage.Sets/src/mage/sets/innistrad/HeartlessSummoning.java +++ b/Mage.Sets/src/mage/sets/innistrad/HeartlessSummoning.java @@ -28,21 +28,15 @@ package mage.sets.innistrad; import java.util.UUID; -import mage.Constants; import mage.Constants.CardType; import mage.Constants.Duration; -import mage.Constants.Outcome; import mage.Constants.Rarity; import mage.Constants.Zone; -import mage.abilities.Ability; -import mage.abilities.SpellAbility; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.CostModificationEffectImpl; import mage.abilities.effects.common.continious.BoostControlledEffect; -import mage.cards.Card; +import mage.abilities.effects.common.cost.SpellsCostReductionEffect; import mage.cards.CardImpl; -import mage.game.Game; -import mage.util.CardUtil; +import mage.filter.common.FilterCreatureCard; /** * @@ -57,10 +51,10 @@ public class HeartlessSummoning extends CardImpl { this.color.setBlack(true); // Creature spells you cast cost {2} less to cast. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new HeartlessSummoningCostReductionEffect())); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SpellsCostReductionEffect(new FilterCreatureCard("Creature spells"), 2))); // Creatures you control get -1/-1. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostControlledEffect(-1, -1, Constants.Duration.WhileOnBattlefield))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostControlledEffect(-1, -1, Duration.WhileOnBattlefield))); } public HeartlessSummoning(final HeartlessSummoning card) { @@ -72,39 +66,3 @@ public class HeartlessSummoning extends CardImpl { return new HeartlessSummoning(this); } } - -class HeartlessSummoningCostReductionEffect extends CostModificationEffectImpl { - - HeartlessSummoningCostReductionEffect ( ) { - super(Duration.WhileOnBattlefield, Outcome.Benefit); - staticText = "Creature spells you cast cost {2} less to cast"; - } - - HeartlessSummoningCostReductionEffect(HeartlessSummoningCostReductionEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source, Ability abilityToModify) { - SpellAbility spellAbility = (SpellAbility) abilityToModify; - CardUtil.adjustCost(spellAbility, 2); - return true; - } - - @Override - public boolean applies(Ability abilityToModify, Ability source, Game game) { - if ( abilityToModify instanceof SpellAbility ) { - Card sourceCard = game.getCard(((SpellAbility)abilityToModify).getSourceId()); - if ( sourceCard != null && sourceCard.getCardType().contains(CardType.CREATURE) && sourceCard.getOwnerId().equals(source.getControllerId()) ) { - return true; - } - } - return false; - } - - @Override - public HeartlessSummoningCostReductionEffect copy() { - return new HeartlessSummoningCostReductionEffect(this); - } - -} diff --git a/Mage.Sets/src/mage/sets/innistrad/RooftopStorm.java b/Mage.Sets/src/mage/sets/innistrad/RooftopStorm.java index 48974c0473..c6e3fbd912 100644 --- a/Mage.Sets/src/mage/sets/innistrad/RooftopStorm.java +++ b/Mage.Sets/src/mage/sets/innistrad/RooftopStorm.java @@ -70,34 +70,6 @@ public class RooftopStorm extends CardImpl { } } -//class RooftopStormAlternativeCost extends AlternativeCostImpl { -// -// public RooftopStormAlternativeCost() { -// super("You may pay {0} rather than pay the mana cost"); -// this.add(new GenericManaCost(0)); -// } -// -// public RooftopStormAlternativeCost(final RooftopStormAlternativeCost cost) { -// super(cost); -// } -// -// @Override -// public RooftopStormAlternativeCost copy() { -// return new RooftopStormAlternativeCost(this); -// } -// -// @Override -// public boolean isAvailable(Game game, Ability source) { -// return true; -// } -// -// @Override -// public String getText() { -// return "You may pay {0} rather than pay the mana cost"; -// } -// -//} - class RooftopStormCostReductionEffect extends CostModificationEffectImpl { private static final String effectText = "You may pay {0} rather than pay the mana cost for Zombie creature spells you cast"; diff --git a/Mage.Sets/src/mage/sets/scourge/GoblinWarchief.java b/Mage.Sets/src/mage/sets/scourge/GoblinWarchief.java index bf65a5b339..8463a959a2 100644 --- a/Mage.Sets/src/mage/sets/scourge/GoblinWarchief.java +++ b/Mage.Sets/src/mage/sets/scourge/GoblinWarchief.java @@ -30,22 +30,17 @@ package mage.sets.scourge; import java.util.UUID; import mage.Constants.CardType; import mage.Constants.Duration; -import mage.Constants.Outcome; import mage.Constants.Rarity; import mage.Constants.Zone; import mage.MageInt; -import mage.abilities.Ability; -import mage.abilities.SpellAbility; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.CostModificationEffectImpl; import mage.abilities.effects.common.continious.GainAbilityControlledEffect; +import mage.abilities.effects.common.cost.SpellsCostReductionEffect; import mage.abilities.keyword.HasteAbility; -import mage.cards.Card; import mage.cards.CardImpl; +import mage.filter.FilterCard; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.mageobject.SubtypePredicate; -import mage.game.Game; -import mage.util.CardUtil; /** * @@ -53,10 +48,12 @@ import mage.util.CardUtil; */ public class GoblinWarchief extends CardImpl { + private static final FilterCard filterSpells = new FilterCard("Goblin spells"); private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("Goblin creatures"); static { filter.add(new SubtypePredicate("Goblin")); + filter.add(new SubtypePredicate("Goblin")); } public GoblinWarchief(UUID ownerId) { @@ -69,7 +66,7 @@ public class GoblinWarchief extends CardImpl { this.toughness = new MageInt(2); // Goblin spells you cast cost {1} less to cast. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GoblinWarchiefEffect())); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SpellsCostReductionEffect(filterSpells, 1))); // Goblin creatures you control have haste. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityControlledEffect(HasteAbility.getInstance(), Duration.WhileOnBattlefield, filter, true))); } @@ -83,38 +80,3 @@ public class GoblinWarchief extends CardImpl { return new GoblinWarchief(this); } } - -class GoblinWarchiefEffect extends CostModificationEffectImpl { - - GoblinWarchiefEffect() { - super(Duration.WhileOnBattlefield, Outcome.Benefit); - staticText = "Goblin spells you cast cost {1} less to cast"; - } - - GoblinWarchiefEffect(GoblinWarchiefEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source, Ability abilityToModify) { - SpellAbility spellAbility = (SpellAbility) abilityToModify; - CardUtil.adjustCost(spellAbility, 1); - return true; - } - - @Override - public boolean applies(Ability abilityToModify, Ability source, Game game) { - if (abilityToModify instanceof SpellAbility) { - Card sourceCard = game.getCard(((SpellAbility) abilityToModify).getSourceId()); - if (sourceCard != null && sourceCard.getSubtype().contains("Goblin") && sourceCard.getOwnerId().equals(source.getControllerId())) { - return true; - } - } - return false; - } - - @Override - public GoblinWarchiefEffect copy() { - return new GoblinWarchiefEffect(this); - } -} diff --git a/Mage.Sets/src/mage/sets/shardsofalara/EtheriumSculptor.java b/Mage.Sets/src/mage/sets/shardsofalara/EtheriumSculptor.java index 8c74da0e60..ae6b9b46e1 100644 --- a/Mage.Sets/src/mage/sets/shardsofalara/EtheriumSculptor.java +++ b/Mage.Sets/src/mage/sets/shardsofalara/EtheriumSculptor.java @@ -29,19 +29,13 @@ package mage.sets.shardsofalara; import java.util.UUID; import mage.Constants.CardType; -import mage.Constants.Duration; -import mage.Constants.Outcome; import mage.Constants.Rarity; import mage.Constants.Zone; import mage.MageInt; -import mage.abilities.Ability; -import mage.abilities.SpellAbility; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.CostModificationEffectImpl; -import mage.cards.Card; +import mage.abilities.effects.common.cost.SpellsCostReductionEffect; import mage.cards.CardImpl; -import mage.game.Game; -import mage.util.CardUtil; +import mage.filter.common.FilterArtifactCard; /** * @@ -60,7 +54,7 @@ public class EtheriumSculptor extends CardImpl { this.toughness = new MageInt(2); // Artifact spells you cast cost {1} less to cast. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new EtheriumSculptorEffect())); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SpellsCostReductionEffect(new FilterArtifactCard("Artifact spells"), 1))); } public EtheriumSculptor(final EtheriumSculptor card) { @@ -72,38 +66,3 @@ public class EtheriumSculptor extends CardImpl { return new EtheriumSculptor(this); } } - -class EtheriumSculptorEffect extends CostModificationEffectImpl { - - EtheriumSculptorEffect() { - super(Duration.WhileOnBattlefield, Outcome.Benefit); - staticText = "Artifact spells you cast cost {1} less to cast"; - } - - EtheriumSculptorEffect(EtheriumSculptorEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source, Ability abilityToModify) { - SpellAbility spellAbility = (SpellAbility) abilityToModify; - CardUtil.adjustCost(spellAbility, 1); - return true; - } - - @Override - public boolean applies(Ability abilityToModify, Ability source, Game game) { - if (abilityToModify instanceof SpellAbility) { - Card sourceCard = game.getCard(((SpellAbility) abilityToModify).getSourceId()); - if (sourceCard != null && sourceCard.getCardType().contains(CardType.ARTIFACT) && sourceCard.getOwnerId().equals(source.getControllerId())) { - return true; - } - } - return false; - } - - @Override - public EtheriumSculptorEffect copy() { - return new EtheriumSculptorEffect(this); - } -} diff --git a/Mage.Sets/src/mage/sets/tempest/EmeraldMedallion.java b/Mage.Sets/src/mage/sets/tempest/EmeraldMedallion.java index 4b17fc5394..3d8846be39 100644 --- a/Mage.Sets/src/mage/sets/tempest/EmeraldMedallion.java +++ b/Mage.Sets/src/mage/sets/tempest/EmeraldMedallion.java @@ -27,29 +27,34 @@ */ package mage.sets.tempest; -import mage.Constants; +import java.util.UUID; import mage.Constants.CardType; import mage.Constants.Rarity; +import mage.Constants.Zone; import mage.ObjectColor; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.common.cost.ColorCostReductionEffect; +import mage.abilities.effects.common.cost.SpellsCostReductionEffect; import mage.cards.CardImpl; - -import java.util.UUID; +import mage.filter.FilterCard; +import mage.filter.predicate.mageobject.ColorPredicate; /** * @author noxx */ public class EmeraldMedallion extends CardImpl { - private static final String ruleText = "Green spells you cast cost {1} less to cast"; + private static final FilterCard filter = new FilterCard("Green spells"); + + static { + filter.add(new ColorPredicate(ObjectColor.GREEN)); + } public EmeraldMedallion(UUID ownerId) { super(ownerId, 273, "Emerald Medallion", Rarity.RARE, new CardType[]{CardType.ARTIFACT}, "{2}"); this.expansionSetCode = "TMP"; // Green spells you cast cost {1} less to cast. - this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, new ColorCostReductionEffect(ObjectColor.GREEN, 1, ruleText))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SpellsCostReductionEffect(filter, 1))); } public EmeraldMedallion(final EmeraldMedallion card) { @@ -61,4 +66,3 @@ public class EmeraldMedallion extends CardImpl { return new EmeraldMedallion(this); } } - diff --git a/Mage.Sets/src/mage/sets/tempest/JetMedallion.java b/Mage.Sets/src/mage/sets/tempest/JetMedallion.java index c4d65325d5..a412fba215 100644 --- a/Mage.Sets/src/mage/sets/tempest/JetMedallion.java +++ b/Mage.Sets/src/mage/sets/tempest/JetMedallion.java @@ -27,29 +27,34 @@ */ package mage.sets.tempest; -import mage.Constants; +import java.util.UUID; import mage.Constants.CardType; import mage.Constants.Rarity; +import mage.Constants.Zone; import mage.ObjectColor; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.common.cost.ColorCostReductionEffect; +import mage.abilities.effects.common.cost.SpellsCostReductionEffect; import mage.cards.CardImpl; - -import java.util.UUID; +import mage.filter.FilterCard; +import mage.filter.predicate.mageobject.ColorPredicate; /** * @author noxx */ public class JetMedallion extends CardImpl { - private static final String ruleText = "Black spells you cast cost {1} less to cast"; + private static final FilterCard filter = new FilterCard("Black spells"); + + static { + filter.add(new ColorPredicate(ObjectColor.BLACK)); + } public JetMedallion(UUID ownerId) { super(ownerId, 282, "Jet Medallion", Rarity.RARE, new CardType[]{CardType.ARTIFACT}, "{2}"); this.expansionSetCode = "TMP"; // Black spells you cast cost {1} less to cast. - this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, new ColorCostReductionEffect(ObjectColor.BLACK, 1, ruleText))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SpellsCostReductionEffect(filter, 1))); } public JetMedallion(final JetMedallion card) { diff --git a/Mage.Sets/src/mage/sets/tempest/PearlMedallion.java b/Mage.Sets/src/mage/sets/tempest/PearlMedallion.java index 69784d6992..cfbc518407 100644 --- a/Mage.Sets/src/mage/sets/tempest/PearlMedallion.java +++ b/Mage.Sets/src/mage/sets/tempest/PearlMedallion.java @@ -27,29 +27,34 @@ */ package mage.sets.tempest; -import mage.Constants; +import java.util.UUID; import mage.Constants.CardType; import mage.Constants.Rarity; +import mage.Constants.Zone; import mage.ObjectColor; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.common.cost.ColorCostReductionEffect; +import mage.abilities.effects.common.cost.SpellsCostReductionEffect; import mage.cards.CardImpl; - -import java.util.UUID; +import mage.filter.FilterCard; +import mage.filter.predicate.mageobject.ColorPredicate; /** * @author noxx */ public class PearlMedallion extends CardImpl { - private static final String ruleText = "White spells you cast cost {1} less to cast"; + private static final FilterCard filter = new FilterCard("White spells"); + + static { + filter.add(new ColorPredicate(ObjectColor.WHITE)); + } public PearlMedallion(UUID ownerId) { super(ownerId, 290, "Pearl Medallion", Rarity.RARE, new CardType[]{CardType.ARTIFACT}, "{2}"); this.expansionSetCode = "TMP"; // White spells you cast cost {1} less to cast. - this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, new ColorCostReductionEffect(ObjectColor.WHITE, 1, ruleText))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SpellsCostReductionEffect(filter, 1))); } public PearlMedallion(final PearlMedallion card) { diff --git a/Mage.Sets/src/mage/sets/tempest/RubyMedallion.java b/Mage.Sets/src/mage/sets/tempest/RubyMedallion.java index b24d162a71..61a5fd7df2 100644 --- a/Mage.Sets/src/mage/sets/tempest/RubyMedallion.java +++ b/Mage.Sets/src/mage/sets/tempest/RubyMedallion.java @@ -27,29 +27,34 @@ */ package mage.sets.tempest; -import mage.Constants; +import java.util.UUID; import mage.Constants.CardType; import mage.Constants.Rarity; +import mage.Constants.Zone; import mage.ObjectColor; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.common.cost.ColorCostReductionEffect; +import mage.abilities.effects.common.cost.SpellsCostReductionEffect; import mage.cards.CardImpl; - -import java.util.UUID; +import mage.filter.FilterCard; +import mage.filter.predicate.mageobject.ColorPredicate; /** * @author noxx */ public class RubyMedallion extends CardImpl { - private static final String ruleText = "Red spells you cast cost {1} less to cast"; + private static final FilterCard filter = new FilterCard("Red spells"); + + static { + filter.add(new ColorPredicate(ObjectColor.RED)); + } public RubyMedallion(UUID ownerId) { super(ownerId, 295, "Ruby Medallion", Rarity.RARE, new CardType[]{CardType.ARTIFACT}, "{2}"); this.expansionSetCode = "TMP"; // Red spells you cast cost {1} less to cast. - this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, new ColorCostReductionEffect(ObjectColor.RED, 1, ruleText))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SpellsCostReductionEffect(filter, 1))); } public RubyMedallion(final RubyMedallion card) { diff --git a/Mage.Sets/src/mage/sets/tempest/SapphireMedallion.java b/Mage.Sets/src/mage/sets/tempest/SapphireMedallion.java index 0d41c76f14..dabd727360 100644 --- a/Mage.Sets/src/mage/sets/tempest/SapphireMedallion.java +++ b/Mage.Sets/src/mage/sets/tempest/SapphireMedallion.java @@ -27,29 +27,34 @@ */ package mage.sets.tempest; -import mage.Constants; +import java.util.UUID; import mage.Constants.CardType; import mage.Constants.Rarity; +import mage.Constants.Zone; import mage.ObjectColor; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.common.cost.ColorCostReductionEffect; +import mage.abilities.effects.common.cost.SpellsCostReductionEffect; import mage.cards.CardImpl; - -import java.util.UUID; +import mage.filter.FilterCard; +import mage.filter.predicate.mageobject.ColorPredicate; /** * @author noxx */ public class SapphireMedallion extends CardImpl { - private static final String ruleText = "Blue spells you cast cost {1} less to cast"; + private static final FilterCard filter = new FilterCard("Blue spells"); + + static { + filter.add(new ColorPredicate(ObjectColor.BLUE)); + } public SapphireMedallion(UUID ownerId) { super(ownerId, 296, "Sapphire Medallion", Rarity.RARE, new CardType[]{CardType.ARTIFACT}, "{2}"); this.expansionSetCode = "TMP"; // Blue spells you cast cost {1} less to cast. - this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, new ColorCostReductionEffect(ObjectColor.BLUE, 1, ruleText))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SpellsCostReductionEffect(filter, 1))); } public SapphireMedallion(final SapphireMedallion card) { diff --git a/Mage.Sets/src/mage/sets/worldwake/EyeOfUgin.java b/Mage.Sets/src/mage/sets/worldwake/EyeOfUgin.java index a4ac95eb08..3d42e36aa3 100644 --- a/Mage.Sets/src/mage/sets/worldwake/EyeOfUgin.java +++ b/Mage.Sets/src/mage/sets/worldwake/EyeOfUgin.java @@ -30,23 +30,20 @@ package mage.sets.worldwake; import java.util.UUID; import mage.Constants.CardType; -import mage.Constants.Duration; -import mage.Constants.Outcome; import mage.Constants.Rarity; import mage.Constants.Zone; import mage.abilities.Ability; -import mage.abilities.SpellAbility; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.CostModificationEffectImpl; +import mage.abilities.effects.common.cost.SpellsCostReductionEffect; import mage.abilities.effects.common.search.SearchLibraryPutInHandEffect; -import mage.cards.Card; import mage.cards.CardImpl; +import mage.filter.FilterCard; import mage.filter.common.FilterCreatureCard; import mage.filter.predicate.mageobject.ColorlessPredicate; -import mage.game.Game; +import mage.filter.predicate.mageobject.SubtypePredicate; import mage.target.common.TargetCardInLibrary; /** @@ -55,11 +52,13 @@ import mage.target.common.TargetCardInLibrary; */ public class EyeOfUgin extends CardImpl { - private static final FilterCreatureCard filter; + private static final FilterCreatureCard filter = new FilterCreatureCard(); + private static final FilterCard filterSpells = new FilterCard("Colorless Eldrazi spells"); static { - filter = new FilterCreatureCard(); filter.add(new ColorlessPredicate()); + filterSpells.add(new ColorlessPredicate()); + filterSpells.add(new SubtypePredicate("Eldrazi")); } public EyeOfUgin (UUID ownerId) { @@ -69,7 +68,7 @@ public class EyeOfUgin extends CardImpl { this.subtype.add("Land"); // Colorless Eldrazi spells you cast cost {2} less to cast. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new EyeOfUginCostReductionEffect())); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SpellsCostReductionEffect(filterSpells, 2))); // {7}, {tap}: Search your library for a colorless creature card, reveal it, and put it into your hand. Then shuffle your library. Ability searchAbility = new SimpleActivatedAbility(Zone.BATTLEFIELD, new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true), @@ -87,47 +86,3 @@ public class EyeOfUgin extends CardImpl { return new EyeOfUgin(this); } } - -class EyeOfUginCostReductionEffect extends CostModificationEffectImpl { - - private static final String effectText = "Colorless Eldrazi spells you cast cost {2} less to cast"; - - EyeOfUginCostReductionEffect ( ) { - super(Duration.WhileOnBattlefield, Outcome.Benefit); - staticText = effectText; - } - - EyeOfUginCostReductionEffect(EyeOfUginCostReductionEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source, Ability abilityToModify) { - SpellAbility spellAbility = (SpellAbility)abilityToModify; - int previousCost = spellAbility.getManaCostsToPay().convertedManaCost(); - int adjustedCost = 0; - if ( (previousCost - 2) > 0 ) { - adjustedCost = previousCost - 2; - } - spellAbility.getManaCostsToPay().load("{" + adjustedCost + "}"); - - return true; - } - - @Override - public boolean applies(Ability abilityToModify, Ability source, Game game) { - if ( abilityToModify instanceof SpellAbility ) { - Card sourceCard = game.getCard(((SpellAbility)abilityToModify).getSourceId()); - if ( sourceCard != null && sourceCard.hasSubtype("Eldrazi") && sourceCard.getOwnerId().equals(source.getControllerId()) ) { - return true; - } - } - return false; - } - - @Override - public EyeOfUginCostReductionEffect copy() { - return new EyeOfUginCostReductionEffect(this); - } - -} diff --git a/Mage/src/mage/abilities/effects/common/cost/ColorCostReductionEffect.java b/Mage/src/mage/abilities/effects/common/cost/ColorCostReductionEffect.java deleted file mode 100644 index b0dd249a41..0000000000 --- a/Mage/src/mage/abilities/effects/common/cost/ColorCostReductionEffect.java +++ /dev/null @@ -1,56 +0,0 @@ -package mage.abilities.effects.common.cost; - -import mage.Constants; -import mage.ObjectColor; -import mage.abilities.Ability; -import mage.abilities.SpellAbility; -import mage.abilities.effects.CostModificationEffectImpl; -import mage.cards.Card; -import mage.game.Game; -import mage.util.CardUtil; - -/** - * @author noxx - */ -public class ColorCostReductionEffect extends CostModificationEffectImpl { - - private ObjectColor color; - private int reduceCount; - - public ColorCostReductionEffect(ObjectColor color, int reduceCount, String ruleText) { - super(Constants.Duration.WhileOnBattlefield, Constants.Outcome.Benefit); - staticText = ruleText; - this.color = color; - this.reduceCount = reduceCount; - } - - private ColorCostReductionEffect(ColorCostReductionEffect effect) { - super(effect); - this.color = effect.color; - this.reduceCount = effect.reduceCount; - } - - @Override - public boolean apply(Game game, Ability source, Ability abilityToModify) { - SpellAbility spellAbility = (SpellAbility) abilityToModify; - CardUtil.adjustCost(spellAbility, this.reduceCount); - return true; - } - - @Override - public boolean applies(Ability abilityToModify, Ability source, Game game) { - if ( abilityToModify instanceof SpellAbility ) { - Card sourceCard = game.getCard(abilityToModify.getSourceId()); - if ( sourceCard != null && sourceCard.getColor().contains(color) && sourceCard.getOwnerId().equals(source.getControllerId()) ) { - return true; - } - } - return false; - } - - @Override - public ColorCostReductionEffect copy() { - return new ColorCostReductionEffect(this); - } - -} \ No newline at end of file diff --git a/Mage/src/mage/abilities/effects/common/cost/SpellsCostReductionEffect.java b/Mage/src/mage/abilities/effects/common/cost/SpellsCostReductionEffect.java new file mode 100644 index 0000000000..cee9e0d522 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/cost/SpellsCostReductionEffect.java @@ -0,0 +1,86 @@ +/* + * 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.effects.common.cost; + +import mage.Constants.Duration; +import mage.Constants.Outcome; +import mage.abilities.Ability; +import mage.abilities.SpellAbility; +import mage.abilities.effects.CostModificationEffectImpl; +import mage.cards.Card; +import mage.filter.FilterCard; +import mage.game.Game; +import mage.util.CardUtil; + +/** + * + * @author North + */ +public class SpellsCostReductionEffect extends CostModificationEffectImpl { + + private FilterCard filter; + private int amount; + + public SpellsCostReductionEffect(FilterCard filter, int amount) { + super(Duration.WhileOnBattlefield, Outcome.Benefit); + this.filter = filter; + this.amount = amount; + + StringBuilder sb = new StringBuilder(); + sb.append(filter.getMessage()).append(" you cast cost {").append(amount).append("} less to cast"); + this.staticText = sb.toString(); + } + + protected SpellsCostReductionEffect(SpellsCostReductionEffect effect) { + super(effect); + this.filter = effect.filter; + this.amount = effect.amount; + } + + @Override + public boolean apply(Game game, Ability source, Ability abilityToModify) { + SpellAbility spellAbility = (SpellAbility) abilityToModify; + CardUtil.adjustCost(spellAbility, this.amount); + return true; + } + + @Override + public boolean applies(Ability abilityToModify, Ability source, Game game) { + if (abilityToModify instanceof SpellAbility + && abilityToModify.getControllerId().equals(source.getControllerId())) { + Card sourceCard = game.getCard(abilityToModify.getSourceId()); + return sourceCard != null && this.filter.match(sourceCard, game); + } + return false; + } + + @Override + public SpellsCostReductionEffect copy() { + return new SpellsCostReductionEffect(this); + } +}