AiController: fixed MayPlay for Land

This commit is contained in:
Hanmac
2018-04-17 08:06:40 +02:00
parent 79c9c914e2
commit eda7fee2c6

View File

@@ -1145,15 +1145,14 @@ public class AiController {
} }
CardCollection landsWannaPlay = ComputerUtilAbility.getAvailableLandsToPlay(game, player); CardCollection landsWannaPlay = ComputerUtilAbility.getAvailableLandsToPlay(game, player);
CardCollection playBeforeLand = CardLists.filter(player.getCardsIn(ZoneType.Hand), new Predicate<Card>() { CardCollection playBeforeLand = CardLists.filter(
@Override player.getCardsIn(ZoneType.Hand), CardPredicates.hasSVar("PlayBeforeLandDrop")
public boolean apply(Card card) { );
return "true".equalsIgnoreCase(card.getSVar("PlayBeforeLandDrop"));
}
});
if (!playBeforeLand.isEmpty()) { if (!playBeforeLand.isEmpty()) {
SpellAbility wantToPlayBeforeLand = chooseSpellAbilityToPlayFromList(ComputerUtilAbility.getSpellAbilities(playBeforeLand, player), false); SpellAbility wantToPlayBeforeLand = chooseSpellAbilityToPlayFromList(
ComputerUtilAbility.getSpellAbilities(playBeforeLand, player), false
);
if (wantToPlayBeforeLand != null) { if (wantToPlayBeforeLand != null) {
return singleSpellAbilityList(wantToPlayBeforeLand); return singleSpellAbilityList(wantToPlayBeforeLand);
} }
@@ -1163,18 +1162,28 @@ public class AiController {
landsWannaPlay = filterLandsToPlay(landsWannaPlay); landsWannaPlay = filterLandsToPlay(landsWannaPlay);
Log.debug("Computer " + game.getPhaseHandler().getPhase().nameForUi); Log.debug("Computer " + game.getPhaseHandler().getPhase().nameForUi);
if (landsWannaPlay != null && !landsWannaPlay.isEmpty() && player.canPlayLand(null)) { if (landsWannaPlay != null && !landsWannaPlay.isEmpty() && player.canPlayLand(null)) {
// TODO search for other land it might want to play?
Card land = chooseBestLandToPlay(landsWannaPlay); Card land = chooseBestLandToPlay(landsWannaPlay);
if (ComputerUtil.getDamageFromETB(player, land) < player.getLife() || !player.canLoseLife() if (ComputerUtil.getDamageFromETB(player, land) < player.getLife() || !player.canLoseLife()
|| player.cantLoseForZeroOrLessLife() ) { || player.cantLoseForZeroOrLessLife() ) {
if (!game.getPhaseHandler().is(PhaseType.MAIN1) || !isSafeToHoldLandDropForMain2(land)) { if (!game.getPhaseHandler().is(PhaseType.MAIN1) || !isSafeToHoldLandDropForMain2(land)) {
// TODO fix logic for mayPlay land
LandAbility la = new LandAbility(land);
final List<SpellAbility> abilities = Lists.newArrayList(); final List<SpellAbility> abilities = Lists.newArrayList();
LandAbility la = new LandAbility(land, player, null);
if (la.canPlay()) { if (la.canPlay()) {
abilities.add(la); abilities.add(la);
} }
return abilities;
// add mayPlay option
for (CardPlayOption o : land.mayPlay(player)) {
la = new LandAbility(land, player, o.getAbility());
if (la.canPlay()) {
abilities.add(la);
}
}
if (!abilities.isEmpty()) {
return abilities;
}
} }
} }
} }