From 9d54aee3ba31d445866a172bd22a9e76349e2a65 Mon Sep 17 00:00:00 2001 From: Alex Vasile <48962821+Alex-Vasile@users.noreply.github.com> Date: Thu, 25 Aug 2022 15:54:10 -0400 Subject: [PATCH] [CLB] Fix Myrkul's Edict not sacrificing creatures on 1-9. For #9381. --- Mage.Sets/src/mage/cards/m/MyrkulsEdict.java | 23 +++-- .../cards/single/clb/MyrkulsEdictTest.java | 86 +++++++++++++++++++ 2 files changed, 100 insertions(+), 9 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/single/clb/MyrkulsEdictTest.java diff --git a/Mage.Sets/src/mage/cards/m/MyrkulsEdict.java b/Mage.Sets/src/mage/cards/m/MyrkulsEdict.java index 697282d387..afdf532f64 100644 --- a/Mage.Sets/src/mage/cards/m/MyrkulsEdict.java +++ b/Mage.Sets/src/mage/cards/m/MyrkulsEdict.java @@ -1,6 +1,7 @@ package mage.cards.m; import mage.abilities.Ability; +import mage.abilities.effects.Effect; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.RollDieWithResultTableEffect; import mage.abilities.effects.common.SacrificeEffect; @@ -16,6 +17,7 @@ import mage.filter.predicate.permanent.GreatestPowerControlledPredicate; import mage.game.Game; import mage.players.Player; import mage.target.common.TargetOpponent; +import mage.target.targetpointer.FixedTarget; import java.util.UUID; @@ -78,16 +80,19 @@ class MyrkulsEdictEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); - if (player == null) { + TargetOpponent target = new TargetOpponent(true); + if (!target.choose(outcome, source.getControllerId(), source.getId(), source, game)) { return false; } - TargetOpponent target = new TargetOpponent(); - target.setNotTarget(true); - player.choose(outcome, target, source, game); - return game.getPlayer(target.getFirstTarget()) != null - && new SacrificeEffect( - StaticFilters.FILTER_PERMANENT_CREATURE, 1, "" - ).apply(game, source); + + Player opponent = game.getPlayer(target.getFirstTarget()); + if (opponent == null) { + return false; + } + + Effect sacrificeEffect = new SacrificeEffect(StaticFilters.FILTER_PERMANENT_CREATURE, 1, ""); + sacrificeEffect.setTargetPointer(new FixedTarget(opponent.getId())); + + return sacrificeEffect.apply(game, source); } } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/clb/MyrkulsEdictTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/clb/MyrkulsEdictTest.java new file mode 100644 index 0000000000..a20c04add2 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/clb/MyrkulsEdictTest.java @@ -0,0 +1,86 @@ +package org.mage.test.cards.single.clb; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Ignore; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * {@link mage.cards.m.MyrkulsEdict Myrkul's Edict} + * Sorcery + * {1}{B} + * + * Roll a d20. + * 1—9 | Choose an opponent. That player sacrifices a creature. + * 10—19 | Each opponent sacrifices a creature. + * 20 | Each opponent sacrifices a creature with the greatest power among creatures that player controls. + * + * @author Alex-Vasile + */ +public class MyrkulsEdictTest extends CardTestPlayerBase { + private static final String myrkulsEdict = "Myrkul's Edict"; + + /** + * Reported bug: https://github.com/magefree/mage/issues/9381 + * AI doesn't sacrifice a creature on a roll of 1-9 + */ + @Ignore + @Test + public void opponentSacrificesLevel1() { + addCard(Zone.HAND, playerA, myrkulsEdict); + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2); + + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion"); + + setStrictChooseMode(true); + + setDieRollResult(playerA, 1); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, myrkulsEdict); + addTarget(playerA, playerB); + addTarget(playerB, "Silvercoat Lion"); + + execute(); + + assertPermanentCount(playerB, 0); + } + + @Test + public void opponentSacrificesLevel2() { + addCard(Zone.HAND, playerA, myrkulsEdict); + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2); + + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion"); + + setStrictChooseMode(true); + + setDieRollResult(playerA, 11); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, myrkulsEdict); + addTarget(playerB, "Silvercoat Lion"); + + execute(); + + assertPermanentCount(playerB, 0); + } + + + @Test + public void opponentSacrificesLevel3() { + addCard(Zone.HAND, playerA, myrkulsEdict); + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2); + + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion"); + addCard(Zone.BATTLEFIELD, playerB, "Aesi, Tyrant of Gyre Strait"); // 5/5 + + setStrictChooseMode(true); + + setDieRollResult(playerA, 20); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, myrkulsEdict); + addTarget(playerB, "Aesi, Tyrant of Gyre Strait"); + + execute(); + + assertPermanentCount(playerB, "Silvercoat Lion", 1); + assertPermanentCount(playerB, "Aesi, Tyrant of Gyre Strait", 0); + } +}