diff --git a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java index fa5e8f6cb2..75e70c3c8d 100644 --- a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java @@ -593,6 +593,54 @@ public class ComputerPlayer extends PlayerImpl implements Player { //if (!target.isRequired()) return false; } + if (target.getOriginalTarget() instanceof TargetPermanentOrPlayer) { + List targets; + TargetPermanentOrPlayer t = ((TargetPermanentOrPlayer) target); + if (outcome.isGood()) { + targets = threats(abilityControllerId, source.getSourceId(), ((FilterPermanentOrPlayer) t.getFilter()).getPermanentFilter(), game, target.getTargets()); + } else { + targets = threats(randomOpponentId, source.getSourceId(), ((FilterPermanentOrPlayer) t.getFilter()).getPermanentFilter(), game, target.getTargets()); + } + + if (targets.isEmpty()) { + if (outcome.isGood()) { + if (target.canTarget(getId(), abilityControllerId, source, game)) { + target.addTarget(abilityControllerId, source, game); + return true; + } + } else if (target.canTarget(getId(), randomOpponentId, source, game)) { + target.addTarget(randomOpponentId, source, game); + return true; + } + } + + if (targets.isEmpty() && target.isRequired(source)) { + targets = game.getBattlefield().getActivePermanents(((FilterPermanentOrPlayer) t.getFilter()).getPermanentFilter(), playerId, game); + } + for (Permanent permanent : targets) { + List alreadyTargetted = target.getTargets(); + if (t.canTarget(abilityControllerId, permanent.getId(), source, game)) { + if (alreadyTargetted != null && !alreadyTargetted.contains(permanent.getId())) { + target.addTarget(permanent.getId(), source, game); + return true; + } + } + } + + if (outcome.isGood()) { + if (target.canTarget(getId(), abilityControllerId, source, game)) { + target.addTarget(abilityControllerId, source, game); + return true; + } + } else if (target.canTarget(getId(), randomOpponentId, source, game)) { + target.addTarget(randomOpponentId, source, game); + return true; + } + + //if (!target.isRequired()) + return false; + } + if (target.getOriginalTarget() instanceof TargetCardInGraveyard) { List cards = new ArrayList<>(); for (Player player : game.getPlayers().values()) {