mirror of
https://github.com/correl/mage.git
synced 2025-01-13 11:01:58 +00:00
* Fixes to handling of AlternateCostSourceAbility for multiple costs (not finished yet).
This commit is contained in:
parent
8549f72010
commit
786fc03044
3 changed files with 26 additions and 21 deletions
|
@ -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;
|
||||
|
@ -64,14 +66,14 @@ public class Contagion extends CardImpl<Contagion> {
|
|||
|
||||
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));
|
||||
|
|
|
@ -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,10 +62,10 @@ 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());
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -67,6 +67,11 @@ public class AlternativeCostSourceAbility extends StaticAbility<AlternativeCostS
|
|||
this.rule = rule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCost(Cost cost) {
|
||||
this.convertToAlternativeCostAndAdd(cost);
|
||||
}
|
||||
|
||||
private void convertToAlternativeCostAndAdd(Cost cost) {
|
||||
AlternativeCost2 alternativeCost = new AlternativeCost2Impl(null, null, cost);
|
||||
this.alternateCosts.add(alternativeCost);
|
||||
|
@ -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)) {
|
||||
alternateCost.activate();
|
||||
if (player.chooseUse(Outcome.Detriment, "Pay alternative costs?", game)) {
|
||||
ability.getManaCostsToPay().clear();
|
||||
ability.getCosts().clear();
|
||||
for (AlternativeCost2 alternateCost: alternateCosts) {
|
||||
alternateCost.activate();
|
||||
for (Iterator it = ((Costs) alternateCost).iterator(); it.hasNext();) {
|
||||
Cost cost = (Cost) it.next();
|
||||
if (cost instanceof ManaCostsImpl) {
|
||||
|
@ -138,8 +142,6 @@ public class AlternativeCostSourceAbility extends StaticAbility<AlternativeCostS
|
|||
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());
|
||||
|
|
Loading…
Reference in a new issue