From 3c0bd8a5913704006260e44368593d9b98b607da Mon Sep 17 00:00:00 2001 From: Hans Mackowiak Date: Fri, 6 Nov 2020 11:46:20 +0100 Subject: [PATCH] PumpEffect: fix keywords using CardManaCost --- .../game/ability/effects/PumpEffect.java | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/forge-game/src/main/java/forge/game/ability/effects/PumpEffect.java b/forge-game/src/main/java/forge/game/ability/effects/PumpEffect.java index 310ee8a4b75..4db199e967e 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/PumpEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/PumpEffect.java @@ -1,5 +1,6 @@ package forge.game.ability.effects; +import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import forge.GameCommand; @@ -304,10 +305,11 @@ public class PumpEffect extends SpellAbilityEffect { } if (sa.hasParam("DefinedLandwalk")) { final String landtype = sa.getParam("DefinedLandwalk"); - final Card c = AbilityUtils.getDefinedCards(host, landtype, sa).get(0); - for (String type : c.getType()) { - if (CardType.isALandType(type)) { - keywords.add(type + "walk"); + for (final Card c : AbilityUtils.getDefinedCards(host, landtype, sa)) { + for (String type : c.getType()) { + if (CardType.isALandType(type)) { + keywords.add(type + "walk"); + } } } } @@ -394,7 +396,7 @@ public class PumpEffect extends SpellAbilityEffect { final Card tgtC = tgtCards.get(j); // only pump things in PumpZone - if (!game.getCardsIn(pumpZone).contains(tgtC)) { + if (!tgtC.isInZone(pumpZone)) { continue; } @@ -404,9 +406,10 @@ public class PumpEffect extends SpellAbilityEffect { } // substitute specific tgtC mana cost for keyword placeholder CardManaCost - if (sa.getParam("KW").contains("CardManaCost")) { - String cost = tgtC.getManaCost().getShortString(); - Iterables.removeIf(keywords, new Predicate() { + List affectedKeywords = Lists.newArrayList(keywords); + + if (!affectedKeywords.isEmpty()) { + Iterables.removeIf(affectedKeywords, new Predicate() { @Override public boolean apply(String input) { if (input.contains("CardManaCost")) { @@ -417,12 +420,23 @@ public class PumpEffect extends SpellAbilityEffect { 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() { + + @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()) {