mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
remove calls to gui from game code
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@@ -296,4 +297,9 @@ public class UntapAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Card chooseSingleCard(Player ai, SpellAbility sa, Collection<Card> list, boolean isOptional, Player targetedPlayer) {
|
||||||
|
return ComputerUtilCard.getBestLandAI(list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import forge.game.PlanarDice;
|
|||||||
import forge.game.ability.SpellAbilityEffect;
|
import forge.game.ability.SpellAbilityEffect;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.gui.GuiDialog;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Write javadoc for this type.
|
* TODO: Write javadoc for this type.
|
||||||
@@ -26,8 +25,8 @@ public class RollPlanarDiceEffect extends SpellAbilityEffect {
|
|||||||
game.getPhaseHandler().incPlanarDiceRolledthisTurn();
|
game.getPhaseHandler().incPlanarDiceRolledthisTurn();
|
||||||
}
|
}
|
||||||
PlanarDice result = PlanarDice.roll(activator, null);
|
PlanarDice result = PlanarDice.roll(activator, null);
|
||||||
|
String message = activator.getName() + " rolled " + result.toString();
|
||||||
GuiDialog.message(activator.getName() + " rolled " + result.toString());
|
game.getAction().nofityOfValue(sa, activator, message, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import forge.ai.ComputerUtilCard;
|
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.ability.SpellAbilityEffect;
|
import forge.game.ability.SpellAbilityEffect;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
@@ -14,8 +13,7 @@ import forge.game.player.Player;
|
|||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.game.spellability.TargetRestrictions;
|
import forge.game.spellability.TargetRestrictions;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.gui.input.InputSelectCards;
|
|
||||||
import forge.gui.input.InputSelectCardsFromList;
|
|
||||||
|
|
||||||
public class UntapEffect extends SpellAbilityEffect {
|
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<Card> list = CardLists.getType(p.getCardsIn(ZoneType.Battlefield), valid);
|
||||||
list = CardLists.filter(list, Presets.TAPPED);
|
list = CardLists.filter(list, Presets.TAPPED);
|
||||||
|
|
||||||
if (p.isHuman()) {
|
List<Card> selected = p.getController().chooseCardsForEffect(list, sa, "Select cards to untap", num, true);
|
||||||
InputSelectCards sc = new InputSelectCardsFromList(0, num, list);
|
if( selected != null )
|
||||||
sc.showAndWait();
|
for( Card c : selected )
|
||||||
if( !sc.hasCancelled() )
|
|
||||||
for( Card c : sc.getSelected() )
|
|
||||||
c.untap();
|
c.untap();
|
||||||
} else {
|
|
||||||
for (int count = 0; !list.isEmpty() && count < num; count++) {
|
|
||||||
final Card c = ComputerUtilCard.getBestLandAI(list);
|
|
||||||
c.untap();
|
|
||||||
list.remove(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ import forge.game.event.GameEventGameRestarted;
|
|||||||
import forge.game.event.GameEventManaBurn;
|
import forge.game.event.GameEventManaBurn;
|
||||||
import forge.game.event.GameEventTurnPhase;
|
import forge.game.event.GameEventTurnPhase;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
|
import forge.game.player.PlayerController.BinaryChoiceType;
|
||||||
import forge.game.player.PlayerController.ManaPaymentPurpose;
|
import forge.game.player.PlayerController.ManaPaymentPurpose;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.game.staticability.StaticAbility;
|
import forge.game.staticability.StaticAbility;
|
||||||
@@ -778,44 +779,50 @@ public class PhaseHandler implements java.io.Serializable {
|
|||||||
* @return a {@link forge.game.player.Player} object.
|
* @return a {@link forge.game.player.Player} object.
|
||||||
*/
|
*/
|
||||||
private Player getNextActivePlayer() {
|
private Player getNextActivePlayer() {
|
||||||
Player nextTurn = game.getNextPlayerAfter(this.getPlayerTurn());
|
|
||||||
if (!this.extraTurns.isEmpty()) {
|
ExtraTurn extraTurn = !this.extraTurns.isEmpty() ? this.extraTurns.pop() : null;
|
||||||
ExtraTurn extraTurn = this.extraTurns.pop();
|
Player nextPlayer = extraTurn != null ? extraTurn.getPlayer() : game.getNextPlayerAfter(this.getPlayerTurn());
|
||||||
nextTurn = extraTurn.getPlayer();
|
|
||||||
|
if (extraTurn != null) {
|
||||||
// The bottom of the extra turn stack is the normal turn
|
// The bottom of the extra turn stack is the normal turn
|
||||||
nextTurn.setExtraTurn(!this.extraTurns.isEmpty());
|
nextPlayer.setExtraTurn(!this.extraTurns.isEmpty());
|
||||||
if (nextTurn.hasKeyword("If you would begin an extra turn, skip that turn instead.")) {
|
if (nextPlayer.hasKeyword("If you would begin an extra turn, skip that turn instead.")) {
|
||||||
return getNextActivePlayer();
|
return getNextActivePlayer();
|
||||||
}
|
}
|
||||||
if (nextTurn.hasKeyword("Skip your next turn.")) {
|
} else
|
||||||
nextTurn.removeKeyword("Skip your next turn.");
|
nextPlayer.setExtraTurn(false);
|
||||||
|
|
||||||
|
if (nextPlayer.hasKeyword("Skip your next turn.")) {
|
||||||
|
nextPlayer.removeKeyword("Skip your next turn.");
|
||||||
|
if( null == extraTurn )
|
||||||
|
this.setPlayerTurn(nextPlayer);
|
||||||
return getNextActivePlayer();
|
return getNextActivePlayer();
|
||||||
}
|
}
|
||||||
if (nextTurn.skipTurnTimeVault()) {
|
|
||||||
|
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();
|
return getNextActivePlayer();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (extraTurn != null) {
|
||||||
if (extraTurn.isLoseAtEndStep()) {
|
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()) {
|
if (extraTurn.isSkipUntap()) {
|
||||||
nextTurn.addKeyword("Skip the untap step of this turn.");
|
nextPlayer.addKeyword("Skip the untap step of this turn.");
|
||||||
}
|
}
|
||||||
if (extraTurn.isCantSetSchemesInMotion()) {
|
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.")) {
|
return nextPlayer;
|
||||||
nextTurn.removeKeyword("Skip your next turn.");
|
|
||||||
this.setPlayerTurn(nextTurn);
|
|
||||||
return getNextActivePlayer();
|
|
||||||
}
|
|
||||||
if (nextTurn.skipTurnTimeVault()) {
|
|
||||||
this.setPlayerTurn(nextTurn);
|
|
||||||
return getNextActivePlayer();
|
|
||||||
}
|
|
||||||
return nextTurn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -69,8 +69,6 @@ import forge.game.zone.PlayerZone;
|
|||||||
import forge.game.zone.PlayerZoneBattlefield;
|
import forge.game.zone.PlayerZoneBattlefield;
|
||||||
import forge.game.zone.Zone;
|
import forge.game.zone.Zone;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.gui.GuiDialog;
|
|
||||||
import forge.gui.GuiDisplayUtil;
|
|
||||||
import forge.properties.ForgePreferences.FPref;
|
import forge.properties.ForgePreferences.FPref;
|
||||||
import forge.util.Lang;
|
import forge.util.Lang;
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
@@ -204,9 +202,7 @@ public class Player extends GameEntity implements Comparable<Player> {
|
|||||||
public Player(String name, Game game0) {
|
public Player(String name, Game game0) {
|
||||||
game = game0;
|
game = game0;
|
||||||
for (final ZoneType z : Player.ALL_ZONES) {
|
for (final ZoneType z : Player.ALL_ZONES) {
|
||||||
final PlayerZone toPut = z == ZoneType.Battlefield
|
final PlayerZone toPut = z == ZoneType.Battlefield ? new PlayerZoneBattlefield(z, this) : new PlayerZone(z, this);
|
||||||
? new PlayerZoneBattlefield(z, this)
|
|
||||||
: new PlayerZone(z, this);
|
|
||||||
this.zones.put(z, toPut);
|
this.zones.put(z, toPut);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,7 +213,7 @@ public class Player extends GameEntity implements Comparable<Player> {
|
|||||||
this.setName("Player 2");
|
this.setName("Player 2");
|
||||||
}
|
}
|
||||||
} else {
|
} 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;
|
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() {
|
public int getStartingHandSize() {
|
||||||
|
|
||||||
return this.startingHandSize;
|
return this.startingHandSize;
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ public abstract class PlayerController {
|
|||||||
PlayOrDraw,
|
PlayOrDraw,
|
||||||
OddsOrEvens,
|
OddsOrEvens,
|
||||||
UntapOrLeaveTapped,
|
UntapOrLeaveTapped,
|
||||||
|
UntapTimeVault,
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final Game game;
|
protected final Game game;
|
||||||
@@ -101,16 +102,7 @@ public abstract class PlayerController {
|
|||||||
|
|
||||||
public LobbyPlayer getLobbyPlayer() { return lobbyPlayer; }
|
public LobbyPlayer getLobbyPlayer() { return lobbyPlayer; }
|
||||||
|
|
||||||
/**
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Uses GUI to learn which spell the player (human in our case) would like to play
|
|
||||||
*/
|
|
||||||
public abstract SpellAbility getAbilityToPlay(List<SpellAbility> abilities, MouseEvent triggerEvent);
|
public abstract SpellAbility getAbilityToPlay(List<SpellAbility> abilities, MouseEvent triggerEvent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -487,10 +487,14 @@ public class PlayerControllerAi extends PlayerController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean chooseBinary(SpellAbility sa, String question, BinaryChoiceType kindOfChoice, Boolean defaultVal) {
|
public boolean chooseBinary(SpellAbility sa, String question, BinaryChoiceType kindOfChoice, Boolean defaultVal) {
|
||||||
if (kindOfChoice == BinaryChoiceType.TapOrUntap) { return true; }
|
switch(kindOfChoice) {
|
||||||
if (kindOfChoice == BinaryChoiceType.UntapOrLeaveTapped) { return defaultVal != null && defaultVal.booleanValue(); }
|
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();
|
return MyRandom.getRandom().nextBoolean();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Card chooseProtectionShield(GameEntity entityBeingDamaged, List<String> options, Map<String, Card> choiceMap) {
|
public Card chooseProtectionShield(GameEntity entityBeingDamaged, List<String> options, Map<String, Card> choiceMap) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import forge.game.player.Player;
|
|||||||
import forge.game.player.PlayerController;
|
import forge.game.player.PlayerController;
|
||||||
import forge.game.player.PlayerType;
|
import forge.game.player.PlayerType;
|
||||||
import forge.gui.FNetOverlay;
|
import forge.gui.FNetOverlay;
|
||||||
|
import forge.gui.GuiDisplayUtil;
|
||||||
|
|
||||||
public class LobbyPlayerHuman extends LobbyPlayer {
|
public class LobbyPlayerHuman extends LobbyPlayer {
|
||||||
public LobbyPlayerHuman(String name) {
|
public LobbyPlayerHuman(String name) {
|
||||||
@@ -24,7 +25,7 @@ public class LobbyPlayerHuman extends LobbyPlayer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Player getPlayer(Game game) {
|
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));
|
player.setFirstController(new PlayerControllerHuman(game, player, this));
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -338,8 +338,25 @@ public class PlayerControllerHuman extends PlayerController {
|
|||||||
if (amount == 1) {
|
if (amount == 1) {
|
||||||
return Lists.newArrayList(chooseSingleCardForEffect(sourceList, sa, title, isOptional));
|
return Lists.newArrayList(chooseSingleCardForEffect(sourceList, sa, title, isOptional));
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiUtils.setPanelSelection(sa.getSourceCard());
|
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);
|
int remaining = isOptional ? -1 : Math.max(sourceList.size() - amount, 0);
|
||||||
return GuiChoose.order(title, "Chosen Cards", remaining, sourceList, null, sa.getSourceCard());
|
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 TapOrUntap: labels = new String[]{"Tap", "Untap"}; break;
|
||||||
case OddsOrEvens: labels = new String[]{"Odds", "Evens"}; break;
|
case OddsOrEvens: labels = new String[]{"Odds", "Evens"}; break;
|
||||||
case UntapOrLeaveTapped: labels = new String[]{"Untap", "Leave tapped"}; 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;
|
case PlayOrDraw: labels = new String[]{"Play", "Draw"}; break;
|
||||||
}
|
}
|
||||||
return GuiDialog.confirm(sa.getSourceCard(), question, defaultVal == null || defaultVal.booleanValue(), labels);
|
return GuiDialog.confirm(sa.getSourceCard(), question, defaultVal == null || defaultVal.booleanValue(), labels);
|
||||||
|
|||||||
Reference in New Issue
Block a user