improve handling for multiple defilers of same color

This commit is contained in:
Northmoc
2022-10-30 10:02:14 -04:00
parent a264344485
commit b17c106d10
5 changed files with 45 additions and 39 deletions

View File

@@ -936,6 +936,7 @@ public final class GameActionUtil {
ability.setHostCard(oldCard); ability.setHostCard(oldCard);
ability.setXManaCostPaid(null); ability.setXManaCostPaid(null);
ability.setSpendPhyrexianMana(false); ability.setSpendPhyrexianMana(false);
ability.clearPipsToReduce();
ability.setPaidLife(0); ability.setPaidLife(0);
if (ability.hasParam("Announce")) { if (ability.hasParam("Announce")) {
for (final String aVar : ability.getParam("Announce").split(",")) { for (final String aVar : ability.getParam("Announce").split(",")) {

View File

@@ -4,7 +4,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import forge.game.spellability.OptionalCost;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Strings; import com.google.common.base.Strings;
@@ -209,20 +208,10 @@ public class CostAdjustment {
// need to reduce generic extra because of 2 hybrid mana // need to reduce generic extra because of 2 hybrid mana
cost.decreaseGenericMana(sumGeneric); cost.decreaseGenericMana(sumGeneric);
if (sa.isSpell() && sa.isOptionalCostPaid(OptionalCost.ReduceW)) { if (sa.isSpell() && !sa.getPipsToReduce().isEmpty()) {
cost.decreaseShard(ManaCostShard.parseNonGeneric("W"), 1); for (String pip : sa.getPipsToReduce()) {
} cost.decreaseShard(ManaCostShard.parseNonGeneric(pip), 1);
if (sa.isSpell() && sa.isOptionalCostPaid(OptionalCost.ReduceU)) { }
cost.decreaseShard(ManaCostShard.parseNonGeneric("U"), 1);
}
if (sa.isSpell() && sa.isOptionalCostPaid(OptionalCost.ReduceB)) {
cost.decreaseShard(ManaCostShard.parseNonGeneric("B"), 1);
}
if (sa.isSpell() && sa.isOptionalCostPaid(OptionalCost.ReduceR)) {
cost.decreaseShard(ManaCostShard.parseNonGeneric("R"), 1);
}
if (sa.isSpell() && sa.isOptionalCostPaid(OptionalCost.ReduceG)) {
cost.decreaseShard(ManaCostShard.parseNonGeneric("G"), 1);
} }
if (sa.isSpell() && sa.isOffering()) { // cost reduction from offerings if (sa.isSpell() && sa.isOffering()) { // cost reduction from offerings

View File

@@ -5,25 +5,27 @@ package forge.game.spellability;
* *
*/ */
public enum OptionalCost { public enum OptionalCost {
Buyback("Buyback"), Buyback("Buyback", ""),
Entwine("Entwine"), Entwine("Entwine", ""),
Kicker1("Kicker"), Kicker1("Kicker", ""),
Kicker2("Kicker"), Kicker2("Kicker", ""),
Retrace("Retrace"), Retrace("Retrace", ""),
Jumpstart("Jump-start"), Jumpstart("Jump-start", ""),
ReduceW("(to reduce white mana)"), ReduceW("(to reduce white mana)", "W"),
ReduceU("(to reduce blue mana)"), ReduceU("(to reduce blue mana)", "U"),
ReduceB("(to reduce black mana)"), ReduceB("(to reduce black mana)", "B"),
ReduceR("(to reduce red mana)"), ReduceR("(to reduce red mana)", "R"),
ReduceG("(to reduce green mana)"), ReduceG("(to reduce green mana)", "G"),
AltCost(""), AltCost("", ""),
Flash("Flash"), // used for Pay Extra for Flash Flash("Flash", ""), // used for Pay Extra for Flash
Generic("Generic"); // used by "Dragon Presence" and pseudo-kicker cards Generic("Generic", ""); // used by "Dragon Presence" and pseudo-kicker cards
private String name; private String name;
private String pip;
OptionalCost(String name) { OptionalCost(String name, String pip) {
this.name = name; this.name = name;
this.pip = pip;
} }
/** /**
@@ -32,4 +34,11 @@ public enum OptionalCost {
public String getName() { public String getName() {
return name; return name;
} }
/**
* @return the pip
*/
public String getPip() {
return pip;
}
} }

View File

@@ -51,12 +51,13 @@ public class OptionalCostValue implements Serializable {
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (type != OptionalCost.Generic && !type.getName().startsWith("(to reduce")) { boolean isTag = type.getName().startsWith("(");
if (type != OptionalCost.Generic && !isTag) {
sb.append(type.getName()); sb.append(type.getName());
sb.append(" "); sb.append(" ");
} }
sb.append(cost.toSimpleString()); sb.append(cost.toSimpleString());
sb.append(type.getName().startsWith("(to reduce") ? " " + type.getName() : ""); sb.append(isTag ? " " + type.getName() : "");
return sb.toString(); return sb.toString();
} }
} }

View File

@@ -17,13 +17,7 @@
*/ */
package forge.game.spellability; package forge.game.spellability;
import java.util.Arrays; import java.util.*;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -159,6 +153,8 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
private EnumMap<AbilityKey, Object> replacingObjects = AbilityKey.newMap(); private EnumMap<AbilityKey, Object> replacingObjects = AbilityKey.newMap();
private final List<String> pipsToReduce = new ArrayList<>();
private List<AbilitySub> chosenList = null; private List<AbilitySub> chosenList = null;
private CardCollection tappedForConvoke = new CardCollection(); private CardCollection tappedForConvoke = new CardCollection();
private Card sacrificedAsOffering; private Card sacrificedAsOffering;
@@ -716,6 +712,9 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
// Thus, to protect the original's set from changes, we make a copy right here. // Thus, to protect the original's set from changes, we make a copy right here.
optionalCosts = EnumSet.copyOf(optionalCosts); optionalCosts = EnumSet.copyOf(optionalCosts);
optionalCosts.add(cost); optionalCosts.add(cost);
if (!cost.getPip().equals("")) {
pipsToReduce.add(cost.getPip());
}
} }
public boolean isBuyBackAbility() { public boolean isBuyBackAbility() {
@@ -1484,6 +1483,13 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
return isAlternativeCost(AlternativeCost.Spectacle); return isAlternativeCost(AlternativeCost.Spectacle);
} }
public List<String> getPipsToReduce() {
return pipsToReduce;
}
public final void clearPipsToReduce() {
pipsToReduce.clear();
}
public CardCollection getTappedForConvoke() { public CardCollection getTappedForConvoke() {
return tappedForConvoke; return tappedForConvoke;
} }