From 2e5be475b0d9bcca9302fdaf2bc217bee34ed98b Mon Sep 17 00:00:00 2001 From: jeffwadsworth Date: Tue, 3 Jul 2012 16:03:11 -0500 Subject: [PATCH] - Fixed Barter in Blood. Improved test for it. --- .../sets/avacynrestored/BarterInBlood.java | 66 +++---------------- .../oneshot/sacrifice/BarterInBloodTest.java | 8 ++- 2 files changed, 17 insertions(+), 57 deletions(-) diff --git a/Mage.Sets/src/mage/sets/avacynrestored/BarterInBlood.java b/Mage.Sets/src/mage/sets/avacynrestored/BarterInBlood.java index 1a534cf7c0..fa8d94e398 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/BarterInBlood.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/BarterInBlood.java @@ -28,25 +28,23 @@ package mage.sets.avacynrestored; import mage.Constants.CardType; -import mage.Constants.Outcome; import mage.Constants.Rarity; -import mage.abilities.Ability; -import mage.abilities.effects.OneShotEffect; import mage.cards.CardImpl; -import mage.filter.common.FilterCreaturePermanent; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.players.Player; -import mage.target.Target; -import mage.target.common.TargetControlledPermanent; - import java.util.UUID; +import mage.abilities.effects.common.SacrificeAllEffect; +import mage.filter.common.FilterControlledPermanent; /** * * @author North */ public class BarterInBlood extends CardImpl { + + private static final FilterControlledPermanent filter = new FilterControlledPermanent("creature"); + + static { + filter.getCardType().add(CardType.CREATURE); + } public BarterInBlood(UUID ownerId) { super(ownerId, 85, "Barter in Blood", Rarity.UNCOMMON, new CardType[]{CardType.SORCERY}, "{2}{B}{B}"); @@ -55,7 +53,7 @@ public class BarterInBlood extends CardImpl { this.color.setBlack(true); // Each player sacrifices two creatures. - this.getSpellAbility().addEffect(new BarterInBloodEffect()); + this.getSpellAbility().addEffect(new SacrificeAllEffect(2, filter)); } public BarterInBlood(final BarterInBlood card) { @@ -66,48 +64,4 @@ public class BarterInBlood extends CardImpl { public BarterInBlood copy() { return new BarterInBlood(this); } -} - -class BarterInBloodEffect extends OneShotEffect { - - public BarterInBloodEffect() { - super(Outcome.Sacrifice); - this.staticText = "Each player sacrifices two creatures"; - } - - public BarterInBloodEffect(final BarterInBloodEffect effect) { - super(effect); - } - - @Override - public BarterInBloodEffect copy() { - return new BarterInBloodEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - FilterCreaturePermanent filter = new FilterCreaturePermanent(); - for (UUID playerId : controller.getInRange()) { - Player player = game.getPlayer(playerId); - if (player != null) { - int amount = Math.min(2, game.getBattlefield().countAll(filter, player.getId(), game)); - Target target = new TargetControlledPermanent(amount, amount, filter, false); - target.setRequired(true); - if (amount > 0 && target.canChoose(player.getId(), game) - && player.choose(Outcome.Sacrifice, target, source.getSourceId(), game)) { - for (UUID targetId : target.getTargets()) { - Permanent permanent = game.getPermanent(targetId); - if (permanent != null) { - permanent.sacrifice(source.getSourceId(), game); - } - } - } - } - } - return true; - } - return false; - } -} +} \ No newline at end of file diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/sacrifice/BarterInBloodTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/sacrifice/BarterInBloodTest.java index ee1d635d28..46d596899e 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/sacrifice/BarterInBloodTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/sacrifice/BarterInBloodTest.java @@ -16,7 +16,12 @@ public class BarterInBloodTest extends CardTestPlayerBase { public void testSacrifice() { addCard(Constants.Zone.BATTLEFIELD, playerA, "Swamp", 4); addCard(Constants.Zone.HAND, playerA, "Barter in Blood"); + + addCard(Constants.Zone.BATTLEFIELD, playerA, "Memnite"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Royal Assassin"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Sengir Vampire"); + addCard(Constants.Zone.BATTLEFIELD, playerB, "Island"); addCard(Constants.Zone.BATTLEFIELD, playerB, "Flowering Lumberknot"); addCard(Constants.Zone.BATTLEFIELD, playerB, "Moorland Inquisitor"); @@ -25,6 +30,7 @@ public class BarterInBloodTest extends CardTestPlayerBase { setStopAt(1, Constants.PhaseStep.BEGIN_COMBAT); execute(); - assertPermanentCount(playerB, 0); + assertPermanentCount(playerA, 5); + assertPermanentCount(playerB, 1); } }