Merge branch 'pumpCritFix' into 'master'

PumpEffect: fix keywords using CardManaCost

See merge request core-developers/forge!3342
This commit is contained in:
Hans Mackowiak
2020-11-06 13:02:34 +00:00

View File

@@ -1,5 +1,6 @@
package forge.game.ability.effects; package forge.game.ability.effects;
import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import forge.GameCommand; import forge.GameCommand;
@@ -304,13 +305,14 @@ public class PumpEffect extends SpellAbilityEffect {
} }
if (sa.hasParam("DefinedLandwalk")) { if (sa.hasParam("DefinedLandwalk")) {
final String landtype = sa.getParam("DefinedLandwalk"); final String landtype = sa.getParam("DefinedLandwalk");
final Card c = AbilityUtils.getDefinedCards(host, landtype, sa).get(0); for (final Card c : AbilityUtils.getDefinedCards(host, landtype, sa)) {
for (String type : c.getType()) { for (String type : c.getType()) {
if (CardType.isALandType(type)) { if (CardType.isALandType(type)) {
keywords.add(type + "walk"); keywords.add(type + "walk");
} }
} }
} }
}
if (sa.hasParam("RandomKeyword")) { if (sa.hasParam("RandomKeyword")) {
final String num = sa.hasParam("RandomKWNum") ? sa.getParam("RandomKWNum") : "1"; final String num = sa.hasParam("RandomKWNum") ? sa.getParam("RandomKWNum") : "1";
final int numkw = AbilityUtils.calculateAmount(host, num, sa); final int numkw = AbilityUtils.calculateAmount(host, num, sa);
@@ -394,7 +396,7 @@ public class PumpEffect extends SpellAbilityEffect {
final Card tgtC = tgtCards.get(j); final Card tgtC = tgtCards.get(j);
// only pump things in PumpZone // only pump things in PumpZone
if (!game.getCardsIn(pumpZone).contains(tgtC)) { if (!tgtC.isInZone(pumpZone)) {
continue; continue;
} }
@@ -404,9 +406,10 @@ public class PumpEffect extends SpellAbilityEffect {
} }
// substitute specific tgtC mana cost for keyword placeholder CardManaCost // substitute specific tgtC mana cost for keyword placeholder CardManaCost
if (sa.getParam("KW").contains("CardManaCost")) { List<String> affectedKeywords = Lists.newArrayList(keywords);
String cost = tgtC.getManaCost().getShortString();
Iterables.removeIf(keywords, new Predicate<String>() { if (!affectedKeywords.isEmpty()) {
Iterables.removeIf(affectedKeywords, new Predicate<String>() {
@Override @Override
public boolean apply(String input) { public boolean apply(String input) {
if (input.contains("CardManaCost")) { if (input.contains("CardManaCost")) {
@@ -417,12 +420,23 @@ public class PumpEffect extends SpellAbilityEffect {
return false; return false;
} }
}); });
for (int i = 0; i < keywords.size(); i++) {
keywords.set(i, TextUtil.fastReplace(keywords.get(i), "CardManaCost", cost)); affectedKeywords = Lists.transform(affectedKeywords, new Function<String, String>() {
@Override
public String apply(String input) {
if (input.contains("CardManaCost")) {
input = input.replace("CardManaCost", tgtC.getManaCost().getShortString());
} else if (input.contains("ConvertedManaCost")) {
final String costcmc = Integer.toString(tgtC.getCMC());
input = input.replace("ConvertedManaCost", costcmc);
} }
return input;
}
});
} }
applyPump(sa, tgtC, a, d, keywords, timestamp); applyPump(sa, tgtC, a, d, affectedKeywords, timestamp);
} }
if (sa.hasParam("AtEOT") && !tgtCards.isEmpty()) { if (sa.hasParam("AtEOT") && !tgtCards.isEmpty()) {