mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Invoking ViewWinLose from FControl (that's temporary - should make a dedicated class), MatchController is no longer bound to UI.
GameNew - trying to split its all-in-one methods into parts to separate game state changes from GUI calls
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -14236,6 +14236,7 @@ src/main/java/forge/game/event/CardDiscardedEvent.java -text
|
||||
src/main/java/forge/game/event/CardEquippedEvent.java -text
|
||||
src/main/java/forge/game/event/CardRegeneratedEvent.java -text
|
||||
src/main/java/forge/game/event/CardSacrificedEvent.java -text
|
||||
src/main/java/forge/game/event/CardsAntedEvent.java -text
|
||||
src/main/java/forge/game/event/CounterAddedEvent.java -text
|
||||
src/main/java/forge/game/event/CounterRemovedEvent.java -text
|
||||
src/main/java/forge/game/event/DrawCardEvent.java -text
|
||||
|
||||
@@ -31,14 +31,23 @@ import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.WindowConstants;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import forge.Card;
|
||||
import forge.FThreads;
|
||||
import forge.Constant.Preferences;
|
||||
import forge.Singletons;
|
||||
import forge.control.KeyboardShortcuts.Shortcut;
|
||||
import forge.game.GameState;
|
||||
import forge.game.ai.AiProfileUtil;
|
||||
import forge.game.event.CardsAntedEvent;
|
||||
import forge.game.event.DuelOutcomeEvent;
|
||||
import forge.game.event.Event;
|
||||
import forge.game.player.LobbyPlayer;
|
||||
import forge.game.player.Player;
|
||||
import forge.gui.GuiDialog;
|
||||
import forge.gui.SOverlayUtils;
|
||||
import forge.gui.deckeditor.CDeckEditorUI;
|
||||
import forge.gui.deckeditor.VDeckEditorUI;
|
||||
@@ -50,6 +59,7 @@ import forge.gui.home.CHomeUI;
|
||||
import forge.gui.home.VHomeUI;
|
||||
import forge.gui.match.CMatchUI;
|
||||
import forge.gui.match.VMatchUI;
|
||||
import forge.gui.match.ViewWinLose;
|
||||
import forge.gui.match.controllers.CCombat;
|
||||
import forge.gui.match.controllers.CDock;
|
||||
import forge.gui.match.controllers.CLog;
|
||||
@@ -365,7 +375,8 @@ public enum FControl {
|
||||
game.getGameLog().addObserver(CLog.SINGLETON_INSTANCE);
|
||||
// some observers were set in CMatchUI.initMatch
|
||||
|
||||
// black magic still
|
||||
// Listen to DuelOutcome event to show ViewWinLose
|
||||
game.getEvents().register(this);
|
||||
|
||||
|
||||
VAntes.SINGLETON_INSTANCE.setModel(game.getRegisteredPlayers());
|
||||
@@ -378,5 +389,24 @@ public enum FControl {
|
||||
//Set Field shown to current player.
|
||||
VField nextField = CMatchUI.SINGLETON_INSTANCE.getFieldViewFor(game.getPlayers().get(0));
|
||||
SDisplayUtil.showTab(nextField);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void receiveGameEvent(Event ev) {
|
||||
|
||||
if( ev instanceof DuelOutcomeEvent ) {
|
||||
FThreads.invokeInEdtNowOrLater(new Runnable() { @Override public void run() {
|
||||
new ViewWinLose(game.getMatch());
|
||||
SOverlayUtils.showOverlay();
|
||||
} });
|
||||
} else if ( ev instanceof CardsAntedEvent ) {
|
||||
// Require EDT here?
|
||||
final String nl = System.getProperty("line.separator");
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
for (final Pair<Player, Card> kv : ((CardsAntedEvent) ev).cards) {
|
||||
msg.append(kv.getKey().getName()).append(" ante: ").append(kv.getValue()).append(nl);
|
||||
}
|
||||
GuiDialog.message(msg.toString(), "Ante");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package forge.game;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -41,6 +41,9 @@ import forge.properties.ForgePreferences.FPref;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.MyRandom;
|
||||
import forge.util.TextUtil;
|
||||
import forge.util.maps.CollectionSuppliers;
|
||||
import forge.util.maps.HashMapOfLists;
|
||||
import forge.util.maps.MapOfLists;
|
||||
|
||||
/**
|
||||
* Methods for all things related to starting a new game.
|
||||
@@ -231,7 +234,7 @@ public class GameNew {
|
||||
// friendliness
|
||||
final Set<CardPrinted> rAICards = new HashSet<CardPrinted>();
|
||||
|
||||
Map<Player, Set<CardPrinted>> removedAnteCards = new HashMap<Player, Set<CardPrinted>>();
|
||||
MapOfLists<Player, CardPrinted> removedAnteCards = new HashMapOfLists<Player, CardPrinted>(CollectionSuppliers.<CardPrinted>hashSets());
|
||||
|
||||
GameType gameType = game.getType();
|
||||
boolean isFirstGame = game.getMatch().getPlayedGames().isEmpty();
|
||||
@@ -281,10 +284,10 @@ public class GameNew {
|
||||
player.getZone(ZoneType.Battlefield).updateObservers();
|
||||
|
||||
if( myRemovedAnteCards != null && !myRemovedAnteCards.isEmpty() )
|
||||
removedAnteCards.put(player, myRemovedAnteCards);
|
||||
removedAnteCards.addAll(player, myRemovedAnteCards);
|
||||
}
|
||||
|
||||
if (rAICards.size() > 0) {
|
||||
if (!rAICards.isEmpty()) {
|
||||
String message = TextUtil.buildFourColumnList("AI deck contains the following cards that it can't play or may be buggy:", rAICards);
|
||||
if (GameType.Quest == game.getType() || GameType.Sealed == game.getType() || GameType.Draft == game.getType()) {
|
||||
// log, but do not visually warn. quest decks are supposedly already vetted by the quest creator,
|
||||
@@ -298,38 +301,35 @@ public class GameNew {
|
||||
|
||||
if (!removedAnteCards.isEmpty()) {
|
||||
StringBuilder ante = new StringBuilder("The following ante cards were removed:\n\n");
|
||||
for (Entry<Player, Set<CardPrinted>> ants : removedAnteCards.entrySet()) {
|
||||
for (Entry<Player, Collection<CardPrinted>> ants : removedAnteCards.entrySet()) {
|
||||
ante.append(TextUtil.buildFourColumnList("From the " + ants.getKey().getName() + "'s deck:", ants.getValue()));
|
||||
}
|
||||
GuiDialog.message(ante.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// Deciding which cards go to ante
|
||||
if (useAnte) {
|
||||
final String nl = System.getProperty("line.separator");
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
for (final Player p : game.getPlayers()) {
|
||||
static List<Pair<Player, Card>> chooseCardsForAnte(final GameState game) {
|
||||
List<Pair<Player, Card>> anteed = new ArrayList<Pair<Player,Card>>();
|
||||
|
||||
final List<Card> lib = p.getCardsIn(ZoneType.Library);
|
||||
Predicate<Card> goodForAnte = Predicates.not(CardPredicates.Presets.BASIC_LANDS);
|
||||
Card ante = Aggregates.random(Iterables.filter(lib, goodForAnte));
|
||||
if (ante == null) {
|
||||
game.getGameLog().add(GameEventType.ANTE, "Only basic lands found. Will ante one of them");
|
||||
ante = Aggregates.random(lib);
|
||||
}
|
||||
game.getGameLog().add(GameEventType.ANTE, p + " anted " + ante);
|
||||
game.getAction().moveTo(ZoneType.Ante, ante);
|
||||
msg.append(p.getName()).append(" ante: ").append(ante).append(nl);
|
||||
for (final Player p : game.getPlayers()) {
|
||||
final List<Card> lib = p.getCardsIn(ZoneType.Library);
|
||||
Predicate<Card> goodForAnte = Predicates.not(CardPredicates.Presets.BASIC_LANDS);
|
||||
Card ante = Aggregates.random(Iterables.filter(lib, goodForAnte));
|
||||
if (ante == null) {
|
||||
game.getGameLog().add(GameEventType.ANTE, "Only basic lands found. Will ante one of them");
|
||||
ante = Aggregates.random(lib);
|
||||
}
|
||||
GuiDialog.message(msg.toString(), "Ante");
|
||||
anteed.add(Pair.of(p, ante));
|
||||
}
|
||||
|
||||
// Draw <handsize> cards
|
||||
for (final Player p1 : game.getPlayers()) {
|
||||
p1.drawCards(p1.getMaxHandSize());
|
||||
return anteed;
|
||||
}
|
||||
|
||||
static void moveCardsToAnte(List<Pair<Player, Card>> cards) {
|
||||
for(Pair<Player, Card> kv : cards) {
|
||||
Player p = kv.getKey();
|
||||
p.getGame().getAction().moveTo(ZoneType.Ante, kv.getValue());
|
||||
p.getGame().getGameLog().add(GameEventType.ANTE, p + " anted " + kv.getValue());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// ultimate of Karn the Liberated
|
||||
|
||||
@@ -7,16 +7,16 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.Card;
|
||||
import forge.FThreads;
|
||||
import forge.Singletons;
|
||||
import forge.control.FControl;
|
||||
import forge.error.BugReporter;
|
||||
import forge.game.event.CardsAntedEvent;
|
||||
import forge.game.event.DuelOutcomeEvent;
|
||||
import forge.game.event.FlipCoinEvent;
|
||||
import forge.game.player.LobbyPlayer;
|
||||
import forge.game.player.Player;
|
||||
import forge.gui.SOverlayUtils;
|
||||
import forge.gui.match.ViewWinLose;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
@@ -49,10 +49,10 @@ public class MatchController {
|
||||
gameType = type;
|
||||
}
|
||||
|
||||
public MatchController(GameType type, List<Pair<LobbyPlayer, PlayerStartConditions>> players0, Boolean forceAnte) {
|
||||
public MatchController(GameType type, List<Pair<LobbyPlayer, PlayerStartConditions>> players0, Boolean overrideAnte) {
|
||||
this(type, players0);
|
||||
if( forceAnte != null )
|
||||
this.useAnte = forceAnte.booleanValue();
|
||||
if( overrideAnte != null )
|
||||
this.useAnte = overrideAnte.booleanValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,11 +91,6 @@ public class MatchController {
|
||||
|
||||
// The log shall listen to events and generate text internally
|
||||
game.getEvents().post(new DuelOutcomeEvent(result, gamesPlayedRo));
|
||||
|
||||
FThreads.invokeInEdtNowOrLater(new Runnable() { @Override public void run() {
|
||||
ViewWinLose v = new ViewWinLose(MatchController.this);
|
||||
SOverlayUtils.showOverlay();
|
||||
} });
|
||||
}
|
||||
|
||||
|
||||
@@ -112,6 +107,17 @@ public class MatchController {
|
||||
final boolean canRandomFoil = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_FOIL) && gameType == GameType.Constructed;
|
||||
GameNew.newGame(currentGame, canRandomFoil, this.useAnte);
|
||||
|
||||
if (useAnte) { // Deciding which cards go to ante
|
||||
List<Pair<Player, Card>> list = GameNew.chooseCardsForAnte(currentGame);
|
||||
GameNew.moveCardsToAnte(list);
|
||||
currentGame.getEvents().post(new CardsAntedEvent(list));
|
||||
}
|
||||
|
||||
// Draw <handsize> cards
|
||||
for (final Player p1 : currentGame.getPlayers()) {
|
||||
p1.drawCards(p1.getMaxHandSize());
|
||||
}
|
||||
|
||||
currentGame.setAge(GameAge.Mulligan);
|
||||
} catch (Exception e) {
|
||||
BugReporter.reportException(e);
|
||||
@@ -123,9 +129,6 @@ public class MatchController {
|
||||
if(currentGame.getType() == GameType.Planechase)
|
||||
firstPlayer.initPlane();
|
||||
|
||||
// Update observers
|
||||
currentGame.getGameLog().updateObservers();
|
||||
|
||||
// This code was run from EDT.
|
||||
FThreads.invokeInNewThread( new Runnable() {
|
||||
@Override
|
||||
|
||||
13
src/main/java/forge/game/event/CardsAntedEvent.java
Normal file
13
src/main/java/forge/game/event/CardsAntedEvent.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package forge.game.event;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import forge.Card;
|
||||
import forge.game.player.Player;
|
||||
|
||||
public class CardsAntedEvent extends Event {
|
||||
public final Iterable<Pair<Player,Card>> cards;
|
||||
public CardsAntedEvent(Iterable<Pair<Player,Card>> cardz) {
|
||||
cards = cardz;
|
||||
}
|
||||
}
|
||||
@@ -12,4 +12,4 @@ public class DuelOutcomeEvent extends Event {
|
||||
this.result = lastOne;
|
||||
this.history = history;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user