remove calls to gui from game code

This commit is contained in:
Maxmtg
2013-12-22 22:36:36 +00:00
parent 446dfd2257
commit 32b0f8333d
9 changed files with 78 additions and 93 deletions

View File

@@ -1,5 +1,6 @@
package forge.ai.ability;
import java.util.Collection;
import java.util.List;
import java.util.Random;
@@ -296,4 +297,9 @@ public class UntapAi extends SpellAbilityAi {
return true;
}
@Override
public Card chooseSingleCard(Player ai, SpellAbility sa, Collection<Card> list, boolean isOptional, Player targetedPlayer) {
return ComputerUtilCard.getBestLandAI(list);
}
}

View File

@@ -5,7 +5,6 @@ import forge.game.PlanarDice;
import forge.game.ability.SpellAbilityEffect;
import forge.game.player.Player;
import forge.game.spellability.SpellAbility;
import forge.gui.GuiDialog;
/**
* TODO: Write javadoc for this type.
@@ -26,8 +25,8 @@ public class RollPlanarDiceEffect extends SpellAbilityEffect {
game.getPhaseHandler().incPlanarDiceRolledthisTurn();
}
PlanarDice result = PlanarDice.roll(activator, null);
GuiDialog.message(activator.getName() + " rolled " + result.toString());
String message = activator.getName() + " rolled " + result.toString();
game.getAction().nofityOfValue(sa, activator, message, null);
}
}

View File

@@ -4,7 +4,6 @@ import java.util.List;
import org.apache.commons.lang3.StringUtils;
import forge.ai.ComputerUtilCard;
import forge.game.ability.AbilityUtils;
import forge.game.ability.SpellAbilityEffect;
import forge.game.card.Card;
@@ -14,8 +13,7 @@ import forge.game.player.Player;
import forge.game.spellability.SpellAbility;
import forge.game.spellability.TargetRestrictions;
import forge.game.zone.ZoneType;
import forge.gui.input.InputSelectCards;
import forge.gui.input.InputSelectCardsFromList;
public class UntapEffect extends SpellAbilityEffect {
@@ -80,19 +78,10 @@ public class UntapEffect extends SpellAbilityEffect {
List<Card> list = CardLists.getType(p.getCardsIn(ZoneType.Battlefield), valid);
list = CardLists.filter(list, Presets.TAPPED);
if (p.isHuman()) {
InputSelectCards sc = new InputSelectCardsFromList(0, num, list);
sc.showAndWait();
if( !sc.hasCancelled() )
for( Card c : sc.getSelected() )
c.untap();
} else {
for (int count = 0; !list.isEmpty() && count < num; count++) {
final Card c = ComputerUtilCard.getBestLandAI(list);
List<Card> selected = p.getController().chooseCardsForEffect(list, sa, "Select cards to untap", num, true);
if( selected != null )
for( Card c : selected )
c.untap();
list.remove(c);
}
}
}
}

View File

@@ -53,6 +53,7 @@ import forge.game.event.GameEventGameRestarted;
import forge.game.event.GameEventManaBurn;
import forge.game.event.GameEventTurnPhase;
import forge.game.player.Player;
import forge.game.player.PlayerController.BinaryChoiceType;
import forge.game.player.PlayerController.ManaPaymentPurpose;
import forge.game.spellability.SpellAbility;
import forge.game.staticability.StaticAbility;
@@ -778,44 +779,50 @@ public class PhaseHandler implements java.io.Serializable {
* @return a {@link forge.game.player.Player} object.
*/
private Player getNextActivePlayer() {
Player nextTurn = game.getNextPlayerAfter(this.getPlayerTurn());
if (!this.extraTurns.isEmpty()) {
ExtraTurn extraTurn = this.extraTurns.pop();
nextTurn = extraTurn.getPlayer();
ExtraTurn extraTurn = !this.extraTurns.isEmpty() ? this.extraTurns.pop() : null;
Player nextPlayer = extraTurn != null ? extraTurn.getPlayer() : game.getNextPlayerAfter(this.getPlayerTurn());
if (extraTurn != null) {
// The bottom of the extra turn stack is the normal turn
nextTurn.setExtraTurn(!this.extraTurns.isEmpty());
if (nextTurn.hasKeyword("If you would begin an extra turn, skip that turn instead.")) {
nextPlayer.setExtraTurn(!this.extraTurns.isEmpty());
if (nextPlayer.hasKeyword("If you would begin an extra turn, skip that turn instead.")) {
return getNextActivePlayer();
}
if (nextTurn.hasKeyword("Skip your next turn.")) {
nextTurn.removeKeyword("Skip your next turn.");
return getNextActivePlayer();
}
if (nextTurn.skipTurnTimeVault()) {
} else
nextPlayer.setExtraTurn(false);
if (nextPlayer.hasKeyword("Skip your next turn.")) {
nextPlayer.removeKeyword("Skip your next turn.");
if( null == extraTurn )
this.setPlayerTurn(nextPlayer);
return getNextActivePlayer();
}
List<Card> vaults = CardLists.filter(nextPlayer.getCardsIn(ZoneType.Battlefield, "Time Vault"), Presets.TAPPED);
if(!vaults.isEmpty()) {
final Card crd = vaults.get(0);
boolean untapTimeVault = nextPlayer.getController().chooseBinary(new SpellAbility.EmptySa(crd, nextPlayer), "Untap " + crd + "?", BinaryChoiceType.UntapTimeVault, false);
if (untapTimeVault) {
if( null == extraTurn )
this.setPlayerTurn(nextPlayer);
return getNextActivePlayer();
}
}
if (extraTurn != null) {
if (extraTurn.isLoseAtEndStep()) {
nextTurn.addKeyword("At the beginning of this turn's end step, you lose the game.");
nextPlayer.addKeyword("At the beginning of this turn's end step, you lose the game.");
}
if (extraTurn.isSkipUntap()) {
nextTurn.addKeyword("Skip the untap step of this turn.");
nextPlayer.addKeyword("Skip the untap step of this turn.");
}
if (extraTurn.isCantSetSchemesInMotion()) {
nextTurn.addKeyword("Schemes can't be set in motion this turn.");
nextPlayer.addKeyword("Schemes can't be set in motion this turn.");
}
return nextTurn;
}
nextTurn.setExtraTurn(false);
if (nextTurn.hasKeyword("Skip your next turn.")) {
nextTurn.removeKeyword("Skip your next turn.");
this.setPlayerTurn(nextTurn);
return getNextActivePlayer();
}
if (nextTurn.skipTurnTimeVault()) {
this.setPlayerTurn(nextTurn);
return getNextActivePlayer();
}
return nextTurn;
return nextPlayer;
}
/**

View File

@@ -69,8 +69,6 @@ import forge.game.zone.PlayerZone;
import forge.game.zone.PlayerZoneBattlefield;
import forge.game.zone.Zone;
import forge.game.zone.ZoneType;
import forge.gui.GuiDialog;
import forge.gui.GuiDisplayUtil;
import forge.properties.ForgePreferences.FPref;
import forge.util.Lang;
import forge.util.MyRandom;
@@ -204,10 +202,8 @@ public class Player extends GameEntity implements Comparable<Player> {
public Player(String name, Game game0) {
game = game0;
for (final ZoneType z : Player.ALL_ZONES) {
final PlayerZone toPut = z == ZoneType.Battlefield
? new PlayerZoneBattlefield(z, this)
: new PlayerZone(z, this);
this.zones.put(z, toPut);
final PlayerZone toPut = z == ZoneType.Battlefield ? new PlayerZoneBattlefield(z, this) : new PlayerZone(z, this);
this.zones.put(z, toPut);
}
if (isHotSeatGame(game)) {
@@ -217,7 +213,7 @@ public class Player extends GameEntity implements Comparable<Player> {
this.setName("Player 2");
}
} else {
this.setName(chooseName(GuiDisplayUtil.personalizeHuman(name)));
this.setName(chooseName(name));
}
}
@@ -2972,33 +2968,6 @@ public class Player extends GameEntity implements Comparable<Player> {
return false;
}
/**
* <p>
* skipTurnTimeVault.
* </p>
*
* @return a {@link forge.game.player.Player} object.
*/
public boolean skipTurnTimeVault() {
// time vault:
List<Card> vaults = getCardsIn(ZoneType.Battlefield, "Time Vault");
vaults = CardLists.filter(vaults, Presets.TAPPED);
if (vaults.size() > 0) {
final Card crd = vaults.get(0);
if (isHuman()) {
if (GuiDialog.confirm(crd, "Untap " + crd + "?")) {
crd.untap();
return true;
}
} else {
// TODO Should AI skip his turn for time vault?
}
}
return false;
}
public int getStartingHandSize() {
return this.startingHandSize;

View File

@@ -57,6 +57,7 @@ public abstract class PlayerController {
PlayOrDraw,
OddsOrEvens,
UntapOrLeaveTapped,
UntapTimeVault,
}
protected final Game game;
@@ -101,16 +102,7 @@ public abstract class PlayerController {
public LobbyPlayer getLobbyPlayer() { return lobbyPlayer; }
/**
* Uses GUI to learn which spell the player (human in our case) would like to play
*/
public final SpellAbility getAbilityToPlay(List<SpellAbility> abilities) {
return getAbilityToPlay(abilities, null);
}
/**
* Uses GUI to learn which spell the player (human in our case) would like to play
*/
public final SpellAbility getAbilityToPlay(List<SpellAbility> abilities) { return getAbilityToPlay(abilities, null); }
public abstract SpellAbility getAbilityToPlay(List<SpellAbility> abilities, MouseEvent triggerEvent);
/**

View File

@@ -487,9 +487,13 @@ public class PlayerControllerAi extends PlayerController {
@Override
public boolean chooseBinary(SpellAbility sa, String question, BinaryChoiceType kindOfChoice, Boolean defaultVal) {
if (kindOfChoice == BinaryChoiceType.TapOrUntap) { return true; }
if (kindOfChoice == BinaryChoiceType.UntapOrLeaveTapped) { return defaultVal != null && defaultVal.booleanValue(); }
return MyRandom.getRandom().nextBoolean();
switch(kindOfChoice) {
case TapOrUntap: return true;
case UntapOrLeaveTapped: return defaultVal != null && defaultVal.booleanValue();
case UntapTimeVault: return false; // TODO Should AI skip his turn for time vault?
default:
return MyRandom.getRandom().nextBoolean();
}
}
@Override

View File

@@ -6,6 +6,7 @@ import forge.game.player.Player;
import forge.game.player.PlayerController;
import forge.game.player.PlayerType;
import forge.gui.FNetOverlay;
import forge.gui.GuiDisplayUtil;
public class LobbyPlayerHuman extends LobbyPlayer {
public LobbyPlayerHuman(String name) {
@@ -24,7 +25,7 @@ public class LobbyPlayerHuman extends LobbyPlayer {
@Override
public Player getPlayer(Game game) {
Player player = new Player(getName(), game);
Player player = new Player(GuiDisplayUtil.personalizeHuman(getName()), game);
player.setFirstController(new PlayerControllerHuman(game, player, this));
return player;
}

View File

@@ -338,8 +338,25 @@ public class PlayerControllerHuman extends PlayerController {
if (amount == 1) {
return Lists.newArrayList(chooseSingleCardForEffect(sourceList, sa, title, isOptional));
}
GuiUtils.setPanelSelection(sa.getSourceCard());
// try to use InputSelectCardsFromList when possible
boolean cardsAreInMyHandOrBattlefield = true;
for(Card c : sourceList) {
Zone z = c.getZone();
if ( z != null && ( z.is(ZoneType.Battlefield) || z.is(ZoneType.Hand, player)))
continue;
cardsAreInMyHandOrBattlefield = false;
break;
}
if(cardsAreInMyHandOrBattlefield) {
InputSelectCards sc = new InputSelectCardsFromList(isOptional ? 0 : amount, amount, sourceList);
sc.setCancelAllowed(isOptional);
sc.showAndWait();
return sc.hasCancelled() ? Lists.<Card>newArrayList() : sc.getSelected();
}
int remaining = isOptional ? -1 : Math.max(sourceList.size() - amount, 0);
return GuiChoose.order(title, "Chosen Cards", remaining, sourceList, null, sa.getSourceCard());
}
@@ -780,6 +797,7 @@ public class PlayerControllerHuman extends PlayerController {
case TapOrUntap: labels = new String[]{"Tap", "Untap"}; break;
case OddsOrEvens: labels = new String[]{"Odds", "Evens"}; break;
case UntapOrLeaveTapped: labels = new String[]{"Untap", "Leave tapped"}; break;
case UntapTimeVault: labels = new String[]{"Untap (and skip this turn)", "Leave tapped"}; break;
case PlayOrDraw: labels = new String[]{"Play", "Draw"}; break;
}
return GuiDialog.confirm(sa.getSourceCard(), question, defaultVal == null || defaultVal.booleanValue(), labels);