Merge branch 'manifest' into 'master'

Fix ManifestAi

See merge request core-developers/forge!5519
This commit is contained in:
Michael Kamensky
2021-10-08 03:35:54 +00:00
7 changed files with 26 additions and 26 deletions

View File

@@ -1202,7 +1202,7 @@ public class AiAttackController {
} }
// look at the attacker in relation to the blockers to establish a // look at the attacker in relation to the blockers to establish a
// number of factors about the attacking context that will be relevant // number of factors about the attacking context that will be relevant
// to the attackers decision according to the selected strategy // to the attackers decision according to the selected strategy
for (final Card defender : validBlockers) { for (final Card defender : validBlockers) {
// if both isWorthLessThanAllKillers and canKillAllDangerous are false there's nothing more to check // if both isWorthLessThanAllKillers and canKillAllDangerous are false there's nothing more to check

View File

@@ -191,7 +191,7 @@ public class ChooseCardAi extends SpellAbilityAi {
} else if (logic.equals("NeedsPrevention")) { } else if (logic.equals("NeedsPrevention")) {
final Game game = ai.getGame(); final Game game = ai.getGame();
final Combat combat = game.getCombat(); final Combat combat = game.getCombat();
CardCollectionView better = CardLists.filter(options, new Predicate<Card>() { CardCollectionView better = CardLists.filter(options, new Predicate<Card>() {
@Override @Override
public boolean apply(final Card c) { public boolean apply(final Card c) {
if (combat == null || !combat.isAttacking(c, ai) || !combat.isUnblocked(c)) { if (combat == null || !combat.isAttacking(c, ai) || !combat.isUnblocked(c)) {

View File

@@ -106,7 +106,7 @@ public class ManifestAi extends SpellAbilityAi {
return false; return false;
} }
if (card.mayPlayerLook(ai)) { if (card.getView().canBeShownTo(ai.getView())) {
// try to avoid manifest a non Permanent // try to avoid manifest a non Permanent
if (!card.isPermanent()) if (!card.isPermanent())
return false; return false;
@@ -115,7 +115,7 @@ public class ManifestAi extends SpellAbilityAi {
if (card.getManaCost().countX() > 0) if (card.getManaCost().countX() > 0)
return false; return false;
// try to avoid manifesting a creature with zero or less thoughness // try to avoid manifesting a creature with zero or less toughness
if (card.isCreature() && card.getNetToughness() <= 0) if (card.isCreature() && card.getNetToughness() <= 0)
return false; return false;
@@ -177,21 +177,21 @@ public class ManifestAi extends SpellAbilityAi {
return MyRandom.getRandom().nextFloat() < .8; return MyRandom.getRandom().nextFloat() < .8;
} }
protected Card chooseSingleCard(final Player ai, final SpellAbility sa, Iterable<Card> options, boolean isOptional, Player targetedPlayer) { @Override
if (Iterables.size(options) <= 1) { protected Card chooseSingleCard(final Player ai, final SpellAbility sa, Iterable<Card> options, boolean isOptional, Player targetedPlayer, Map<String, Object> params) {
return Iterables.getFirst(options, null); if (Iterables.size(options) > 1 || isOptional) {
} CardCollection filtered = CardLists.filter(options, new Predicate<Card>() {
CardCollection filtered = CardLists.filter(options, new Predicate<Card>() { @Override
@Override public boolean apply(Card input) {
public boolean apply(Card input) { return shouldManyfest(input, ai, sa);
return !shouldManyfest(input, ai, sa); }
});
if (!filtered.isEmpty()) {
return ComputerUtilCard.getBestAI(filtered);
}
if (isOptional) {
return null;
} }
});
if (!filtered.isEmpty()) {
return ComputerUtilCard.getBestAI(filtered);
}
if (isOptional) {
return null;
} }
return Iterables.getFirst(options, null); return Iterables.getFirst(options, null);
} }

View File

@@ -526,16 +526,16 @@ public class PumpAi extends PumpAiBase {
} }
list = getCurseCreatures(ai, sa, defense, attack, keywords); list = getCurseCreatures(ai, sa, defense, attack, keywords);
} else { } else {
if (!tgt.canTgtCreature()) {
ZoneType zone = tgt.getZone().get(0);
list = new CardCollection(game.getCardsIn(zone));
} else {
list = getPumpCreatures(ai, sa, defense, attack, keywords, immediately);
}
if (sa.canTarget(ai)) { if (sa.canTarget(ai)) {
sa.getTargets().add(ai); sa.getTargets().add(ai);
return true; return true;
} }
if (tgt.canTgtCreature()) {
list = getPumpCreatures(ai, sa, defense, attack, keywords, immediately);
} else {
ZoneType zone = tgt.getZone().get(0);
list = new CardCollection(game.getCardsIn(zone));
}
} }
list = CardLists.getValidCards(list, tgt.getValidTgts(), ai, source, sa); list = CardLists.getValidCards(list, tgt.getValidTgts(), ai, source, sa);

View File

@@ -1069,7 +1069,6 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
public final Card getEncodingCard() { public final Card getEncodingCard() {
return encoding; return encoding;
} }
public final void setEncodingCard(final Card e) { public final void setEncodingCard(final Card e) {
encoding = e; encoding = e;
} }

View File

@@ -486,7 +486,7 @@ public class CardView extends GameEntityView {
}); });
} }
private boolean canBeShownTo(final PlayerView viewer) { public boolean canBeShownTo(final PlayerView viewer) {
if (viewer == null) { return false; } if (viewer == null) { return false; }
ZoneType zone = getZone(); ZoneType zone = getZone();

View File

@@ -426,6 +426,7 @@ public class TargetRestrictions {
*/ */
public final boolean canTgtCreature() { public final boolean canTgtCreature() {
for (final String s : this.validTgts) { for (final String s : this.validTgts) {
// TODO check IsCommander when in that variant
if ((s.contains("Creature") || s.startsWith("Permanent")) if ((s.contains("Creature") || s.startsWith("Permanent"))
&& !s.contains("nonCreature")) { && !s.contains("nonCreature")) {
return true; return true;