diff --git a/Mage.Sets/src/mage/sets/avacynrestored/ArcaneMelee.java b/Mage.Sets/src/mage/sets/avacynrestored/ArcaneMelee.java index 68833fd61d..00627c61f4 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/ArcaneMelee.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/ArcaneMelee.java @@ -34,6 +34,8 @@ import mage.abilities.Ability; import mage.abilities.SpellAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.CostModificationEffectImpl; +import mage.abilities.keyword.FlashbackAbility; +import mage.abilities.keyword.RetraceAbility; import mage.cards.Card; import mage.cards.CardImpl; import mage.game.Game; @@ -87,7 +89,7 @@ class ArcaneMeleeCostReductionEffect extends CostModificationEffectImpl { @Override public boolean applies(Ability abilityToModify, Ability source, Game game) { - if (abilityToModify instanceof SpellAbility) { - SpellAbility spell = (SpellAbility) abilityToModify; + if (abilityToModify instanceof SpellAbility || abilityToModify instanceof FlashbackAbility || abilityToModify instanceof RetraceAbility) { + Ability spell = abilityToModify; if (spell.getControllerId().equals(source.getControllerId())) { Card sourceCard = game.getCard(spell.getSourceId()); if (sourceCard != null && sourceCard.hasSubtype("Samurai")) { diff --git a/Mage.Sets/src/mage/sets/darkascension/ThaliaGuardianOfThraben.java b/Mage.Sets/src/mage/sets/darkascension/ThaliaGuardianOfThraben.java index ce465dd388..f752a82b7d 100644 --- a/Mage.Sets/src/mage/sets/darkascension/ThaliaGuardianOfThraben.java +++ b/Mage.Sets/src/mage/sets/darkascension/ThaliaGuardianOfThraben.java @@ -27,7 +27,6 @@ */ package mage.sets.darkascension; -import java.util.UUID; import mage.Constants; import mage.Constants.CardType; import mage.Constants.Rarity; @@ -35,12 +34,16 @@ import mage.MageInt; import mage.abilities.Ability; import mage.abilities.SpellAbility; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.effects.CostModificationEffectImpl; import mage.abilities.keyword.FirstStrikeAbility; +import mage.abilities.keyword.FlashbackAbility; +import mage.abilities.keyword.RetraceAbility; import mage.cards.Card; import mage.cards.CardImpl; import mage.game.Game; +import mage.util.CardUtil; + +import java.util.UUID; /** * @@ -89,14 +92,13 @@ class ThaliaGuardianOfThrabenCostReductionEffect extends CostModificationEffectI @Override public boolean apply(Game game, Ability source, Ability abilityToModify) { - SpellAbility spellAbility = (SpellAbility) abilityToModify; - spellAbility.getManaCostsToPay().add(new GenericManaCost(1)); + CardUtil.increaseCost(abilityToModify, 1); return true; } @Override public boolean applies(Ability abilityToModify, Ability source, Game game) { - if (abilityToModify instanceof SpellAbility) { + if (abilityToModify instanceof SpellAbility || abilityToModify instanceof FlashbackAbility || abilityToModify instanceof RetraceAbility) { Card card = game.getCard(abilityToModify.getSourceId()); if (card != null && !card.getCardType().contains(CardType.CREATURE)) { return true; diff --git a/Mage.Sets/src/mage/sets/innistrad/RooftopStorm.java b/Mage.Sets/src/mage/sets/innistrad/RooftopStorm.java index 8fe712598b..baca5e5b0f 100644 --- a/Mage.Sets/src/mage/sets/innistrad/RooftopStorm.java +++ b/Mage.Sets/src/mage/sets/innistrad/RooftopStorm.java @@ -27,7 +27,6 @@ */ package mage.sets.innistrad; -import java.util.UUID; import mage.Constants; import mage.Constants.CardType; import mage.Constants.Outcome; @@ -37,12 +36,16 @@ import mage.abilities.SpellAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.CostModificationEffectImpl; +import mage.abilities.keyword.FlashbackAbility; +import mage.abilities.keyword.RetraceAbility; import mage.cards.Card; import mage.cards.CardImpl; import mage.game.Game; import mage.players.Player; import mage.util.CardUtil; +import java.util.UUID; + /** * * @author BetaSteward @@ -92,8 +95,8 @@ class RooftopStormCostReductionEffect extends CostModificationEffectImpl { @Override public boolean applies(Ability abilityToModify, Ability source, Game game) { - if (abilityToModify instanceof SpellAbility) { + if (abilityToModify instanceof SpellAbility || abilityToModify instanceof FlashbackAbility || abilityToModify instanceof RetraceAbility) { Card sourceCard = game.getCard(abilityToModify.getSourceId()); StackObject stackObject = game.getStack().getStackObject(abilityToModify.getSourceId()); if (stackObject != null && stackObject instanceof Spell) { diff --git a/Mage.Sets/src/mage/sets/ninthedition/DefenseGrid.java b/Mage.Sets/src/mage/sets/ninthedition/DefenseGrid.java index 1be0b1eb53..f757aaaa7c 100644 --- a/Mage.Sets/src/mage/sets/ninthedition/DefenseGrid.java +++ b/Mage.Sets/src/mage/sets/ninthedition/DefenseGrid.java @@ -27,7 +27,6 @@ */ package mage.sets.ninthedition; -import java.util.UUID; import mage.Constants; import mage.Constants.CardType; import mage.Constants.Rarity; @@ -36,9 +35,13 @@ import mage.abilities.SpellAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.effects.CostModificationEffectImpl; +import mage.abilities.keyword.FlashbackAbility; +import mage.abilities.keyword.RetraceAbility; import mage.cards.CardImpl; import mage.game.Game; +import java.util.UUID; + /** * * @author Plopman @@ -84,7 +87,7 @@ class DefenseGridCostModificationEffect extends CostModificationEffectImpl 0) { - CardUtil.adjustCost(spellAbility, amount); + CardUtil.reduceCost(spellAbility, amount); return true; } } @@ -152,8 +155,8 @@ class RakdosLordOfRiotsCostReductionEffect extends CostModificationEffectImpl> implements Ability { return false; } + //20101001 - 601.2e + game.getContinuousEffects().costModification(this, game); + if (!useAlternativeCost(game)) { - //20101001 - 601.2e - game.getContinuousEffects().costModification(this, game); //20100716 - 601.2f if (!manaCostsToPay.pay(this, game, sourceId, controllerId, noMana)) { diff --git a/Mage/src/mage/abilities/SpellAbility.java b/Mage/src/mage/abilities/SpellAbility.java index e0d5272c8f..a2d4989d9f 100644 --- a/Mage/src/mage/abilities/SpellAbility.java +++ b/Mage/src/mage/abilities/SpellAbility.java @@ -33,7 +33,9 @@ import mage.Constants.AsThoughEffectType; import mage.Constants.CardType; import mage.Constants.Zone; import mage.MageObject; +import mage.abilities.costs.Cost; import mage.abilities.costs.mana.ManaCost; +import mage.abilities.effects.Effect; import mage.abilities.keyword.FlashAbility; import mage.game.Game; @@ -46,11 +48,20 @@ import java.util.UUID; public class SpellAbility extends ActivatedAbilityImpl { public SpellAbility(ManaCost cost, String cardName) { - super(AbilityType.SPELL, Zone.HAND); + this(cost, cardName, Zone.HAND); + } + + public SpellAbility(ManaCost cost, String cardName, Zone zone) { + super(AbilityType.SPELL, zone); this.addManaCost(cost); this.name = "Cast " + cardName; } + public SpellAbility(Cost cost, String cardName, Effect effect, Zone zone) { + super(zone, effect, cost); + this.name = "Cast " + cardName; + } + public SpellAbility(SpellAbility ability) { super(ability); } diff --git a/Mage/src/mage/abilities/effects/common/cost/SpellsCostReductionEffect.java b/Mage/src/mage/abilities/effects/common/cost/SpellsCostReductionEffect.java index e3294d7d08..8d372afff0 100644 --- a/Mage/src/mage/abilities/effects/common/cost/SpellsCostReductionEffect.java +++ b/Mage/src/mage/abilities/effects/common/cost/SpellsCostReductionEffect.java @@ -65,7 +65,7 @@ public class SpellsCostReductionEffect extends CostModificationEffectImpl { +public class FlashbackAbility extends /*SpellAbility*/ ActivatedAbilityImpl { public FlashbackAbility(Cost cost, Constants.TimingRule timingRule) { + //super(cost, "", new FlashbackEffect(), Constants.Zone.GRAVEYARD); super(Constants.Zone.GRAVEYARD, new FlashbackEffect(), cost); this.timing = timingRule; this.usesStack = false; diff --git a/Mage/src/mage/util/CardUtil.java b/Mage/src/mage/util/CardUtil.java index becfbf174b..3eb2556f7e 100644 --- a/Mage/src/mage/util/CardUtil.java +++ b/Mage/src/mage/util/CardUtil.java @@ -32,6 +32,8 @@ import mage.Constants; import mage.Mana; import mage.abilities.Ability; import mage.abilities.SpellAbility; +import mage.abilities.costs.AlternativeCost; +import mage.abilities.costs.AlternativeCostImpl; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.costs.mana.ManaCost; import mage.abilities.costs.mana.ManaCosts; @@ -41,6 +43,8 @@ import mage.game.permanent.token.Token; import mage.util.functions.CopyFunction; import mage.util.functions.CopyTokenFunction; +import java.util.Iterator; + /** * @author nantuko */ @@ -88,6 +92,63 @@ public class CardUtil { return false; } + + /** + * Increase spell or ability cost to be paid. + * + * @param ability + * @param increaseCount + */ + public static void increaseCost(Ability ability, int increaseCount) { + adjustCost(ability, -increaseCount); + adjustAlternativeCosts(ability, -increaseCount); + } + + /** + * Reduces ability cost to be paid. + * + * @param ability + * @param reduceCount + */ + public static void reduceCost(Ability ability, int reduceCount) { + adjustCost(ability, reduceCount); + adjustAlternativeCosts(ability, reduceCount); + } + + private static void adjustAlternativeCosts(Ability ability, int reduceCount) { + for (AlternativeCost alternativeCost : ability.getAlternativeCosts()) { + if (alternativeCost instanceof AlternativeCostImpl) { + AlternativeCostImpl impl = (AlternativeCostImpl) alternativeCost; + ManaCosts adjustedCost = new ManaCostsImpl(); + boolean updated = false; + Iterator it = impl.iterator(); + while (it.hasNext()) { + Object cost = it.next(); + if (cost instanceof ManaCosts) { + for (Object object : ((ManaCosts) cost)) { + if (object instanceof ManaCost) { + ManaCost manaCost = (ManaCost) object; + Mana mana = manaCost.getOptions().get(0); + int colorless = mana != null ? mana.getColorless() : 0; + if (!updated && colorless > 0) { + if ((colorless - reduceCount) > 0) { + int newColorless = colorless - reduceCount; + it.remove(); + adjustedCost.add(new GenericManaCost(newColorless)); + } + updated = true; + } else { + adjustedCost.add(manaCost); + } + } + } + } + } + impl.add(adjustedCost); + } + } + } + /** * Adjusts spell or ability cost to be paid. * @@ -95,32 +156,39 @@ public class CardUtil { * @param reduceCount */ public static void adjustCost(SpellAbility spellAbility, int reduceCount) { - Ability ability = (Ability) spellAbility; - CardUtil.adjustCost(ability, reduceCount); + CardUtil.adjustCost(spellAbility, reduceCount); + adjustAlternativeCosts(spellAbility, reduceCount); } + /** * Adjusts ability cost to be paid. * * @param ability * @param reduceCount */ - public static void adjustCost(Ability ability, int reduceCount) { + private static void adjustCost(Ability ability, int reduceCount) { ManaCosts previousCost = ability.getManaCostsToPay(); ManaCosts adjustedCost = new ManaCostsImpl(); - boolean reduced = false; + boolean updated = false; for (ManaCost manaCost : previousCost) { Mana mana = manaCost.getOptions().get(0); int colorless = mana != null ? mana.getColorless() : 0; - if (!reduced && colorless > 0) { + if (!updated && colorless > 0) { if ((colorless - reduceCount) > 0) { int newColorless = colorless - reduceCount; adjustedCost.add(new GenericManaCost(newColorless)); } - reduced = true; + updated = true; } else { adjustedCost.add(manaCost); } } + + // for increasing spell cost effects + if (!updated && reduceCount < 0) { + adjustedCost.add(new GenericManaCost(-reduceCount)); + } + ability.getManaCostsToPay().clear(); ability.getManaCostsToPay().addAll(adjustedCost); } @@ -129,7 +197,7 @@ public class CardUtil { * Adjusts spell or ability cost to be paid by colored and generic mana. * * @param spellAbility - * @param mana costs to reduce + * @param manaCostsToReduce costs to reduce */ public static void adjustCost(SpellAbility spellAbility, ManaCosts manaCostsToReduce) { ManaCosts previousCost = spellAbility.getManaCostsToPay();