Fix Goldberry, River-Daughter

If the Goldberry and the target permanent had different counts of counters, they would not be filtered out from her first ability's effect. Fix this by using the Keys (counter name strings) rather than the Values (Counters).
This commit is contained in:
Grath 2024-01-20 02:17:35 -05:00
parent 8cef411c70
commit bbe452352f
2 changed files with 7 additions and 6 deletions

View file

@ -93,15 +93,15 @@ class GoldberryRiverDaughterFromEffect extends OneShotEffect {
} }
// Create a set of all of the unique counter types on the target permanent that aren't on Goldberry // Create a set of all of the unique counter types on the target permanent that aren't on Goldberry
Set<Counter> fromCounters = new HashSet<Counter>(fromPermanent.getCounters(game).values()); Set<String> fromCounters = new HashSet<>(fromPermanent.getCounters(game).keySet());
fromCounters.removeAll(toPermanent.getCounters(game).values()); fromCounters.removeAll(toPermanent.getCounters(game).keySet());
if (fromCounters.size() == 0) { if (fromCounters.size() == 0) {
return false; return false;
} }
for (Counter counter : fromCounters) { for (String counter : fromCounters) {
fromPermanent.removeCounters(counter.getName(), 1, source, game); fromPermanent.removeCounters(counter, 1, source, game);
toPermanent.addCounters(CounterType.findByName(counter.getName()).createInstance(1), toPermanent.addCounters(CounterType.findByName(counter).createInstance(1),
source.getControllerId(), source, game); source.getControllerId(), source, game);
} }
return true; return true;

View file

@ -54,6 +54,7 @@ public class GoldberryRiverDaughterTest extends CardTestPlayerBase {
@Test @Test
// Author: alexander-novo // Author: alexander-novo
// Unhappy path - Try to remove some counters from something when some of those counters are already on Goldberry // Unhappy path - Try to remove some counters from something when some of those counters are already on Goldberry
// (but now with different counts, to cover that edge case.)
public void testCounterAlreadyOnGoldberry() { public void testCounterAlreadyOnGoldberry() {
CounterType counter = CounterType.ACORN; CounterType counter = CounterType.ACORN;
String island = "Island"; String island = "Island";
@ -61,7 +62,7 @@ public class GoldberryRiverDaughterTest extends CardTestPlayerBase {
addCard(Zone.BATTLEFIELD, playerA, goldberry, 1); addCard(Zone.BATTLEFIELD, playerA, goldberry, 1);
addCard(Zone.BATTLEFIELD, playerA, island, 1); addCard(Zone.BATTLEFIELD, playerA, island, 1);
addCounters(1, PhaseStep.PRECOMBAT_MAIN, playerA, island, counter, 1); addCounters(1, PhaseStep.PRECOMBAT_MAIN, playerA, island, counter, 2);
addCounters(1, PhaseStep.PRECOMBAT_MAIN, playerA, goldberry, counter, 1); addCounters(1, PhaseStep.PRECOMBAT_MAIN, playerA, goldberry, counter, 1);
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, ability1, island); activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, ability1, island);