Fix SimAI not respecting Pithing Needle effects.

Before this change, Sim AI would just choose effects that should be blocked by Pithing Needle (and similar cards). Adds a test.
This commit is contained in:
asvitkine
2023-10-04 15:15:10 -04:00
parent 23ec143892
commit 685cd2583f
3 changed files with 41 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ import java.util.List;
import forge.item.PaperCard;
import forge.model.FModel;
import java.util.function.Predicate;
import org.testng.AssertJUnit;
import org.testng.annotations.Test;
@@ -860,4 +861,37 @@ public class SpellAbilityPickerSimulationTest extends SimulationTest {
AssertJUnit.assertTrue(targets.toString().contains("Forest Bear"));
AssertJUnit.assertTrue(targets.toString().contains("Flying Men"));
}
@Test
public void testPithingNeedlePreventsAbilitiesFromBeingChosen() {
Game game = initAndCreateGame();
Player p = game.getPlayers().get(1);
Player opponent = game.getPlayers().get(0);
opponent.setLife(1, null);
Card goblinBombardment = addCard("Goblin Bombardment", p);
addCard("Flying Men", p);
game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p);
final SpellAbilityPicker picker = new SpellAbilityPicker(game, p);
Runnable assertPickIsGoblinBombardmenTargetingOpponent = () -> {
game.getAction().checkStateEffects(true);
SpellAbility sa = picker.chooseSpellAbilityToPlay(null);
AssertJUnit.assertNotNull(sa);
AssertJUnit.assertEquals(goblinBombardment, sa.getHostCard());
MultiTargetSelector.Targets targets = picker.getPlan().getSelectedDecision().targets;
AssertJUnit.assertEquals(1, targets.size());
AssertJUnit.assertTrue(targets.toString().contains(opponent.getName()));
};
assertPickIsGoblinBombardmenTargetingOpponent.run();
// If we have a Pithing Needle, but it's naming something else, that's still fine.
Card pithingNeedle = addCard("Pithing Needle", opponent);
pithingNeedle.setNamedCard("Flooded Strand");
assertPickIsGoblinBombardmenTargetingOpponent.run();
// But if it's naming Gobling Bombardment, then we can't choose that SA.
pithingNeedle.setNamedCard("Goblin Bombardment");
game.getAction().checkStateEffects(true);
AssertJUnit.assertNull(picker.chooseSpellAbilityToPlay(null));
}
}