mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
Changes so the AI behaves better when asked to sacrifice multiple permanents. Previous versions caused it to enter an infinite cycle of picking targets.
This commit is contained in:
parent
7fbd807991
commit
9aca4b0284
3 changed files with 9 additions and 5 deletions
|
@ -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<SacrificeEffect>{
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,9 @@ public class TargetPermanent<T extends TargetPermanent<T>> 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
|
||||
|
|
|
@ -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<T extends TargetControlledPermanent<T>> 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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue