* Fixes to handling of AlternateCostSourceAbility for multiple costs (not finished yet).

This commit is contained in:
LevelX2 2014-02-21 15:04:09 +01:00
parent 8549f72010
commit 786fc03044
3 changed files with 26 additions and 21 deletions

View file

@ -32,9 +32,11 @@ import mage.ObjectColor;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.costs.AlternativeCostImpl;
import mage.abilities.costs.AlternativeCostSourceAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.CostsImpl;
import mage.abilities.costs.common.ExileFromHandCost;
import mage.abilities.costs.common.GainLifeOpponentCost;
import mage.abilities.costs.common.PayLifeCost;
import mage.abilities.effects.OneShotEffect;
import mage.cards.CardImpl;
@ -57,21 +59,21 @@ import mage.target.common.TargetCreaturePermanentAmount;
* @author Plopman
*/
public class Contagion extends CardImpl<Contagion> {
public Contagion(UUID ownerId) {
super(ownerId, 4, "Contagion", Rarity.UNCOMMON, new CardType[]{CardType.INSTANT}, "{3}{B}{B}");
this.expansionSetCode = "ALL";
this.color.setBlack(true);
// You may pay 1 life and exile a black card from your hand rather than pay Contagion's mana cost.
FilterOwnedCard filter = new FilterOwnedCard("black card from your hand");
filter.add(new ColorPredicate(ObjectColor.BLACK));
filter.add(Predicates.not(new CardIdPredicate(this.getId()))); // the exile cost can never be paid with the card itself
CostsImpl<Cost> costs = new CostsImpl<Cost>();
costs.add(new PayLifeCost(1));
costs.add(new ExileFromHandCost(new TargetCardInHand(filter)));
this.getSpellAbility().addAlternativeCost(new AlternativeCostImpl("Pay 1 life and exile a black card from your hand rather than pay {source}'s mana cost", costs));
// You may pay 1 life and exile a black card from your hand rather than pay Contagion's mana cost.
AlternativeCostSourceAbility ability = new AlternativeCostSourceAbility(new PayLifeCost(1));
ability.addCost(new ExileFromHandCost(new TargetCardInHand(filter)));
this.addAbility(ability);
// Distribute two -2/-1 counters among one or two target creatures.
this.getSpellAbility().addTarget(new TargetCreaturePermanentAmount(2));

View file

@ -32,6 +32,7 @@ import mage.constants.CardType;
import mage.constants.Rarity;
import mage.ObjectColor;
import mage.abilities.costs.AlternativeCostImpl;
import mage.abilities.costs.AlternativeCostSourceAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.CostsImpl;
import mage.abilities.costs.common.ExileFromHandCost;
@ -61,11 +62,11 @@ public class ForceOfWill extends CardImpl<ForceOfWill> {
FilterOwnedCard filter = new FilterOwnedCard("blue card from your hand");
filter.add(new ColorPredicate(ObjectColor.BLUE));
filter.add(Predicates.not(new CardIdPredicate(this.getId()))); // the exile cost can never be paid with the card itself
CostsImpl<Cost> costs = new CostsImpl<Cost>();
costs.add(new PayLifeCost(1));
costs.add(new ExileFromHandCost(new TargetCardInHand(filter)));
this.getSpellAbility().addAlternativeCost(new AlternativeCostImpl("Pay 1 life and exile a blue card from your hand rather than pay Force of Will's mana cost", costs));
AlternativeCostSourceAbility ability = new AlternativeCostSourceAbility(new PayLifeCost(1));
ability.addCost(new ExileFromHandCost(new TargetCardInHand(filter)));
this.addAbility(ability);
// Counter target spell.
this.getSpellAbility().addEffect(new CounterTargetEffect());
this.getSpellAbility().addTarget(new TargetSpell());

View file

@ -47,7 +47,7 @@ import mage.players.Player;
*/
public class AlternativeCostSourceAbility extends StaticAbility<AlternativeCostSourceAbility> implements AlternativeSourceCosts {
protected List<AlternativeCost2> alternateCosts = new LinkedList<AlternativeCost2>();
protected List<AlternativeCost2> alternateCosts = new LinkedList<>();
protected Condition condition;
protected String rule;
@ -66,6 +66,11 @@ public class AlternativeCostSourceAbility extends StaticAbility<AlternativeCostS
this.condition = condition;
this.rule = rule;
}
@Override
public void addCost(Cost cost) {
this.convertToAlternativeCostAndAdd(cost);
}
private void convertToAlternativeCostAndAdd(Cost cost) {
AlternativeCost2 alternativeCost = new AlternativeCost2Impl(null, null, cost);
@ -97,12 +102,11 @@ public class AlternativeCostSourceAbility extends StaticAbility<AlternativeCostS
if (ability instanceof SpellAbility) {
Player player = game.getPlayer(controllerId);
if (player != null) {
for (AlternativeCost2 alternateCost: alternateCosts) {
if (alternateCost.canPay(sourceId, controllerId, game) &&
player.chooseUse(Outcome.Benefit, new StringBuilder("Pay alternative costs: ").append(alternateCost.getText()).append(" ?").toString(), game)) {
if (player.chooseUse(Outcome.Detriment, "Pay alternative costs?", game)) {
ability.getManaCostsToPay().clear();
ability.getCosts().clear();
for (AlternativeCost2 alternateCost: alternateCosts) {
alternateCost.activate();
ability.getManaCostsToPay().clear();
ability.getCosts().clear();
for (Iterator it = ((Costs) alternateCost).iterator(); it.hasNext();) {
Cost cost = (Cost) it.next();
if (cost instanceof ManaCostsImpl) {
@ -112,7 +116,7 @@ public class AlternativeCostSourceAbility extends StaticAbility<AlternativeCostS
}
}
}
}
}
}
}
return isActivated();
@ -137,9 +141,7 @@ public class AlternativeCostSourceAbility extends StaticAbility<AlternativeCostS
public String getRule() {
if (rule != null) {
return rule;
}
// You may exile a black card from your hand rather than pay Unmask's mana cost.
}
StringBuilder sb = new StringBuilder();
if (condition != null) {
sb.append(condition.toString());