mirror of
https://github.com/correl/mage.git
synced 2024-11-14 19:19:32 +00:00
Computer AI - Fixed a bug in AI target handling (e.g. AI Show and Tell selection blocked UI).
This commit is contained in:
parent
26e03d6c0f
commit
56b81f8635
2 changed files with 36 additions and 37 deletions
|
@ -511,7 +511,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
while (!target.isChosen() && !cardsInHand.isEmpty() && target.getMaxNumberOfTargets() > target.getTargets().size()) {
|
||||
Card card = pickBestCard(cardsInHand, null, target, source, game);
|
||||
if (card != null) {
|
||||
if (target.canTarget(card.getId(), source, game)) {
|
||||
if (target.canTarget(getId(), card.getId(), source, game)) {
|
||||
target.addTarget(card.getId(), source, game);
|
||||
cardsInHand.remove(card);
|
||||
if (target.isChosen()) {
|
||||
|
@ -525,7 +525,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
findPlayables(game);
|
||||
if (unplayable.size() > 0) {
|
||||
for (int i = unplayable.size() - 1; i >= 0; i--) {
|
||||
if (target.canTarget(unplayable.values().toArray(new Card[0])[i].getId(), source, game)) {
|
||||
if (target.canTarget(getId(), unplayable.values().toArray(new Card[0])[i].getId(), source, game)) {
|
||||
target.addTarget(unplayable.values().toArray(new Card[0])[i].getId(), source, game);
|
||||
if (target.isChosen()) {
|
||||
return true;
|
||||
|
@ -535,7 +535,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
}
|
||||
if (hand.size() > 0) {
|
||||
for (int i = 0; i < hand.size(); i++) {
|
||||
if (target.canTarget(hand.toArray(new UUID[0])[i], source, game)) {
|
||||
if (target.canTarget(getId(), hand.toArray(new UUID[0])[i], source, game)) {
|
||||
target.addTarget(hand.toArray(new UUID[0])[i], source, game);
|
||||
if (target.isChosen()) {
|
||||
return true;
|
||||
|
@ -600,13 +600,13 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
|
||||
if (targets.isEmpty()) {
|
||||
if (outcome.isGood()) {
|
||||
if (target.canTarget(abilityControllerId, source, game)) {
|
||||
if (target.canTarget(getId(), abilityControllerId, source, game)) {
|
||||
target.addTarget(abilityControllerId, source, game);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (target.canTarget(opponentId, source, game)) {
|
||||
if (target.canTarget(getId(), opponentId, source, game)) {
|
||||
target.addTarget(opponentId, source, game);
|
||||
return true;
|
||||
}
|
||||
|
@ -627,13 +627,13 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
}
|
||||
|
||||
if (outcome.isGood()) {
|
||||
if (target.canTarget(abilityControllerId, source, game)) {
|
||||
if (target.canTarget(getId(),abilityControllerId, source, game)) {
|
||||
target.addTarget(abilityControllerId, source, game);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (target.canTarget(opponentId, source, game)) {
|
||||
if (target.canTarget(getId(),opponentId, source, game)) {
|
||||
target.addTarget(opponentId, source, game);
|
||||
return true;
|
||||
}
|
||||
|
@ -757,7 +757,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
targets = game.getBattlefield().getActivePermanents(new FilterPlaneswalkerPermanent(), opponentId, game);
|
||||
if (targets != null && !targets.isEmpty()) {
|
||||
for (Permanent planeswalker: targets) {
|
||||
if (target.canTarget(planeswalker.getId(), source, game)) {
|
||||
if (target.canTarget(getId(),planeswalker.getId(), source, game)) {
|
||||
target.addTarget(planeswalker.getId(), source, game);
|
||||
}
|
||||
if (target.isChosen()) {
|
||||
|
@ -766,7 +766,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
}
|
||||
}
|
||||
if (!target.isChosen()) {
|
||||
if (target.canTarget(opponentId, source, game)) {
|
||||
if (target.canTarget(getId() ,opponentId, source, game)) {
|
||||
target.addTarget(opponentId, source, game);
|
||||
}
|
||||
}
|
||||
|
@ -818,7 +818,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
card = pickWorstCard(cards, null, target, source, game);
|
||||
}
|
||||
if (source != null) {
|
||||
if (target.canTarget(this.getId(), card.getId(), source, game)) {
|
||||
if (target.canTarget(getId(), card.getId(), source, game)) {
|
||||
return card;
|
||||
}
|
||||
}
|
||||
|
@ -849,21 +849,21 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
targets = threats(opponentId, source.getSourceId(), new FilterCreaturePermanent(), game, target.getTargets());
|
||||
}
|
||||
for (Permanent permanent: targets) {
|
||||
if (target.canTarget(permanent.getId(), source, game)) {
|
||||
if (target.canTarget(getId() ,permanent.getId(), source, game)) {
|
||||
if (permanent.getToughness().getValue() <= target.getAmountRemaining()) {
|
||||
target.addTarget(permanent.getId(), permanent.getToughness().getValue(), source, game);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (outcome.isGood() && target.canTarget(playerId, playerId, source, game)) {
|
||||
if (outcome.isGood() && target.canTarget(getId(), getId(), source, game)) {
|
||||
target.addTarget(opponentId, target.getAmountRemaining(), source, game);
|
||||
return true;
|
||||
} else if (target.canTarget(playerId, opponentId, source, game)){
|
||||
} else if (target.canTarget(getId(), opponentId, source, game)){
|
||||
// no permanent target so take opponent
|
||||
target.addTarget(opponentId, target.getAmountRemaining(), source, game);
|
||||
return true;
|
||||
} else if (target.canTarget(playerId, playerId, source, game)) {
|
||||
} else if (target.canTarget(getId(), playerId, source, game)) {
|
||||
target.addTarget(opponentId, target.getAmountRemaining(), source, game);
|
||||
return true;
|
||||
}
|
||||
|
@ -1778,7 +1778,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
} else if (score > maxScore) { // we need better card
|
||||
if (target != null && source != null && game != null) {
|
||||
// but also check it can be targeted
|
||||
betterCard = target.canTarget(card.getId(), source, game);
|
||||
betterCard = target.canTarget(getId(), card.getId(), source, game);
|
||||
} else {
|
||||
// target object wasn't provided, so acceptings it anyway
|
||||
betterCard = true;
|
||||
|
@ -1807,7 +1807,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
} else if (score < minScore) { // we need worse card
|
||||
if (target != null && source != null && game != null) {
|
||||
// but also check it can be targeted
|
||||
worseCard = target.canTarget(card.getId(), source, game);
|
||||
worseCard = target.canTarget(getId(), card.getId(), source, game);
|
||||
} else {
|
||||
// target object wasn't provided, so accepting it anyway
|
||||
worseCard = true;
|
||||
|
|
|
@ -43,7 +43,6 @@ import mage.filter.predicate.Predicates;
|
|||
import mage.filter.predicate.mageobject.CardTypePredicate;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.players.PlayerList;
|
||||
import mage.target.common.TargetCardInHand;
|
||||
|
||||
/**
|
||||
|
@ -76,11 +75,12 @@ class ShowAndTellEffect extends OneShotEffect {
|
|||
private static final FilterCard filter = new FilterCard("artifact, creature, enchantment, or land card");
|
||||
|
||||
static {
|
||||
filter.add(Predicates.or(
|
||||
new CardTypePredicate(CardType.ARTIFACT),
|
||||
new CardTypePredicate(CardType.CREATURE),
|
||||
new CardTypePredicate(CardType.ENCHANTMENT),
|
||||
new CardTypePredicate(CardType.LAND)));
|
||||
List<CardTypePredicate> cardTypes = new ArrayList<>();
|
||||
cardTypes.add(new CardTypePredicate(CardType.ARTIFACT));
|
||||
cardTypes.add(new CardTypePredicate(CardType.CREATURE));
|
||||
cardTypes.add(new CardTypePredicate(CardType.ENCHANTMENT));
|
||||
cardTypes.add(new CardTypePredicate(CardType.LAND));
|
||||
filter.add(Predicates.or(cardTypes));
|
||||
}
|
||||
|
||||
public ShowAndTellEffect() {
|
||||
|
@ -105,24 +105,23 @@ class ShowAndTellEffect extends OneShotEffect {
|
|||
}
|
||||
List<Card> cardsToPutIntoPlay = new ArrayList<>();
|
||||
TargetCardInHand target = new TargetCardInHand(filter);
|
||||
PlayerList playerList = game.getPlayerList().copy();
|
||||
playerList.setCurrent(game.getActivePlayerId());
|
||||
Player player = game.getPlayer(game.getActivePlayerId());
|
||||
do {
|
||||
if (player.chooseUse(outcome, "Put an artifact, creature, enchantment, or land card from hand onto the battlefield?", game)) {
|
||||
target.clearChosen();
|
||||
if (player.chooseTarget(outcome, target, source, game)) {
|
||||
Card card = game.getCard(target.getFirstTarget());
|
||||
if (card != null) {
|
||||
cardsToPutIntoPlay.add(card);
|
||||
|
||||
for(UUID playerId: game.getState().getPlayersInRange(controller.getId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
if (player.chooseUse(outcome, "Put an artifact, creature, enchantment, or land card from hand onto the battlefield?", game)) {
|
||||
target.clearChosen();
|
||||
if (player.chooseTarget(outcome, target, source, game)) {
|
||||
Card card = game.getCard(target.getFirstTarget());
|
||||
if (card != null) {
|
||||
cardsToPutIntoPlay.add(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
player = playerList.getNextInRange(controller, game);
|
||||
} while (!player.getId().equals(game.getActivePlayerId()));
|
||||
|
||||
}
|
||||
for (Card card: cardsToPutIntoPlay) {
|
||||
player = game.getPlayer(card.getOwnerId());
|
||||
Player player = game.getPlayer(card.getOwnerId());
|
||||
if (player != null) {
|
||||
player.putOntoBattlefieldWithInfo(card, game, Zone.HAND, source.getSourceId());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue