GameView: do not store Game anymore, get it from Match

This commit is contained in:
Hans Mackowiak
2020-11-28 19:02:33 +01:00
parent 70e75bde91
commit 88c017f962
18 changed files with 274 additions and 238 deletions

View File

@@ -213,7 +213,7 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
if(FModel.getPreferences().getPrefBoolean(ForgePreferences.FPref.FILTERED_HANDS)){
baseLandParameter--;
}
landsNeeded = new Double((baseLandParameter + 3.14f * avCMC) * targetSize/60f).intValue();
landsNeeded = Double.valueOf((baseLandParameter + 3.14f * avCMC) * targetSize/60f).intValue();
if (logToConsole) {
System.out.println("Required lands from linear regression : " + avCMC + " cmc, needed: " + landsNeeded);
}
@@ -425,8 +425,6 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
@Override
public boolean apply(CardRules subject) {
ManaCost mc = subject.getManaCost();
boolean generic = mc.isPureGeneric();
return ((allowedColor.containsAllColorsFrom(subject.getColorIdentity().getColor())));
}
}

View File

@@ -149,7 +149,7 @@ public class HostedMatch {
if (game.getRules().getGameType() == GameType.Quest) {
final QuestController qc = FModel.getQuest();
// Reset new list when the Match round starts, not when each game starts
if (game.getMatch().getPlayedGames().isEmpty()) {
if (game.getMatch().getOutcomes().isEmpty()) {
qc.getCards().resetNewList();
}
game.subscribeToEvents(qc); // this one listens to player's mulligans ATM

View File

@@ -4,7 +4,6 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import forge.FThreads;
import forge.game.Game;
import forge.game.card.Card;
import forge.game.player.Player;
import forge.game.player.PlayerView;
@@ -17,10 +16,8 @@ public class InputLockUI implements Input {
private final AtomicInteger iCall = new AtomicInteger();
private final InputQueue inputQueue;
private final Game game;
private final PlayerControllerHuman controller;
public InputLockUI(final Game game0, final InputQueue inputQueue0, final PlayerControllerHuman controller) {
game = game0;
public InputLockUI(final InputQueue inputQueue0, final PlayerControllerHuman controller) {
inputQueue = inputQueue0;
this.controller = controller;
}
@@ -90,7 +87,7 @@ public class InputLockUI implements Input {
@Override
public void selectButtonCancel() {
//cancel auto pass for all players
for (final Player player : game.getPlayers()) {
for (final Player player : controller.getGame().getPlayers()) {
player.getController().autoPassCancel();
}
}

View File

@@ -21,7 +21,7 @@ import java.util.Observable;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
import forge.game.Game;
import forge.game.GameView;
import forge.player.PlayerControllerHuman;
/**
@@ -34,10 +34,10 @@ import forge.player.PlayerControllerHuman;
*/
public class InputQueue extends Observable {
private final BlockingDeque<InputSynchronized> inputStack = new LinkedBlockingDeque<>();
private final Game game;
private final GameView gameView;
public InputQueue(final Game game, final InputProxy inputProxy) {
this.game = game;
public InputQueue(final GameView gameView, final InputProxy inputProxy) {
this.gameView = gameView;
addObserver(inputProxy);
}
@@ -64,10 +64,10 @@ public class InputQueue extends Observable {
public final Input getActualInput(final PlayerControllerHuman controller) {
final Input topMost = inputStack.peek(); // incoming input to Control
if (topMost != null && !game.isGameOver()) {
if (topMost != null && !gameView.isGameOver()) {
return topMost;
}
return new InputLockUI(game, this, controller);
return new InputLockUI(this, controller);
} // getInput()
// only for debug purposes

View File

@@ -5,6 +5,8 @@ import java.util.*;
import java.util.Map.Entry;
import forge.game.ability.AbilityUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.Range;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -108,7 +110,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
public PlayerControllerHuman(final Game game0, final Player p, final LobbyPlayer lp) {
super(game0, p, lp);
inputProxy = new InputProxy(this);
inputQueue = new InputQueue(game, inputProxy);
inputQueue = new InputQueue(game0.getView(), inputProxy);
}
public PlayerControllerHuman(final Player p, final LobbyPlayer lp, final PlayerControllerHuman owner) {
@@ -268,19 +270,8 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
// Sideboard rules have changed for M14, just need to consider min
// maindeck and max sideboard sizes
// No longer need 1:1 sideboarding in non-limited formats
Object resp = getGui().sideboard(sideboard, main, message);
if (resp instanceof List<?> &&
!((List) resp).isEmpty() &&
((List) resp).get(0) instanceof PaperCard) {
newMain = (List) resp;
} else if (resp == null) {
// if we got here, the user took too long to reply
newMain = main.toFlatList();
} else {
System.err.println("PlayerControllerHuman.sideboard -- FAILED!");
System.err.println("resp instanceof " + resp.getClass().toString());
System.err.println("resp = " + resp.toString());
}
List<PaperCard> resp = getGui().sideboard(sideboard, main, message);
newMain = ObjectUtils.defaultIfNull(resp, main.toFlatList());
} while (conform && (newMain.size() < deckMinSize || combinedDeckSize - newMain.size() > sbMax));
return newMain;
@@ -667,8 +658,8 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
}
if (tos.containsKey(AbilityKey.Card)) {
final Card card = (Card) tos.get(AbilityKey.Card);
if (card != null && (card.getController() == player || game.getZoneOf(card) == null
|| game.getZoneOf(card).getZoneType().isKnown())) {
if (card != null && (card.getController() == player || getGame().getZoneOf(card) == null
|| getGame().getZoneOf(card).getZoneType().isKnown())) {
buildQuestion.append("\n").append(localizer.getMessage("lblTriggeredby")).append(": ").append(tos.get(AbilityKey.Card));
}
}
@@ -680,7 +671,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
@Override
public Player chooseStartingPlayer(final boolean isFirstGame) {
if (game.getPlayers().size() == 2) {
if (getGame().getPlayers().size() == 2) {
String prompt = null;
if (isFirstGame) {
prompt = localizer.getMessage("lblYouHaveWonTheCoinToss", player.getName());
@@ -702,7 +693,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
}
prompt += "\n\n" + localizer.getMessage("lblWhoWouldYouLiketoStartthisGame");
final InputSelectEntitiesFromList<Player> input = new InputSelectEntitiesFromList<>(this, 1, 1,
new FCollection<>(game.getPlayersInTurnOrder()));
new FCollection<>(getGame().getPlayersInTurnOrder()));
input.setMessage(prompt);
input.showAndWait();
return input.getFirstSelected();
@@ -922,7 +913,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
return cards;
case ForgeConstants.GRAVEYARD_ORDERING_OWN_CARDS:
// Order only if the relevant cards controlled by the player determine the potential necessity for it
if (!game.isGraveyardOrdered(player)) {
if (!getGame().isGraveyardOrdered(player)) {
return cards;
}
break;
@@ -1286,7 +1277,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
@Override
public List<SpellAbility> chooseSpellAbilityToPlay() {
final MagicStack stack = game.getStack();
final MagicStack stack = getGame().getStack();
if (mayAutoPass()) {
// avoid prompting for input if current phase is set to be
@@ -1297,8 +1288,8 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
if (stack.isEmpty()) {
// make sure to briefly pause at phases you're not set up to
// skip
if (!getGui().isUiSetToSkipPhase(game.getPhaseHandler().getPlayerTurn().getView(),
game.getPhaseHandler().getPhase())) {
if (!getGui().isUiSetToSkipPhase(getGame().getPhaseHandler().getPlayerTurn().getView(),
getGame().getPhaseHandler().getPhase())) {
delay = FControlGamePlayback.phasesDelay;
}
} else {
@@ -1317,8 +1308,8 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
}
if (stack.isEmpty()) {
if (getGui().isUiSetToSkipPhase(game.getPhaseHandler().getPlayerTurn().getView(),
game.getPhaseHandler().getPhase())) {
if (getGui().isUiSetToSkipPhase(getGame().getPhaseHandler().getPlayerTurn().getView(),
getGame().getPhaseHandler().getPhase())) {
return null; // avoid prompt for input if stack is empty and
// player is set to skip the current phase
}
@@ -1504,7 +1495,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
public void notifyOfValue(final SpellAbility sa, final GameObject realtedTarget, final String value) {
final String message = MessageUtil.formatNotificationMessage(sa, player, realtedTarget, value);
if (sa != null && sa.isManaAbility()) {
game.getGameLog().add(GameLogEntryType.LAND, message);
getGame().getGameLog().add(GameLogEntryType.LAND, message);
} else {
getGui().message(message,
sa == null || sa.getHostCard() == null ? "" : CardView.get(sa.getHostCard()).toString());
@@ -1522,14 +1513,14 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
@Override
public List<AbilitySub> chooseModeForAbility(final SpellAbility sa, List<AbilitySub> possible, final int min, final int num,
boolean allowRepeat) {
boolean trackerFrozen = game.getTracker().isFrozen();
boolean trackerFrozen = getGame().getTracker().isFrozen();
if (trackerFrozen) {
// The view tracker needs to be unfrozen to update the SpellAbilityViews at this point, or it may crash
game.getTracker().unfreeze();
getGame().getTracker().unfreeze();
}
Map<SpellAbilityView, AbilitySub> spellViewCache = SpellAbilityView.getMap(possible);
if (trackerFrozen) {
game.getTracker().freeze(); // refreeze if the tracker was frozen prior to this update
getGame().getTracker().freeze(); // refreeze if the tracker was frozen prior to this update
}
final List<SpellAbilityView> choices = Lists.newArrayList(spellViewCache.keySet());
final String modeTitle = localizer.getMessage("lblPlayerActivatedCardChooseMode", sa.getActivatingPlayer().toString(), CardTranslation.getTranslatedName(sa.getHostCard().getName()));
@@ -1894,10 +1885,10 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
}
public boolean canUndoLastAction() {
if (!game.stack.canUndo(player)) {
if (!getGame().stack.canUndo(player)) {
return false;
}
final Player priorityPlayer = game.getPhaseHandler().getPriorityPlayer();
final Player priorityPlayer = getGame().getPhaseHandler().getPriorityPlayer();
return priorityPlayer != null && priorityPlayer == player;
}
@@ -1911,7 +1902,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
return false;
}
if (game.getStack().undo()) {
if (getGame().getStack().undo()) {
final Input currentInput = inputQueue.getInput();
if (currentInput instanceof InputPassPriority) {
// ensure prompt updated if needed
@@ -2057,7 +2048,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
@Override
public void setViewAllCards(final boolean canViewAll) {
mayLookAtAllCards = canViewAll;
for (final Player p : game.getPlayers()) {
for (final Player p : getGame().getPlayers()) {
getGui().updateCards(CardView.getCollection(p.getAllCards()));
}
}
@@ -2069,18 +2060,18 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
*/
@Override
public void generateMana() {
final Player pPriority = game.getPhaseHandler().getPriorityPlayer();
final Player pPriority = getGame().getPhaseHandler().getPriorityPlayer();
if (pPriority == null) {
getGui().message(localizer.getMessage("lblNoPlayerHasPriorityCannotAddedManaToPool"));
return;
}
final Card dummy = new Card(-777777, game);
final Card dummy = new Card(-777777, getGame());
dummy.setOwner(pPriority);
final Map<String, String> produced = Maps.newHashMap();
produced.put("Produced", "W W W W W W W U U U U U U U B B B B B B B G G G G G G G R R R R R R R 7");
final AbilityManaPart abMana = new AbilityManaPart(dummy, produced);
game.getAction().invoke(new Runnable() {
getGame().getAction().invoke(new Runnable() {
@Override
public void run() {
abMana.produceMana(null);
@@ -2106,7 +2097,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
public void dumpGameState() {
final GameState state = createGameStateObject();
try {
state.initFromGame(game);
state.initFromGame(getGame());
final File f = GuiBase.getInterface().getSaveFile(new File(ForgeConstants.USER_GAMES_DIR, "state.txt"));
if (f != null
&& (!f.exists() || getGui().showConfirmDialog(localizer.getMessage("lblOverwriteExistFileConfirm"), localizer.getMessage("lblFileExists")))) {
@@ -2156,12 +2147,12 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
return;
}
final Player pPriority = game.getPhaseHandler().getPriorityPlayer();
final Player pPriority = getGame().getPhaseHandler().getPriorityPlayer();
if (pPriority == null) {
getGui().message(localizer.getMessage("lblNoPlayerPriorityGameStateCannotBeSetup"));
return;
}
state.applyToGame(game);
state.applyToGame(getGame());
}
/*
@@ -2171,7 +2162,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
*/
@Override
public void tutorForCard() {
final Player pPriority = game.getPhaseHandler().getPriorityPlayer();
final Player pPriority = getGame().getPhaseHandler().getPriorityPlayer();
if (pPriority == null) {
getGui().message(localizer.getMessage("lblNoPlayerPriorityDeckCantBeTutoredFrom"));
return;
@@ -2180,17 +2171,17 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
final CardCollection lib = (CardCollection) pPriority.getCardsIn(ZoneType.Library);
final List<ZoneType> origin = Lists.newArrayList();
origin.add(ZoneType.Library);
final SpellAbility sa = new SpellAbility.EmptySa(new Card(-1, game));
final SpellAbility sa = new SpellAbility.EmptySa(new Card(-1, getGame()));
final Card card = chooseSingleCardForZoneChange(ZoneType.Hand, origin, sa, lib, null, localizer.getMessage("lblChooseaCard"), true,
pPriority);
if (card == null) {
return;
}
game.getAction().invoke(new Runnable() {
getGame().getAction().invoke(new Runnable() {
@Override
public void run() {
game.getAction().moveToHand(card, null);
getGame().getAction().moveToHand(card, null);
}
});
}
@@ -2218,7 +2209,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
public void modifyCountersOnPermanent(boolean subtract) {
final String titleMsg = subtract ? localizer.getMessage("lblRemoveCountersFromWhichCard") : localizer.getMessage("lblAddCountersToWhichCard");
GameEntityViewMap<Card, CardView> gameCacheCounters = GameEntityView.getMap(game.getCardsIn(ZoneType.Battlefield));
GameEntityViewMap<Card, CardView> gameCacheCounters = GameEntityView.getMap(getGame().getCardsIn(ZoneType.Battlefield));
final CardView cv = getGui().oneOrNone(titleMsg, gameCacheCounters.getTrackableKeys());
if (cv == null || !gameCacheCounters.containsKey(cv)) {
@@ -2259,10 +2250,10 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
*/
@Override
public void tapPermanents() {
game.getAction().invoke(new Runnable() {
getGame().getAction().invoke(new Runnable() {
@Override
public void run() {
final CardCollectionView untapped = CardLists.filter(game.getCardsIn(ZoneType.Battlefield),
final CardCollectionView untapped = CardLists.filter(getGame().getCardsIn(ZoneType.Battlefield),
Predicates.not(CardPredicates.Presets.TAPPED));
final InputSelectCardsFromList inp = new InputSelectCardsFromList(PlayerControllerHuman.this, 0,
Integer.MAX_VALUE, untapped);
@@ -2285,10 +2276,10 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
*/
@Override
public void untapPermanents() {
game.getAction().invoke(new Runnable() {
getGame().getAction().invoke(new Runnable() {
@Override
public void run() {
final CardCollectionView tapped = CardLists.filter(game.getCardsIn(ZoneType.Battlefield),
final CardCollectionView tapped = CardLists.filter(getGame().getCardsIn(ZoneType.Battlefield),
CardPredicates.Presets.TAPPED);
final InputSelectCardsFromList inp = new InputSelectCardsFromList(PlayerControllerHuman.this, 0,
Integer.MAX_VALUE, tapped);
@@ -2312,7 +2303,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
@Override
public void setPlayerLife() {
GameEntityViewMap<Player, PlayerView> gameCachePlayer = GameEntityView.getMap(game.getPlayers());
GameEntityViewMap<Player, PlayerView> gameCachePlayer = GameEntityView.getMap(getGame().getPlayers());
final PlayerView pv = getGui().oneOrNone(localizer.getMessage("lblSetLifeforWhichPlayer"), gameCachePlayer.getTrackableKeys());
if (pv == null || !gameCachePlayer.containsKey(pv)) {
@@ -2343,7 +2334,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
// set life of all other players to 0
final LobbyPlayer guiPlayer = getLobbyPlayer();
final FCollectionView<Player> players = game.getPlayers();
final FCollectionView<Player> players = getGame().getPlayers();
for (final Player player : players) {
if (player.getLobbyPlayer() != guiPlayer) {
player.setLife(0, null);
@@ -2448,7 +2439,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
return;
}
} else {
GameEntityViewMap<Player, PlayerView> gameCachePlayer = GameEntityView.getMap(game.getPlayers());
GameEntityViewMap<Player, PlayerView> gameCachePlayer = GameEntityView.getMap(getGame().getPlayers());
PlayerView pv = getGui().oneOrNone(message, gameCachePlayer.getTrackableKeys());
if (pv == null || !gameCachePlayer.containsKey(pv)) {
return;
@@ -2470,9 +2461,9 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
final PaperCard c = carddb.getUniqueByName(f.getName());
final Card forgeCard = Card.fromPaperCard(c, p);
forgeCard.setTimestamp(game.getNextTimestamp());
forgeCard.setTimestamp(getGame().getNextTimestamp());
game.getAction().invoke(new Runnable() {
getGame().getAction().invoke(new Runnable() {
@Override
public void run() {
if (targetZone == ZoneType.Battlefield) {
@@ -2488,7 +2479,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
}
}
}
game.getAction().moveTo(targetZone, forgeCard, null);
getGame().getAction().moveTo(targetZone, forgeCard, null);
if (forgeCard.isCreature()) {
forgeCard.setSickness(lastSummoningSickness);
}
@@ -2499,10 +2490,10 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
} else {
if (c.getRules().getType().isLand()) {
// this is needed to ensure land abilities fire
game.getAction().moveToHand(forgeCard, null);
game.getAction().moveToPlay(forgeCard, null);
getGame().getAction().moveToHand(forgeCard, null);
getGame().getAction().moveToPlay(forgeCard, null);
// ensure triggered abilities fire
game.getTriggerHandler().runWaitingTriggers();
getGame().getTriggerHandler().runWaitingTriggers();
} else {
final FCollectionView<SpellAbility> choices = forgeCard.getBasicSpells();
if (choices.isEmpty()) {
@@ -2522,14 +2513,14 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
lastAddedSA = sa;
// this is really needed (for rollbacks at least)
game.getAction().moveToHand(forgeCard, null);
getGame().getAction().moveToHand(forgeCard, null);
// Human player is choosing targets for an ability
// controlled by chosen player.
sa.setActivatingPlayer(p);
HumanPlay.playSaWithoutPayingManaCost(PlayerControllerHuman.this, game, sa, true);
HumanPlay.playSaWithoutPayingManaCost(PlayerControllerHuman.this, getGame(), sa, true);
}
// playSa could fire some triggers
game.getStack().addAllTriggeredAbilitiesToStack();
getGame().getStack().addAllTriggeredAbilitiesToStack();
}
} else if (targetZone == ZoneType.Library) {
if (!repeatLast) {
@@ -2537,12 +2528,12 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
true, Arrays.asList(localizer.getMessage("lblTop"), localizer.getMessage("lblBottom")));
}
if (lastTopOfTheLibrary) {
game.getAction().moveToLibrary(forgeCard, null);
getGame().getAction().moveToLibrary(forgeCard, null);
} else {
game.getAction().moveToBottomOfLibrary(forgeCard, null);
getGame().getAction().moveToBottomOfLibrary(forgeCard, null);
}
} else {
game.getAction().moveTo(targetZone, forgeCard, null);
getGame().getAction().moveTo(targetZone, forgeCard, null);
}
lastAdded = f;
@@ -2560,7 +2551,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
*/
@Override
public void exileCardsFromHand() {
GameEntityViewMap<Player, PlayerView> gameCachePlayer = GameEntityView.getMap(game.getPlayers());
GameEntityViewMap<Player, PlayerView> gameCachePlayer = GameEntityView.getMap(getGame().getPlayers());
final PlayerView pv = getGui().oneOrNone(localizer.getMessage("lblExileCardsFromPlayerHandConfirm"),
gameCachePlayer.getTrackableKeys());
@@ -2581,12 +2572,12 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
if (c == null) {
continue;
}
if (game.getAction().moveTo(ZoneType.Exile, c, null) != null) {
if (getGame().getAction().moveTo(ZoneType.Exile, c, null) != null) {
StringBuilder sb = new StringBuilder();
sb.append(p).append(" exiles ").append(c).append(" due to Dev Cheats.");
game.getGameLog().add(GameLogEntryType.DISCARD, sb.toString());
getGame().getGameLog().add(GameLogEntryType.DISCARD, sb.toString());
} else {
game.getGameLog().add(GameLogEntryType.INFORMATION, "DISCARD CHEAT ERROR");
getGame().getGameLog().add(GameLogEntryType.INFORMATION, "DISCARD CHEAT ERROR");
}
}
}
@@ -2598,7 +2589,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
*/
@Override
public void exileCardsFromBattlefield() {
GameEntityViewMap<Player, PlayerView> gameCachePlayer = GameEntityView.getMap(game.getPlayers());
GameEntityViewMap<Player, PlayerView> gameCachePlayer = GameEntityView.getMap(getGame().getPlayers());
final PlayerView pv = getGui().oneOrNone(localizer.getMessage("lblExileCardsFromPlayerBattlefieldConfirm"),
gameCachePlayer.getTrackableKeys());
@@ -2619,12 +2610,12 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
if (c == null) {
continue;
}
if (game.getAction().moveTo(ZoneType.Exile, c, null) != null) {
if (getGame().getAction().moveTo(ZoneType.Exile, c, null) != null) {
StringBuilder sb = new StringBuilder();
sb.append(p).append(" exiles ").append(c).append(" due to Dev Cheats.");
game.getGameLog().add(GameLogEntryType.ZONE_CHANGE, sb.toString());
getGame().getGameLog().add(GameLogEntryType.ZONE_CHANGE, sb.toString());
} else {
game.getGameLog().add(GameLogEntryType.INFORMATION, "EXILE FROM PLAY CHEAT ERROR");
getGame().getGameLog().add(GameLogEntryType.INFORMATION, "EXILE FROM PLAY CHEAT ERROR");
}
}
}
@@ -2636,7 +2627,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
*/
@Override
public void removeCardsFromGame() {
GameEntityViewMap<Player, PlayerView> gameCachePlayer = GameEntityView.getMap(game.getPlayers());
GameEntityViewMap<Player, PlayerView> gameCachePlayer = GameEntityView.getMap(getGame().getPlayers());
final PlayerView pv = getGui().oneOrNone(localizer.getMessage("lblRemoveCardBelongingWitchPlayer"),
gameCachePlayer.getTrackableKeys());
@@ -2665,7 +2656,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
StringBuilder sb = new StringBuilder();
sb.append(p).append(" removes ").append(c).append(" from game due to Dev Cheats.");
game.getGameLog().add(GameLogEntryType.ZONE_CHANGE, sb.toString());
getGame().getGameLog().add(GameLogEntryType.ZONE_CHANGE, sb.toString());
}
}
@@ -2676,7 +2667,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
*/
@Override
public void riggedPlanarRoll() {
GameEntityViewMap<Player, PlayerView> gameCachePlayer = GameEntityView.getMap(game.getPlayers());
GameEntityViewMap<Player, PlayerView> gameCachePlayer = GameEntityView.getMap(getGame().getPlayers());
final PlayerView pv = getGui().oneOrNone(localizer.getMessage("lblWhichPlayerShouldRoll"), gameCachePlayer.getTrackableKeys());
if (pv == null || !gameCachePlayer.containsKey(pv)) {
@@ -2691,7 +2682,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
System.out.println("Rigging planar dice roll: " + res.toString());
game.getAction().invoke(new Runnable() {
getGame().getAction().invoke(new Runnable() {
@Override
public void run() {
PlanarDice.roll(player, res);
@@ -2706,10 +2697,10 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
*/
@Override
public void planeswalkTo() {
if (!game.getRules().hasAppliedVariant(GameType.Planechase)) {
if (!getGame().getRules().hasAppliedVariant(GameType.Planechase)) {
return;
}
final Player p = game.getPhaseHandler().getPlayerTurn();
final Player p = getGame().getPhaseHandler().getPlayerTurn();
final List<PaperCard> allPlanars = Lists.newArrayList();
for (final PaperCard c : FModel.getMagicDb().getVariantCards().getAllCards()) {
@@ -2727,10 +2718,10 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
final Card forgeCard = Card.fromPaperCard(c, p);
forgeCard.setOwner(p);
game.getAction().invoke(new Runnable() {
getGame().getAction().invoke(new Runnable() {
@Override
public void run() {
game.getAction().changeZone(null, p.getZone(ZoneType.PlanarDeck), forgeCard, 0, null);
getGame().getAction().changeZone(null, p.getZone(ZoneType.PlanarDeck), forgeCard, 0, null);
PlanarDice.roll(p, PlanarDice.Planeswalk);
}
});
@@ -2781,7 +2772,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
// the parsing
// process, and this implementation is still a "proof of concept".
int opponentID = 0;
for (final Player player : game.getPlayers()) {
for (final Player player : getGame().getPlayers()) {
if (player.getId() != playerID) {
opponentID = player.getId();
break;
@@ -2842,14 +2833,14 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
// Fetch cards and players specified by the user input
final ZoneType[] zones = { ZoneType.Battlefield, ZoneType.Hand, ZoneType.Graveyard, ZoneType.Exile,
ZoneType.Command };
final CardCollectionView cards = game.getCardsIn(Arrays.asList(zones));
final CardCollectionView cards = getGame().getCardsIn(Arrays.asList(zones));
for (final Pair<Integer, Boolean> entity : entityInfo) {
boolean found = false;
// Nested loops are no fun; however, seems there's no better way
// to get stuff by ID
boolean isPlayer = entity.getValue();
if (isPlayer) {
for (final Player player : game.getPlayers()) {
for (final Player player : getGame().getPlayers()) {
if (player.getId() == entity.getKey()) {
found = true;
rememberedActions.add(Pair.of(player.getView(), true));
@@ -2945,7 +2936,11 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
@Override
public void nextGameDecision(final NextGameDecision decision) {
game.fireEvent(new UiEventNextGameDecision(this, decision));
Game game = getGame();
// in case the game ended before the button is pressed, then match doesn't remember the game anymore
if (game != null) {
game.fireEvent(new UiEventNextGameDecision(this, decision));
}
}
@Override