From 9aca4b02841298b856a9c784e1becfaac646c7a3 Mon Sep 17 00:00:00 2001 From: "maurer.it" Date: Mon, 10 Jan 2011 14:23:25 -0500 Subject: [PATCH] Changes so the AI behaves better when asked to sacrifice multiple permanents. Previous versions caused it to enter an infinite cycle of picking targets. --- .../src/mage/abilities/effects/common/SacrificeEffect.java | 7 ++++--- Mage/src/mage/target/TargetPermanent.java | 4 +++- Mage/src/mage/target/common/TargetControlledPermanent.java | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Mage/src/mage/abilities/effects/common/SacrificeEffect.java b/Mage/src/mage/abilities/effects/common/SacrificeEffect.java index 13d3c0a999..8638c24fbb 100644 --- a/Mage/src/mage/abilities/effects/common/SacrificeEffect.java +++ b/Mage/src/mage/abilities/effects/common/SacrificeEffect.java @@ -36,7 +36,8 @@ import mage.filter.FilterPermanent; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; -import mage.target.TargetPermanent; +import mage.target.Target; +import mage.target.common.TargetControlledPermanent; /** * @@ -66,13 +67,13 @@ public class SacrificeEffect extends OneShotEffect{ public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getTargets().getFirstTarget()); filter.setTargetController(TargetController.YOU); - TargetPermanent target = new TargetPermanent(count, count, filter, false); + Target target = new TargetControlledPermanent(count, count, filter, false); //A spell or ability could have removed the only legal target this player //had, if thats the case this ability should fizzle. if (target.canChoose(player.getId(), game)) { boolean abilityApplied = false; - while (!target.isChosen()) { + while (!target.isChosen() && target.canChoose(player.getId(), game)) { player.choose(Outcome.Sacrifice, target, game); } diff --git a/Mage/src/mage/target/TargetPermanent.java b/Mage/src/mage/target/TargetPermanent.java index 3af17a7ed4..f5963cf01f 100644 --- a/Mage/src/mage/target/TargetPermanent.java +++ b/Mage/src/mage/target/TargetPermanent.java @@ -127,7 +127,9 @@ public class TargetPermanent> extends TargetObject< */ @Override public boolean canChoose(UUID sourceControllerId, Game game) { - return game.getBattlefield().count(filter, sourceControllerId, game) >= this.minNumberOfTargets; + int possibleTargets = game.getBattlefield().count(filter, sourceControllerId, game); + return possibleTargets >= this.minNumberOfTargets && + this.getTargets().size() < possibleTargets; } @Override diff --git a/Mage/src/mage/target/common/TargetControlledPermanent.java b/Mage/src/mage/target/common/TargetControlledPermanent.java index 1a0e66d0b0..b68099ac4d 100644 --- a/Mage/src/mage/target/common/TargetControlledPermanent.java +++ b/Mage/src/mage/target/common/TargetControlledPermanent.java @@ -28,6 +28,7 @@ package mage.target.common; +import mage.filter.FilterPermanent; import mage.filter.common.FilterControlledPermanent; import mage.target.TargetPermanent; @@ -49,7 +50,7 @@ public class TargetControlledPermanent> e this(1, 1, filter, false); } - public TargetControlledPermanent(int minNumTargets, int maxNumTargets, FilterControlledPermanent filter, boolean notTarget) { + public TargetControlledPermanent(int minNumTargets, int maxNumTargets, FilterPermanent filter, boolean notTarget) { super(minNumTargets, maxNumTargets, filter, notTarget); this.targetName = filter.getMessage(); }