mirror of
https://github.com/correl/mage.git
synced 2024-11-28 19:19:55 +00:00
* Fixed a problem of AI target handling (e.g. for Precursor Golem)
This commit is contained in:
parent
f3c0d3fce0
commit
2162fab114
4 changed files with 42 additions and 35 deletions
|
@ -207,11 +207,10 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
abilityControllerId = target.getAbilityController();
|
abilityControllerId = target.getAbilityController();
|
||||||
}
|
}
|
||||||
UUID randomOpponentId = getRandomOpponent(abilityControllerId, game);
|
UUID randomOpponentId = getRandomOpponent(abilityControllerId, game);
|
||||||
if (target instanceof TargetPlayer) {
|
if (target.getOriginalTarget() instanceof TargetPlayer) {
|
||||||
return setTargetPlayer(outcome, target, null, sourceId, abilityControllerId, randomOpponentId, game);
|
return setTargetPlayer(outcome, target, null, sourceId, abilityControllerId, randomOpponentId, game);
|
||||||
}
|
}
|
||||||
|
if (target.getOriginalTarget() instanceof TargetDiscard) {
|
||||||
if (target instanceof TargetDiscard) {
|
|
||||||
findPlayables(game);
|
findPlayables(game);
|
||||||
if (unplayable.size() > 0) {
|
if (unplayable.size() > 0) {
|
||||||
for (int i = unplayable.size() - 1; i >= 0; i--) {
|
for (int i = unplayable.size() - 1; i >= 0; i--) {
|
||||||
|
@ -235,7 +234,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (target instanceof TargetControlledPermanent) {
|
if (target.getOriginalTarget() instanceof TargetControlledPermanent) {
|
||||||
List<Permanent> targets;
|
List<Permanent> targets;
|
||||||
targets = threats(abilityControllerId, sourceId, ((TargetControlledPermanent) target).getFilter(), game, target.getTargets());
|
targets = threats(abilityControllerId, sourceId, ((TargetControlledPermanent) target).getFilter(), game, target.getTargets());
|
||||||
if (!outcome.isGood()) {
|
if (!outcome.isGood()) {
|
||||||
|
@ -249,7 +248,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (target instanceof TargetPermanent) {
|
if (target.getOriginalTarget() instanceof TargetPermanent) {
|
||||||
List<Permanent> targets;
|
List<Permanent> targets;
|
||||||
if (outcome.isCanTargetAll()) {
|
if (outcome.isCanTargetAll()) {
|
||||||
targets = threats(null, sourceId, ((TargetPermanent) target).getFilter(), game, target.getTargets());
|
targets = threats(null, sourceId, ((TargetPermanent) target).getFilter(), game, target.getTargets());
|
||||||
|
@ -288,8 +287,8 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
return target.isChosen();
|
return target.isChosen();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target instanceof TargetCardInHand
|
if (target.getOriginalTarget() instanceof TargetCardInHand
|
||||||
|| (target.getZone().equals(Zone.HAND) && (target instanceof TargetCard))) {
|
|| (target.getZone().equals(Zone.HAND) && (target.getOriginalTarget() instanceof TargetCard))) {
|
||||||
List<Card> cards = new ArrayList<>();
|
List<Card> cards = new ArrayList<>();
|
||||||
for (UUID cardId : target.possibleTargets(sourceId, this.getId(), game)) {
|
for (UUID cardId : target.possibleTargets(sourceId, this.getId(), game)) {
|
||||||
Card card = game.getCard(cardId);
|
Card card = game.getCard(cardId);
|
||||||
|
@ -307,7 +306,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
}
|
}
|
||||||
return target.isChosen();
|
return target.isChosen();
|
||||||
}
|
}
|
||||||
if (target instanceof TargetCreatureOrPlayer) {
|
if (target.getOriginalTarget() instanceof TargetCreatureOrPlayer) {
|
||||||
List<Permanent> targets;
|
List<Permanent> targets;
|
||||||
TargetCreatureOrPlayer t = ((TargetCreatureOrPlayer) target);
|
TargetCreatureOrPlayer t = ((TargetCreatureOrPlayer) target);
|
||||||
if (outcome.isGood()) {
|
if (outcome.isGood()) {
|
||||||
|
@ -338,7 +337,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target instanceof TargetPermanentOrPlayer) {
|
if (target.getOriginalTarget() instanceof TargetPermanentOrPlayer) {
|
||||||
List<Permanent> targets;
|
List<Permanent> targets;
|
||||||
TargetPermanentOrPlayer t = ((TargetPermanentOrPlayer) target);
|
TargetPermanentOrPlayer t = ((TargetPermanentOrPlayer) target);
|
||||||
List<Permanent> ownedTargets = threats(abilityControllerId, sourceId, ((FilterPermanentOrPlayer) t.getFilter()).getPermanentFilter(), game, target.getTargets());
|
List<Permanent> ownedTargets = threats(abilityControllerId, sourceId, ((FilterPermanentOrPlayer) t.getFilter()).getPermanentFilter(), game, target.getTargets());
|
||||||
|
@ -393,7 +392,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (target instanceof TargetCardInGraveyard) {
|
if (target.getOriginalTarget() instanceof TargetCardInGraveyard) {
|
||||||
List<Card> cards = new ArrayList<>();
|
List<Card> cards = new ArrayList<>();
|
||||||
for (Player player : game.getPlayers().values()) {
|
for (Player player : game.getPlayers().values()) {
|
||||||
for (Card card : player.getGraveyard().getCards(game)) {
|
for (Card card : player.getGraveyard().getCards(game)) {
|
||||||
|
@ -411,7 +410,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
return target.isChosen();
|
return target.isChosen();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target instanceof TargetCardInYourGraveyard) {
|
if (target.getOriginalTarget() instanceof TargetCardInYourGraveyard) {
|
||||||
List<UUID> alreadyTargetted = target.getTargets();
|
List<UUID> alreadyTargetted = target.getTargets();
|
||||||
List<Card> cards = new ArrayList<>(game.getPlayer(abilityControllerId).getGraveyard().getCards(game));
|
List<Card> cards = new ArrayList<>(game.getPlayer(abilityControllerId).getGraveyard().getCards(game));
|
||||||
while (!cards.isEmpty()) {
|
while (!cards.isEmpty()) {
|
||||||
|
@ -423,7 +422,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (target instanceof TargetSource) {
|
if (target.getOriginalTarget() instanceof TargetSource) {
|
||||||
Set<UUID> targets;
|
Set<UUID> targets;
|
||||||
TargetSource t = ((TargetSource) target);
|
TargetSource t = ((TargetSource) target);
|
||||||
targets = t.possibleTargets(sourceId, abilityControllerId, game);
|
targets = t.possibleTargets(sourceId, abilityControllerId, game);
|
||||||
|
@ -459,11 +458,11 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
abilityControllerId = target.getAbilityController();
|
abilityControllerId = target.getAbilityController();
|
||||||
}
|
}
|
||||||
UUID randomOpponentId = getRandomOpponent(abilityControllerId, game);
|
UUID randomOpponentId = getRandomOpponent(abilityControllerId, game);
|
||||||
if (target instanceof TargetPlayer) {
|
if (target.getOriginalTarget() instanceof TargetPlayer) {
|
||||||
return setTargetPlayer(outcome, target, source, source.getSourceId(), abilityControllerId, randomOpponentId, game);
|
return setTargetPlayer(outcome, target, source, source.getSourceId(), abilityControllerId, randomOpponentId, game);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target instanceof TargetDiscard || target instanceof TargetCardInHand) {
|
if (target.getOriginalTarget() instanceof TargetDiscard || target.getOriginalTarget() instanceof TargetCardInHand) {
|
||||||
if (outcome.isGood()) {
|
if (outcome.isGood()) {
|
||||||
Cards cards = new CardsImpl(target.possibleTargets(source.getSourceId(), getId(), game));
|
Cards cards = new CardsImpl(target.possibleTargets(source.getSourceId(), getId(), game));
|
||||||
ArrayList<Card> cardsInHand = new ArrayList<>(cards.getCards(game));
|
ArrayList<Card> cardsInHand = new ArrayList<>(cards.getCards(game));
|
||||||
|
@ -506,7 +505,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (target instanceof TargetControlledPermanent) {
|
if (target.getOriginalTarget() instanceof TargetControlledPermanent) {
|
||||||
List<Permanent> targets;
|
List<Permanent> targets;
|
||||||
targets = threats(abilityControllerId, source.getSourceId(), ((TargetControlledPermanent) target).getFilter(), game, target.getTargets());
|
targets = threats(abilityControllerId, source.getSourceId(), ((TargetControlledPermanent) target).getFilter(), game, target.getTargets());
|
||||||
if (!outcome.isGood()) {
|
if (!outcome.isGood()) {
|
||||||
|
@ -523,7 +522,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
return target.isChosen();
|
return target.isChosen();
|
||||||
|
|
||||||
}
|
}
|
||||||
if (target instanceof TargetPermanent) {
|
if (target.getOriginalTarget() instanceof TargetPermanent) {
|
||||||
List<Permanent> targets;
|
List<Permanent> targets;
|
||||||
boolean outcomeTargets = true;
|
boolean outcomeTargets = true;
|
||||||
if (outcome.isGood()) {
|
if (outcome.isGood()) {
|
||||||
|
@ -547,7 +546,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
}
|
}
|
||||||
return target.isChosen();
|
return target.isChosen();
|
||||||
}
|
}
|
||||||
if (target instanceof TargetCreatureOrPlayer) {
|
if (target.getOriginalTarget() instanceof TargetCreatureOrPlayer) {
|
||||||
List<Permanent> targets;
|
List<Permanent> targets;
|
||||||
TargetCreatureOrPlayer t = ((TargetCreatureOrPlayer) target);
|
TargetCreatureOrPlayer t = ((TargetCreatureOrPlayer) target);
|
||||||
if (outcome.isGood()) {
|
if (outcome.isGood()) {
|
||||||
|
@ -594,7 +593,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
//if (!target.isRequired())
|
//if (!target.isRequired())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (target instanceof TargetCardInGraveyard) {
|
if (target.getOriginalTarget() instanceof TargetCardInGraveyard) {
|
||||||
List<Card> cards = new ArrayList<>();
|
List<Card> cards = new ArrayList<>();
|
||||||
for (Player player : game.getPlayers().values()) {
|
for (Player player : game.getPlayers().values()) {
|
||||||
cards.addAll(player.getGraveyard().getCards(game));
|
cards.addAll(player.getGraveyard().getCards(game));
|
||||||
|
@ -607,7 +606,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
//if (!target.isRequired())
|
//if (!target.isRequired())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (target instanceof TargetCardInLibrary) {
|
if (target.getOriginalTarget() instanceof TargetCardInLibrary) {
|
||||||
List<Card> cards = new ArrayList<>(game.getPlayer(abilityControllerId).getLibrary().getCards(game));
|
List<Card> cards = new ArrayList<>(game.getPlayer(abilityControllerId).getLibrary().getCards(game));
|
||||||
Card card = pickTarget(cards, outcome, target, source, game);
|
Card card = pickTarget(cards, outcome, target, source, game);
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
|
@ -616,7 +615,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (target instanceof TargetCardInYourGraveyard) {
|
if (target.getOriginalTarget() instanceof TargetCardInYourGraveyard) {
|
||||||
List<Card> cards = new ArrayList<>(game.getPlayer(abilityControllerId).getGraveyard().getCards(game));
|
List<Card> cards = new ArrayList<>(game.getPlayer(abilityControllerId).getGraveyard().getCards(game));
|
||||||
while (!target.isChosen() && !cards.isEmpty()) {
|
while (!target.isChosen() && !cards.isEmpty()) {
|
||||||
Card card = pickTarget(cards, outcome, target, source, game);
|
Card card = pickTarget(cards, outcome, target, source, game);
|
||||||
|
@ -626,7 +625,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
}
|
}
|
||||||
return target.isChosen();
|
return target.isChosen();
|
||||||
}
|
}
|
||||||
if (target instanceof TargetSpell) {
|
if (target.getOriginalTarget() instanceof TargetSpell) {
|
||||||
if (game.getStack().size() > 0) {
|
if (game.getStack().size() > 0) {
|
||||||
Iterator<StackObject> it = game.getStack().iterator();
|
Iterator<StackObject> it = game.getStack().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
|
@ -639,7 +638,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (target instanceof TargetSpellOrPermanent) {
|
if (target.getOriginalTarget() instanceof TargetSpellOrPermanent) {
|
||||||
// TODO: Also check if a spell should be selected
|
// TODO: Also check if a spell should be selected
|
||||||
List<Permanent> targets;
|
List<Permanent> targets;
|
||||||
boolean outcomeTargets = true;
|
boolean outcomeTargets = true;
|
||||||
|
@ -675,7 +674,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (target instanceof TargetCardInOpponentsGraveyard) {
|
if (target.getOriginalTarget() instanceof TargetCardInOpponentsGraveyard) {
|
||||||
List<Card> cards = new ArrayList<>();
|
List<Card> cards = new ArrayList<>();
|
||||||
for (UUID uuid : game.getOpponents(abilityControllerId)) {
|
for (UUID uuid : game.getOpponents(abilityControllerId)) {
|
||||||
Player player = game.getPlayer(uuid);
|
Player player = game.getPlayer(uuid);
|
||||||
|
@ -691,7 +690,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
//if (!target.isRequired())
|
//if (!target.isRequired())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (target instanceof TargetDefender) {
|
if (target.getOriginalTarget() instanceof TargetDefender) {
|
||||||
// TODO: Improve, now planeswalker is always chosen if it exits
|
// TODO: Improve, now planeswalker is always chosen if it exits
|
||||||
List<Permanent> targets;
|
List<Permanent> targets;
|
||||||
targets = game.getBattlefield().getActivePermanents(new FilterPlaneswalkerPermanent(), randomOpponentId, game);
|
targets = game.getBattlefield().getActivePermanents(new FilterPlaneswalkerPermanent(), randomOpponentId, game);
|
||||||
|
@ -713,7 +712,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
return target.isChosen();
|
return target.isChosen();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target instanceof TargetCardInASingleGraveyard) {
|
if (target.getOriginalTarget() instanceof TargetCardInASingleGraveyard) {
|
||||||
List<Card> cards = new ArrayList<>();
|
List<Card> cards = new ArrayList<>();
|
||||||
for (Player player : game.getPlayers().values()) {
|
for (Player player : game.getPlayers().values()) {
|
||||||
cards.addAll(player.getGraveyard().getCards(game));
|
cards.addAll(player.getGraveyard().getCards(game));
|
||||||
|
@ -727,7 +726,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
return target.isChosen();
|
return target.isChosen();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target instanceof TargetCardInExile) {
|
if (target.getOriginalTarget() instanceof TargetCardInExile) {
|
||||||
List<Card> cards = new ArrayList<>();
|
List<Card> cards = new ArrayList<>();
|
||||||
for (UUID uuid : ((TargetCardInExile) target).possibleTargets(source.getSourceId(), source.getControllerId(), game)) {
|
for (UUID uuid : ((TargetCardInExile) target).possibleTargets(source.getSourceId(), source.getControllerId(), game)) {
|
||||||
Card card = game.getCard(uuid);
|
Card card = game.getCard(uuid);
|
||||||
|
@ -773,7 +772,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
log.debug("chooseTarget: " + outcome.toString() + ":" + target.toString());
|
log.debug("chooseTarget: " + outcome.toString() + ":" + target.toString());
|
||||||
}
|
}
|
||||||
UUID opponentId = game.getOpponents(playerId).iterator().next();
|
UUID opponentId = game.getOpponents(playerId).iterator().next();
|
||||||
if (target instanceof TargetCreatureOrPlayerAmount) {
|
if (target.getOriginalTarget() instanceof TargetCreatureOrPlayerAmount) {
|
||||||
if (outcome.equals(Outcome.Damage) && game.getPlayer(opponentId).getLife() <= target.getAmountRemaining()) {
|
if (outcome.equals(Outcome.Damage) && game.getPlayer(opponentId).getLife() <= target.getAmountRemaining()) {
|
||||||
target.addTarget(opponentId, target.getAmountRemaining(), source, game);
|
target.addTarget(opponentId, target.getAmountRemaining(), source, game);
|
||||||
return true;
|
return true;
|
||||||
|
@ -2148,7 +2147,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private boolean setTargetPlayer(Outcome outcome, Target target, Ability source, UUID sourceId, UUID abilityControllerId, UUID randomOpponentId, Game game) {
|
private boolean setTargetPlayer(Outcome outcome, Target target, Ability source, UUID sourceId, UUID abilityControllerId, UUID randomOpponentId, Game game) {
|
||||||
if (target instanceof TargetOpponent) {
|
if (target.getOriginalTarget() instanceof TargetOpponent) {
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
if (((TargetOpponent) target).canTarget(randomOpponentId, game)) {
|
if (((TargetOpponent) target).canTarget(randomOpponentId, game)) {
|
||||||
target.add(randomOpponentId, game);
|
target.add(randomOpponentId, game);
|
||||||
|
@ -2172,7 +2171,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target instanceof TargetPlayer) {
|
if (target.getOriginalTarget() instanceof TargetPlayer) {
|
||||||
if (outcome.isGood()) {
|
if (outcome.isGood()) {
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
if (target.canTarget(abilityControllerId, game)) {
|
if (target.canTarget(abilityControllerId, game)) {
|
||||||
|
|
|
@ -261,9 +261,6 @@ class TargetWithAdditionalFilter<T extends MageItem> extends TargetImpl {
|
||||||
|
|
||||||
protected final FilterInPlay<T> additionalFilter;
|
protected final FilterInPlay<T> additionalFilter;
|
||||||
protected final Target originalTarget;
|
protected final Target originalTarget;
|
||||||
protected static final Integer minNumberOfTargets = null;
|
|
||||||
protected static final Integer maxNumberOfTargets = null;
|
|
||||||
protected static final Zone zone = null;
|
|
||||||
|
|
||||||
public TargetWithAdditionalFilter(final TargetWithAdditionalFilter target) {
|
public TargetWithAdditionalFilter(final TargetWithAdditionalFilter target) {
|
||||||
this(target.originalTarget, target.additionalFilter, false);
|
this(target.originalTarget, target.additionalFilter, false);
|
||||||
|
@ -274,14 +271,18 @@ class TargetWithAdditionalFilter<T extends MageItem> extends TargetImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
public TargetWithAdditionalFilter(Target originalTarget, FilterInPlay<T> additionalFilter, boolean notTarget) {
|
public TargetWithAdditionalFilter(Target originalTarget, FilterInPlay<T> additionalFilter, boolean notTarget) {
|
||||||
originalTarget = originalTarget.copy();
|
this.originalTarget = originalTarget.copy();
|
||||||
originalTarget.clearChosen();
|
this.originalTarget.clearChosen();
|
||||||
this.originalTarget = originalTarget;
|
|
||||||
this.targetName = originalTarget.getFilter().getMessage();
|
this.targetName = originalTarget.getFilter().getMessage();
|
||||||
this.notTarget = notTarget;
|
this.notTarget = notTarget;
|
||||||
this.additionalFilter = additionalFilter;
|
this.additionalFilter = additionalFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Target getOriginalTarget() {
|
||||||
|
return originalTarget;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNumberOfTargets() {
|
public int getNumberOfTargets() {
|
||||||
return originalTarget.getNumberOfTargets();
|
return originalTarget.getNumberOfTargets();
|
||||||
|
|
|
@ -155,4 +155,6 @@ public interface Target extends Serializable {
|
||||||
int getTargetTag();
|
int getTargetTag();
|
||||||
|
|
||||||
void setTargetTag(int tag);
|
void setTargetTag(int tag);
|
||||||
|
|
||||||
|
Target getOriginalTarget();
|
||||||
}
|
}
|
||||||
|
|
|
@ -554,4 +554,9 @@ public abstract class TargetImpl implements Target {
|
||||||
this.targetTag = targetTag;
|
this.targetTag = targetTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Target getOriginalTarget() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue