Fixed GoadAllEffect from affecting creatures that ETB after it resolves. Closes #9227.

This commit is contained in:
Alex Vasile 2022-07-17 19:41:25 -04:00
parent 8c22db650a
commit 9715021a35
3 changed files with 71 additions and 1 deletions

View file

@ -44,7 +44,7 @@ public final class MockingDoppelganger extends CardImpl {
@Override @Override
public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) { public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
blueprint.getAbilities().add(new SimpleStaticAbility(new GoadAllEffect( blueprint.getAbilities().add(new SimpleStaticAbility(new GoadAllEffect(
Duration.WhileOnBattlefield, filter Duration.WhileOnBattlefield, filter, false
).setText("other creatures with the same name as this creature are goaded"))); ).setText("other creatures with the same name as this creature are goaded")));
return true; return true;
} }

View file

@ -10,6 +10,7 @@ import mage.game.GameException;
import mage.game.mulligan.MulliganType; import mage.game.mulligan.MulliganType;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.util.functions.Function;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.mage.test.player.TestPlayer; import org.mage.test.player.TestPlayer;
@ -62,6 +63,34 @@ public class GoadTest extends CardTestMultiPlayerBase {
); );
} }
/**
* Checks whether the given attacker is NOT goaded by the provided player(s).
*
* @param attacker the name of the attacker
* @param players the player(s) that the attacker is supposed to be goaded by.
*/
private void assertNotGoaded(String attacker, TestPlayer... players) {
Assert.assertTrue("At least one player should be provided", players.length > 0);
Permanent permanent = getPermanent(attacker);
Assert.assertNotEquals(
"Creature should be goaded by "
+ Arrays
.stream(players)
.map(Player::getName)
.reduce((a, b) -> a + ", " + b).orElse(""),
permanent.getGoadingPlayers(),
Arrays.stream(players)
.map(TestPlayer::getId)
.collect(Collectors.toSet())
);
}
/**
* Checks whether the given attacker is goaded by the provided player(s).
*
* @param attacker the name of the attacker
* @param players the player(s) that the attacker is supposed to be goaded by.
*/
private void assertGoaded(String attacker, TestPlayer... players) { private void assertGoaded(String attacker, TestPlayer... players) {
Assert.assertTrue("At least one player should be provided", players.length > 0); Assert.assertTrue("At least one player should be provided", players.length > 0);
Permanent permanent = getPermanent(attacker); Permanent permanent = getPermanent(attacker);
@ -194,4 +223,40 @@ public class GoadTest extends CardTestMultiPlayerBase {
assertAttacking("Berserkers of Blood Ridge", playerB, playerC, playerD); assertAttacking("Berserkers of Blood Ridge", playerB, playerC, playerD);
} }
/**
* Reported bug: https://github.com/magefree/mage/issues/9227
* Geode Rager (and other goad all effects) goad creatures that enter the battlefield after the effect resolved.
*
* Ruling:
* Creatures that enter the battlefield or come under the target players control after Geode Ragers ability has resolved wont be goaded.
* (2020-09-25)
*/
@Test
public void goadAllCorrectAffect() {
addCard(Zone.BATTLEFIELD, playerA, "Geode Rager");
addCard(Zone.HAND, playerA, "Swamp");
addCard(Zone.BATTLEFIELD, playerD, "Goblin Balloon Brigade");
addCard(Zone.BATTLEFIELD, playerD, "Mountain");
addCard(Zone.HAND, playerD, "Goblin Champion");
setStrictChooseMode(true);
playLand(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Swamp");
addTarget(playerA, playerD); // Goad all of playerD's creatures
castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerD, "Goblin Champion");
addTarget(playerD, playerC); // Goblin Balloon Brigade attack player C
// Should not have to specify a target for Goblin Champion since they aren't goaded
setStopAt(2, PhaseStep.DECLARE_BLOCKERS);
execute();
assertAllCommandsUsed();
assertGoaded("Goblin Balloon Brigade", playerA);
assertNotGoaded("Goblin Champion", playerA);
}
} }

View file

@ -24,8 +24,13 @@ public class GoadAllEffect extends ContinuousEffectImpl {
} }
public GoadAllEffect(Duration duration, FilterPermanent filter) { public GoadAllEffect(Duration duration, FilterPermanent filter) {
this(duration, filter, true);
}
public GoadAllEffect(Duration duration, FilterPermanent filter, boolean affectedObjectsSet) {
super(duration, Layer.RulesEffects, SubLayer.NA, Outcome.Detriment); super(duration, Layer.RulesEffects, SubLayer.NA, Outcome.Detriment);
this.filter = filter; this.filter = filter;
this.affectedObjectsSet = affectedObjectsSet;
} }
private GoadAllEffect(final GoadAllEffect effect) { private GoadAllEffect(final GoadAllEffect effect) {