From 271f7b812fd9a9ca974b35d6341c779cd0860efc Mon Sep 17 00:00:00 2001 From: Ingmar Goudt Date: Sun, 22 Aug 2021 12:01:10 +0200 Subject: [PATCH] fix #8097, the sacrifice target cost was optional, but SacrificeCost.canPay first checks if there are valid targets. In this scenario there were none, but the spell should still be playable --- .../cost/sacrifice/OptionalSacrificeTests.java | 17 +++++++++++++++++ .../costs/common/SacrificeTargetCost.java | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/cost/sacrifice/OptionalSacrificeTests.java b/Mage.Tests/src/test/java/org/mage/test/cards/cost/sacrifice/OptionalSacrificeTests.java index 412181a3bf..7a5e0dfddf 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/cost/sacrifice/OptionalSacrificeTests.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/cost/sacrifice/OptionalSacrificeTests.java @@ -190,4 +190,21 @@ public class OptionalSacrificeTests extends CardTestPlayerBase { assertHandCount(playerB, "Propaganda", 0); assertPermanentCount(playerB, "Propaganda", 1); } + + /** + As an additional cost to cast Devouring Greed, you may sacrifice any number of Spirits. + + // Target player loses 2 life plus 2 life for each Spirit sacrificed this way. You gain that much life. + **/ + @Test + public void testDevouringGreedWithoutSpirits(){ + addCard(Zone.HAND, playerA, "Devouring Greed"); + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 10); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Devouring Greed", playerB); + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + assertLife(playerB, 18); + assertLife(playerA, 22); + assertGraveyardCount(playerA, "Devouring Greed", 1); + } } diff --git a/Mage/src/main/java/mage/abilities/costs/common/SacrificeTargetCost.java b/Mage/src/main/java/mage/abilities/costs/common/SacrificeTargetCost.java index fdd4b8cbe9..19a54ee2c9 100644 --- a/Mage/src/main/java/mage/abilities/costs/common/SacrificeTargetCost.java +++ b/Mage/src/main/java/mage/abilities/costs/common/SacrificeTargetCost.java @@ -87,6 +87,10 @@ public class SacrificeTargetCost extends CostImpl { } } } + // solves issue #8097, if a sacrifice cost is optional and you don't have valid targets, then the cost can be paid + if(validTargets == 0 && targets.get(0).getMinNumberOfTargets() == 0){ + return true; + } return false; }