mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
Fix mindslaver effects.
- Fix bug where game would become unsreponsive after mind slaving ends; - Fix bug where players could concede for mind-slaved opponents; - Cleanup, managed to remove some fields.
This commit is contained in:
@@ -244,7 +244,6 @@ public final class CMatchUI
|
|||||||
|
|
||||||
private void initMatch(final FCollectionView<PlayerView> sortedPlayers, final Collection<PlayerView> myPlayers) {
|
private void initMatch(final FCollectionView<PlayerView> sortedPlayers, final Collection<PlayerView> myPlayers) {
|
||||||
this.sortedPlayers = sortedPlayers;
|
this.sortedPlayers = sortedPlayers;
|
||||||
this.setLocalPlayers(myPlayers);
|
|
||||||
allHands = sortedPlayers.size() == getLocalPlayerCount();
|
allHands = sortedPlayers.size() == getLocalPlayerCount();
|
||||||
|
|
||||||
final String[] indices = FModel.getPreferences().getPref(FPref.UI_AVATARS).split(",");
|
final String[] indices = FModel.getPreferences().getPref(FPref.UI_AVATARS).split(",");
|
||||||
|
|||||||
@@ -59,31 +59,26 @@ public class ControlWinLose {
|
|||||||
|
|
||||||
/** Action performed when "continue" button is pressed in default win/lose UI. */
|
/** Action performed when "continue" button is pressed in default win/lose UI. */
|
||||||
public void actionOnContinue() {
|
public void actionOnContinue() {
|
||||||
SOverlayUtils.hideOverlay();
|
nextGameAction(NextGameDecision.CONTINUE);
|
||||||
saveOptions();
|
|
||||||
for (final IGameController controller : matchUI.getGameControllers()) {
|
|
||||||
controller.nextGameDecision(NextGameDecision.CONTINUE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Action performed when "restart" button is pressed in default win/lose UI. */
|
/** Action performed when "restart" button is pressed in default win/lose UI. */
|
||||||
public void actionOnRestart() {
|
public void actionOnRestart() {
|
||||||
SOverlayUtils.hideOverlay();
|
nextGameAction(NextGameDecision.NEW);
|
||||||
saveOptions();
|
|
||||||
for (final IGameController controller : matchUI.getGameControllers()) {
|
|
||||||
controller.nextGameDecision(NextGameDecision.NEW);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Action performed when "quit" button is pressed in default win/lose UI. */
|
/** Action performed when "quit" button is pressed in default win/lose UI. */
|
||||||
public void actionOnQuit() {
|
public void actionOnQuit() {
|
||||||
// Reset other stuff
|
nextGameAction(NextGameDecision.QUIT);
|
||||||
saveOptions();
|
|
||||||
for (final IGameController controller : matchUI.getGameControllers()) {
|
|
||||||
controller.nextGameDecision(NextGameDecision.QUIT);
|
|
||||||
}
|
|
||||||
Singletons.getControl().setCurrentScreen(FScreen.HOME_SCREEN);
|
Singletons.getControl().setCurrentScreen(FScreen.HOME_SCREEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void nextGameAction(final NextGameDecision decision) {
|
||||||
SOverlayUtils.hideOverlay();
|
SOverlayUtils.hideOverlay();
|
||||||
|
saveOptions();
|
||||||
|
for (final IGameController controller : matchUI.getOriginalGameControllers()) {
|
||||||
|
controller.nextGameDecision(decision);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -110,7 +110,6 @@ public class MatchController extends AbstractGuiGame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void openView(final TrackableCollection<PlayerView> myPlayers) {
|
public void openView(final TrackableCollection<PlayerView> myPlayers) {
|
||||||
setLocalPlayers(myPlayers);
|
|
||||||
final boolean noHumans = !hasLocalPlayers();
|
final boolean noHumans = !hasLocalPlayers();
|
||||||
|
|
||||||
final FCollectionView<PlayerView> allPlayers = getGameView().getPlayers();
|
final FCollectionView<PlayerView> allPlayers = getGameView().getPlayers();
|
||||||
|
|||||||
@@ -235,9 +235,15 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
|||||||
if (ev.player.getGame().isGameOver()) {
|
if (ev.player.getGame().isGameOver()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final PlayerControllerHuman newController;
|
||||||
if (ev.newController instanceof PlayerControllerHuman) {
|
if (ev.newController instanceof PlayerControllerHuman) {
|
||||||
matchController.setGameController(PlayerView.get(ev.player), (PlayerControllerHuman) ev.newController);
|
newController = (PlayerControllerHuman) ev.newController;
|
||||||
|
} else {
|
||||||
|
newController = null;
|
||||||
}
|
}
|
||||||
|
matchController.setGameController(PlayerView.get(ev.player), newController);
|
||||||
|
|
||||||
needPlayerControlUpdate = true;
|
needPlayerControlUpdate = true;
|
||||||
return processEvent();
|
return processEvent();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,9 @@ import forge.util.ITriggerEvent;
|
|||||||
|
|
||||||
public interface IGuiGame {
|
public interface IGuiGame {
|
||||||
void setGameView(GameView gameView);
|
void setGameView(GameView gameView);
|
||||||
|
void setOriginalGameController(PlayerView view, IGameController gameController);
|
||||||
void setGameController(PlayerView player, IGameController gameController);
|
void setGameController(PlayerView player, IGameController gameController);
|
||||||
|
void setSpectator(IGameController spectator);
|
||||||
void openView(TrackableCollection<PlayerView> myPlayers);
|
void openView(TrackableCollection<PlayerView> myPlayers);
|
||||||
void afterGameEnd();
|
void afterGameEnd();
|
||||||
void showCombat();
|
void showCombat();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
@@ -27,37 +28,24 @@ import forge.game.player.PlayerView;
|
|||||||
import forge.interfaces.IGameController;
|
import forge.interfaces.IGameController;
|
||||||
import forge.interfaces.IGuiGame;
|
import forge.interfaces.IGuiGame;
|
||||||
import forge.interfaces.IMayViewCards;
|
import forge.interfaces.IMayViewCards;
|
||||||
import forge.util.FCollection;
|
|
||||||
import forge.util.FCollectionView;
|
|
||||||
|
|
||||||
public abstract class AbstractGuiGame implements IGuiGame, IMayViewCards {
|
public abstract class AbstractGuiGame implements IGuiGame, IMayViewCards {
|
||||||
private FCollection<PlayerView> localPlayers = new FCollection<PlayerView>();
|
|
||||||
private PlayerView currentPlayer = null;
|
private PlayerView currentPlayer = null;
|
||||||
|
private IGameController spectator = null;
|
||||||
protected final void setLocalPlayers(final Collection<PlayerView> myPlayers) {
|
private final Map<PlayerView, IGameController> gameControllers = Maps.newHashMap();
|
||||||
this.localPlayers = myPlayers == null ? new FCollection<PlayerView>() : new FCollection<PlayerView>(myPlayers);
|
private final Map<PlayerView, IGameController> originalGameControllers = Maps.newHashMap();
|
||||||
this.currentPlayer = Iterables.getFirst(this.localPlayers, null);
|
|
||||||
this.autoPassUntilEndOfTurn.retainAll(myPlayers);
|
|
||||||
}
|
|
||||||
private void addLocalPlayer(final PlayerView player) {
|
|
||||||
this.localPlayers.add(player);
|
|
||||||
}
|
|
||||||
private void removeLocalPlayer(final PlayerView player) {
|
|
||||||
this.localPlayers.remove(player);
|
|
||||||
this.autoPassUntilEndOfTurn.remove(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean hasLocalPlayers() {
|
public final boolean hasLocalPlayers() {
|
||||||
return !localPlayers.isEmpty();
|
return !gameControllers.isEmpty();
|
||||||
}
|
}
|
||||||
public final FCollectionView<PlayerView> getLocalPlayers() {
|
public final Set<PlayerView> getLocalPlayers() {
|
||||||
return localPlayers;
|
return gameControllers.keySet();
|
||||||
}
|
}
|
||||||
public final int getLocalPlayerCount() {
|
public final int getLocalPlayerCount() {
|
||||||
return localPlayers.size();
|
return gameControllers.size();
|
||||||
}
|
}
|
||||||
public final boolean isLocalPlayer(final PlayerView player) {
|
public final boolean isLocalPlayer(final PlayerView player) {
|
||||||
return localPlayers.contains(player);
|
return gameControllers.containsKey(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final PlayerView getCurrentPlayer() {
|
public final PlayerView getCurrentPlayer() {
|
||||||
@@ -65,6 +53,9 @@ public abstract class AbstractGuiGame implements IGuiGame, IMayViewCards {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public final void setCurrentPlayer(final PlayerView player) {
|
public final void setCurrentPlayer(final PlayerView player) {
|
||||||
|
if (!gameControllers.containsKey(player)) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
this.currentPlayer = player;
|
this.currentPlayer = player;
|
||||||
updateCurrentPlayer(player);
|
updateCurrentPlayer(player);
|
||||||
}
|
}
|
||||||
@@ -79,24 +70,54 @@ public abstract class AbstractGuiGame implements IGuiGame, IMayViewCards {
|
|||||||
this.gameView = gameView;
|
this.gameView = gameView;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Map<PlayerView, IGameController> gameControllers = Maps.newHashMap();
|
|
||||||
public final IGameController getGameController() {
|
public final IGameController getGameController() {
|
||||||
return gameControllers.get(getCurrentPlayer());
|
return getGameController(getCurrentPlayer());
|
||||||
}
|
}
|
||||||
public final IGameController getGameController(final PlayerView p0) {
|
public final IGameController getGameController(final PlayerView player) {
|
||||||
return gameControllers.get(p0);
|
if (player == null) {
|
||||||
|
return spectator;
|
||||||
|
}
|
||||||
|
return gameControllers.get(player);
|
||||||
}
|
}
|
||||||
public final Collection<IGameController> getGameControllers() {
|
|
||||||
return gameControllers.values();
|
public final Collection<IGameController> getOriginalGameControllers() {
|
||||||
|
return originalGameControllers.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOriginalGameController(final PlayerView player, final IGameController gameController) {
|
||||||
|
if (player == null || gameController == null) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
originalGameControllers.put(player, gameController);
|
||||||
|
gameControllers.put(player, gameController);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setGameController(final PlayerView player, final IGameController gameController) {
|
public void setGameController(final PlayerView player, final IGameController gameController) {
|
||||||
this.gameControllers.put(player, gameController);
|
if (player == null) {
|
||||||
if (gameController == null) {
|
throw new IllegalArgumentException();
|
||||||
addLocalPlayer(player);
|
|
||||||
} else {
|
|
||||||
removeLocalPlayer(player);
|
|
||||||
}
|
}
|
||||||
|
if (gameController == null) {
|
||||||
|
if (originalGameControllers.containsKey(player)) {
|
||||||
|
gameControllers.put(player, originalGameControllers.get(player));
|
||||||
|
} else {
|
||||||
|
gameControllers.remove(player);
|
||||||
|
autoPassUntilEndOfTurn.remove(player);
|
||||||
|
final PlayerView currentPlayer = getCurrentPlayer();
|
||||||
|
if (Objects.equals(player, currentPlayer)) {
|
||||||
|
// set current player to a value known to be legal
|
||||||
|
setCurrentPlayer(Iterables.getFirst(gameControllers.keySet(), null));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.gameControllers.put(player, gameController);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSpectator(final IGameController spectator) {
|
||||||
|
this.spectator = spectator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -177,8 +198,8 @@ public abstract class AbstractGuiGame implements IGuiGame, IMayViewCards {
|
|||||||
}
|
}
|
||||||
if (hasLocalPlayers()) {
|
if (hasLocalPlayers()) {
|
||||||
if (showConfirmDialog("This will concede the current game and you will lose.\n\nConcede anyway?", "Concede Game?", "Concede", "Cancel")) {
|
if (showConfirmDialog("This will concede the current game and you will lose.\n\nConcede anyway?", "Concede Game?", "Concede", "Cancel")) {
|
||||||
for (final IGameController c : getGameControllers()) {
|
for (final IGameController c : getOriginalGameControllers()) {
|
||||||
// Concede each player on this Gui
|
// Concede each player on this Gui (except mind-controlled players)
|
||||||
c.concede();
|
c.concede();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -204,9 +225,6 @@ public abstract class AbstractGuiGame implements IGuiGame, IMayViewCards {
|
|||||||
updateButtons(owner, "OK", "Cancel", okEnabled, cancelEnabled, focusOk);
|
updateButtons(owner, "OK", "Cancel", okEnabled, cancelEnabled, focusOk);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract void updateButtons(PlayerView owner, String label1, String label2, boolean enable1, boolean enable2, boolean focus1);
|
|
||||||
|
|
||||||
// Auto-yield and other input-related code
|
// Auto-yield and other input-related code
|
||||||
|
|
||||||
private final Set<PlayerView> autoPassUntilEndOfTurn = Sets.newHashSet();
|
private final Set<PlayerView> autoPassUntilEndOfTurn = Sets.newHashSet();
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ public class HostedMatch {
|
|||||||
final IGuiGame gui = guis.get(p.getRegisteredPlayer());
|
final IGuiGame gui = guis.get(p.getRegisteredPlayer());
|
||||||
humanController.setGui(gui);
|
humanController.setGui(gui);
|
||||||
gui.setGameView(gameView);
|
gui.setGameView(gameView);
|
||||||
gui.setGameController(p.getView(), humanController);
|
gui.setOriginalGameController(p.getView(), humanController);
|
||||||
|
|
||||||
game.subscribeToEvents(new FControlGameEventHandler(humanController));
|
game.subscribeToEvents(new FControlGameEventHandler(humanController));
|
||||||
playersPerGui.add(gui, p.getView());
|
playersPerGui.add(gui, p.getView());
|
||||||
@@ -189,7 +189,7 @@ public class HostedMatch {
|
|||||||
final PlayerControllerHuman humanController = new WatchLocalGame(game, new LobbyPlayerHuman("Spectator"), gui);
|
final PlayerControllerHuman humanController = new WatchLocalGame(game, new LobbyPlayerHuman("Spectator"), gui);
|
||||||
game.subscribeToEvents(new FControlGameEventHandler(humanController));
|
game.subscribeToEvents(new FControlGameEventHandler(humanController));
|
||||||
humanControllers.add(humanController);
|
humanControllers.add(humanController);
|
||||||
gui.setGameController(null, humanController);
|
gui.setSpectator(humanController);
|
||||||
|
|
||||||
gui.openView(null);
|
gui.openView(null);
|
||||||
}
|
}
|
||||||
@@ -230,12 +230,11 @@ public class HostedMatch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerSpectator(final IGuiGame gui) {
|
public void registerSpectator(final IGuiGame gui) {
|
||||||
final PlayerControllerHuman humanController = new WatchLocalGame(game, null, gui);
|
final PlayerControllerHuman humanController = new WatchLocalGame(game, null, gui);
|
||||||
gui.setGameController(null, humanController);
|
gui.setSpectator(humanController);
|
||||||
gui.openView(null);
|
gui.openView(null);
|
||||||
|
|
||||||
game.subscribeToEvents(new FControlGameEventHandler(humanController));
|
game.subscribeToEvents(new FControlGameEventHandler(humanController));
|
||||||
|
|||||||
Reference in New Issue
Block a user