mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
Fixed Issue#79: Cost reduction does not work properly
This commit is contained in:
parent
3a4eae3bca
commit
ded2979dab
18 changed files with 160 additions and 45 deletions
|
@ -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<ArcaneMe
|
|||
|
||||
@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(((SpellAbility)abilityToModify).getSourceId());
|
||||
if ( sourceCard != null && (sourceCard.getCardType().contains(CardType.INSTANT) || sourceCard.getCardType().contains(CardType.SORCERY))) {
|
||||
return true;
|
||||
|
|
|
@ -37,7 +37,9 @@ import mage.abilities.common.AttacksTriggeredAbility;
|
|||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.effects.CostModificationEffectImpl;
|
||||
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
|
||||
import mage.abilities.keyword.FlashbackAbility;
|
||||
import mage.abilities.keyword.FlyingAbility;
|
||||
import mage.abilities.keyword.RetraceAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.counters.CounterType;
|
||||
|
@ -107,8 +109,8 @@ class HeraldOfWarCostReductionEffect extends CostModificationEffectImpl<HeraldOf
|
|||
|
||||
@Override
|
||||
public boolean applies(Ability abilityToModify, Ability source, Game game) {
|
||||
if (abilityToModify instanceof SpellAbility) {
|
||||
Card sourceCard = game.getCard(((SpellAbility) abilityToModify).getSourceId());
|
||||
if (abilityToModify instanceof SpellAbility || abilityToModify instanceof FlashbackAbility || abilityToModify instanceof RetraceAbility) {
|
||||
Card sourceCard = game.getCard(abilityToModify.getSourceId());
|
||||
if (sourceCard != null && abilityToModify.getControllerId().equals(source.getControllerId()) && (sourceCard.hasSubtype("Angel") || sourceCard.hasSubtype("Human"))) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
*/
|
||||
package mage.sets.betrayersofkamigawa;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.Constants;
|
||||
import mage.Constants.CardType;
|
||||
import mage.Constants.Rarity;
|
||||
|
@ -37,11 +36,15 @@ import mage.abilities.SpellAbility;
|
|||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.effects.CostModificationEffectImpl;
|
||||
import mage.abilities.keyword.BushidoAbility;
|
||||
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 java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
@ -96,8 +99,8 @@ public class KentaroTheSmilingCat extends CardImpl<KentaroTheSmilingCat> {
|
|||
|
||||
@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")) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<Rooftop
|
|||
|
||||
@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("Zombie")) {
|
||||
|
|
|
@ -32,6 +32,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 OmniscienceEffect extends CostModificationEffectImpl<OmniscienceEffect> {
|
|||
|
||||
@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) {
|
||||
|
|
|
@ -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<Defen
|
|||
|
||||
@Override
|
||||
public boolean applies(Ability abilityToModify, Ability source, Game game) {
|
||||
if (abilityToModify instanceof SpellAbility) {
|
||||
if (abilityToModify instanceof SpellAbility || abilityToModify instanceof FlashbackAbility || abilityToModify instanceof RetraceAbility) {
|
||||
if(!abilityToModify.getControllerId().equals(game.getActivePlayerId())) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
*/
|
||||
package mage.sets.planechase2012;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.Constants;
|
||||
import mage.Constants.CardType;
|
||||
import mage.Constants.Rarity;
|
||||
|
@ -37,13 +36,17 @@ 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.LifelinkAbility;
|
||||
import mage.abilities.keyword.RetraceAbility;
|
||||
import mage.abilities.keyword.TrampleAbility;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.game.Game;
|
||||
import mage.target.Target;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
|
@ -102,7 +105,7 @@ class ElderwoodScionCostReductionEffect extends CostModificationEffectImpl<Elder
|
|||
|
||||
@Override
|
||||
public boolean applies(Ability abilityToModify, Ability source, Game game) {
|
||||
if (abilityToModify instanceof SpellAbility) {
|
||||
if (abilityToModify instanceof SpellAbility || abilityToModify instanceof FlashbackAbility || abilityToModify instanceof RetraceAbility) {
|
||||
if (abilityToModify.getControllerId().equals(source.getControllerId())) {
|
||||
for (Target target :abilityToModify.getTargets()) {
|
||||
for (UUID targetUUID :target.getTargets()) {
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
*/
|
||||
package mage.sets.prophecy;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.Constants;
|
||||
import mage.Constants.CardType;
|
||||
import mage.Constants.Rarity;
|
||||
|
@ -40,12 +39,16 @@ import mage.abilities.common.SimpleStaticAbility;
|
|||
import mage.abilities.costs.AdjustingSourceCosts;
|
||||
import mage.abilities.effects.CostModificationEffectImpl;
|
||||
import mage.abilities.effects.common.continious.CanBlockAdditionalCreatureEffect;
|
||||
import mage.abilities.keyword.FlashbackAbility;
|
||||
import mage.abilities.keyword.FlyingAbility;
|
||||
import mage.abilities.keyword.RetraceAbility;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Plopman
|
||||
|
@ -138,7 +141,8 @@ class AdjustingCostsEffect extends CostModificationEffectImpl<AdjustingCostsEffe
|
|||
|
||||
@Override
|
||||
public boolean applies(Ability abilityToModify, Ability source, Game game) {
|
||||
if (abilityToModify instanceof SpellAbility && abilityToModify.getSourceId().equals(source.getSourceId())) {
|
||||
if ((abilityToModify instanceof SpellAbility || abilityToModify instanceof FlashbackAbility || abilityToModify instanceof RetraceAbility)
|
||||
&& abilityToModify.getSourceId().equals(source.getSourceId())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
*/
|
||||
package mage.sets.returntoravnica;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.Constants;
|
||||
import mage.Constants.CardType;
|
||||
import mage.Constants.Rarity;
|
||||
|
@ -38,7 +37,9 @@ import mage.abilities.common.SimpleStaticAbility;
|
|||
import mage.abilities.costs.CostImpl;
|
||||
import mage.abilities.dynamicvalue.common.OpponentsLostLifeCount;
|
||||
import mage.abilities.effects.CostModificationEffectImpl;
|
||||
import mage.abilities.keyword.FlashbackAbility;
|
||||
import mage.abilities.keyword.FlyingAbility;
|
||||
import mage.abilities.keyword.RetraceAbility;
|
||||
import mage.abilities.keyword.TrampleAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
|
@ -46,6 +47,8 @@ import mage.game.Game;
|
|||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
|
@ -138,12 +141,12 @@ class RakdosLordOfRiotsCostReductionEffect extends CostModificationEffectImpl<Ra
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source, Ability abilityToModify) {
|
||||
SpellAbility spellAbility = (SpellAbility) abilityToModify;
|
||||
Ability spellAbility = (SpellAbility) abilityToModify;
|
||||
if (spellAbility != null) {
|
||||
OpponentsLostLifeCount dynamicValue = new OpponentsLostLifeCount();
|
||||
int amount = dynamicValue.calculate(game, source);
|
||||
if (amount > 0) {
|
||||
CardUtil.adjustCost(spellAbility, amount);
|
||||
CardUtil.reduceCost(spellAbility, amount);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -152,8 +155,8 @@ class RakdosLordOfRiotsCostReductionEffect extends CostModificationEffectImpl<Ra
|
|||
|
||||
@Override
|
||||
public boolean applies(Ability abilityToModify, Ability source, Game game) {
|
||||
if (abilityToModify instanceof SpellAbility) {
|
||||
Card sourceCard = game.getCard(((SpellAbility) abilityToModify).getSourceId());
|
||||
if (abilityToModify instanceof SpellAbility || abilityToModify instanceof FlashbackAbility || abilityToModify instanceof RetraceAbility) {
|
||||
Card sourceCard = game.getCard(abilityToModify.getSourceId());
|
||||
if (sourceCard != null && abilityToModify.getControllerId().equals(source.getControllerId()) && (sourceCard.getCardType().contains(CardType.CREATURE))) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@ import mage.abilities.common.EntersBattlefieldTriggeredAbility;
|
|||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.effects.CostModificationEffectImpl;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.keyword.FlashbackAbility;
|
||||
import mage.abilities.keyword.RetraceAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.filter.FilterCard;
|
||||
|
@ -136,8 +138,8 @@ class SemblanceAnvilCostReductionEffect extends CostModificationEffectImpl<Sembl
|
|||
|
||||
@Override
|
||||
public boolean applies(Ability abilityToModify, Ability source, Game game) {
|
||||
if (abilityToModify instanceof SpellAbility) {
|
||||
Card sourceCard = game.getCard(((SpellAbility) abilityToModify).getSourceId());
|
||||
if (abilityToModify instanceof SpellAbility || abilityToModify instanceof FlashbackAbility || abilityToModify instanceof RetraceAbility) {
|
||||
Card sourceCard = game.getCard(abilityToModify.getSourceId());
|
||||
if (sourceCard != null && sourceCard.getOwnerId().equals(source.getControllerId())) {
|
||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||
if (permanent != null) {
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
*/
|
||||
package mage.sets.worldwake;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.Constants;
|
||||
import mage.Constants.CardType;
|
||||
import mage.Constants.Rarity;
|
||||
|
@ -37,10 +36,14 @@ 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.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.game.Game;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jeffwadsworth
|
||||
|
@ -89,7 +92,7 @@ class LodestoneGolemCostReductionEffect extends CostModificationEffectImpl<Lodes
|
|||
|
||||
@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.ARTIFACT)) {
|
||||
return true;
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
*/
|
||||
package mage.sets.worldwake;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.Constants;
|
||||
import mage.Constants.CardType;
|
||||
import mage.Constants.Duration;
|
||||
|
@ -43,6 +42,7 @@ import mage.abilities.effects.CostModificationEffectImpl;
|
|||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.ExileTargetEffect;
|
||||
import mage.abilities.keyword.FlashbackAbility;
|
||||
import mage.abilities.keyword.RetraceAbility;
|
||||
import mage.abilities.keyword.TrampleAbility;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
|
@ -52,6 +52,8 @@ import mage.game.permanent.token.Token;
|
|||
import mage.target.targetpointer.FixedTarget;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jeffwadsworth
|
||||
|
@ -104,13 +106,13 @@ class StoneIdolTrapCostReductionEffect extends CostModificationEffectImpl<StoneI
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source, Ability abilityToModify) {
|
||||
int reductionAmount = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(),game);
|
||||
CardUtil.adjustCost(abilityToModify, reductionAmount);
|
||||
CardUtil.reduceCost(abilityToModify, reductionAmount);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applies(Ability abilityToModify, Ability source, Game game) {
|
||||
if ((abilityToModify instanceof SpellAbility || abilityToModify instanceof FlashbackAbility)
|
||||
if ((abilityToModify instanceof SpellAbility || abilityToModify instanceof FlashbackAbility || abilityToModify instanceof RetraceAbility)
|
||||
&& abilityToModify.getSourceId().equals(source.getSourceId())) {
|
||||
return game.getCard(abilityToModify.getSourceId()) != null;
|
||||
}
|
||||
|
|
|
@ -266,9 +266,10 @@ public abstract class AbilityImpl<T extends AbilityImpl<T>> 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)) {
|
||||
|
|
|
@ -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<SpellAbility> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public class SpellsCostReductionEffect extends CostModificationEffectImpl<Spells
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source, Ability abilityToModify) {
|
||||
CardUtil.adjustCost(abilityToModify, this.amount);
|
||||
CardUtil.reduceCost(abilityToModify, this.amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,9 +46,10 @@ import mage.target.Target;
|
|||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public class FlashbackAbility extends ActivatedAbilityImpl<FlashbackAbility> {
|
||||
public class FlashbackAbility extends /*SpellAbility*/ ActivatedAbilityImpl<FlashbackAbility> {
|
||||
|
||||
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;
|
||||
|
|
|
@ -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<ManaCost> adjustedCost = new ManaCostsImpl<ManaCost>();
|
||||
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<ManaCost> previousCost = ability.getManaCostsToPay();
|
||||
ManaCosts<ManaCost> adjustedCost = new ManaCostsImpl<ManaCost>();
|
||||
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<ManaCost> manaCostsToReduce) {
|
||||
ManaCosts<ManaCost> previousCost = spellAbility.getManaCostsToPay();
|
||||
|
|
Loading…
Reference in a new issue