Merge branch 'mayPlayLand' into 'master'

May play land

See merge request core-developers/forge!415
This commit is contained in:
Michael Kamensky
2018-04-17 14:54:04 +00:00
11 changed files with 225 additions and 76 deletions

View File

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

View File

@@ -448,8 +448,10 @@ public class PlayerControllerAi extends PlayerController {
@Override
public void playChosenSpellAbility(SpellAbility sa) {
// System.out.println("Playing sa: " + sa);
if (sa == sa.getHostCard().getGame().PLAY_LAND_SURROGATE) {
player.playLand(sa.getHostCard(), false);
if (sa instanceof LandAbility) {
if (sa.canPlay()) {
sa.resolve();
}
} else {
ComputerUtil.handlePlayingSpellAbility(player, sa, game);
}

View File

@@ -11,11 +11,10 @@ import forge.game.Game;
import forge.game.ability.ApiType;
import forge.game.ability.effects.CharmEffect;
import forge.game.card.*;
import forge.game.cost.Cost;
import forge.game.phase.PhaseType;
import forge.game.player.Player;
import forge.game.spellability.Ability;
import forge.game.spellability.AbilitySub;
import forge.game.spellability.LandAbility;
import forge.game.spellability.SpellAbility;
import forge.game.spellability.SpellAbilityCondition;
import forge.game.zone.ZoneType;
@@ -115,18 +114,10 @@ public class SpellAbilityPicker {
printPhaseInfo();
SpellAbility sa = getPlannedSpellAbility(origGameScore, candidateSAs);
if (sa != null) {
return transformSA(sa);
return sa;
}
createNewPlan(origGameScore, candidateSAs);
return transformSA(getPlannedSpellAbility(origGameScore, candidateSAs));
}
private SpellAbility transformSA(SpellAbility sa) {
if (sa instanceof PlayLandAbility) {
game.PLAY_LAND_SURROGATE.setHostCard(sa.getHostCard());
return game.PLAY_LAND_SURROGATE;
}
return sa;
return getPlannedSpellAbility(origGameScore, candidateSAs);
}
private Plan formulatePlanWithPhase(Score origGameScore, List<SpellAbility> candidateSAs, PhaseType phase) {
@@ -456,20 +447,11 @@ public class SpellAbilityPicker {
return ComputerUtil.chooseSacrificeType(player, type, ability, ability.getTargetCard(), amount);
}
public static class PlayLandAbility extends Ability {
public static class PlayLandAbility extends LandAbility {
public PlayLandAbility(Card land) {
super(null, (Cost) null);
setHostCard(land);
}
@Override
public boolean canPlay() {
return true; //if this ability is added anywhere, it can be assumed that land can be played
}
@Override
public void resolve() {
throw new RuntimeException("This ability is intended to indicate \"land to play\" choice only");
super(land);
}
@Override
public String toUnsuppressedString() { return "Play land " + (getHostCard() != null ? getHostCard().getName() : ""); }
}