mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 13:02:06 -08:00
added deck construction to draft
This commit is contained in:
parent
d62b512a72
commit
c79758f0e5
19 changed files with 154 additions and 25 deletions
|
|
@ -53,12 +53,10 @@ import mage.view.DraftView;
|
|||
*/
|
||||
public class DraftController {
|
||||
|
||||
// private static ExecutorService gameExecutor = ThreadExecutor.getInstance().getGameExecutor();
|
||||
private final static Logger logger = Logging.getLogger(GameController.class.getName());
|
||||
public static final String INIT_FILE_PATH = "config" + File.separator + "init.txt";
|
||||
|
||||
private ConcurrentHashMap<UUID, DraftSession> draftSessions = new ConcurrentHashMap<UUID, DraftSession>();
|
||||
// private ConcurrentHashMap<UUID, GameWatcher> watchers = new ConcurrentHashMap<UUID, GameWatcher>();
|
||||
private ConcurrentHashMap<UUID, UUID> sessionPlayerMap;
|
||||
private UUID draftSessionId;
|
||||
private Draft draft;
|
||||
|
|
@ -83,6 +81,9 @@ public class DraftController {
|
|||
case UPDATE:
|
||||
updateDraft();
|
||||
break;
|
||||
case END:
|
||||
endDraft();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -146,6 +147,10 @@ public class DraftController {
|
|||
draft.leave(getPlayerId(sessionId));
|
||||
}
|
||||
|
||||
private void endDraft() {
|
||||
TableManager.getInstance().endDraft(tableId);
|
||||
}
|
||||
|
||||
public void kill(UUID sessionId) {
|
||||
if (sessionPlayerMap.containsKey(sessionId)) {
|
||||
draftSessions.get(sessionPlayerMap.get(sessionId)).setKilled();
|
||||
|
|
@ -166,7 +171,7 @@ public class DraftController {
|
|||
for (final DraftSession draftSession: draftSessions.values()) {
|
||||
draftSession.gameOver(message);
|
||||
}
|
||||
TableManager.getInstance().endGame(tableId);
|
||||
TableManager.getInstance().endDraft(tableId);
|
||||
}
|
||||
|
||||
public UUID getSessionId() {
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ import mage.game.match.Match;
|
|||
import mage.game.Seat;
|
||||
import mage.game.draft.Draft;
|
||||
import mage.game.draft.DraftOptions;
|
||||
import mage.game.draft.DraftPlayer;
|
||||
import mage.game.events.Listener;
|
||||
import mage.game.events.TableEvent;
|
||||
import mage.game.match.MatchOptions;
|
||||
|
|
@ -112,6 +113,9 @@ public class TableController {
|
|||
case SIDEBOARD:
|
||||
sideboard(event.getPlayerId(), event.getDeck());
|
||||
break;
|
||||
case CONSTRUCT:
|
||||
construct(event.getPlayerId(), event.getDeck());
|
||||
break;
|
||||
case SUBMIT_DECK:
|
||||
submitDeck(event.getPlayerId(), event.getDeck());
|
||||
break;
|
||||
|
|
@ -167,21 +171,35 @@ public class TableController {
|
|||
}
|
||||
|
||||
public synchronized boolean submitDeck(UUID sessionId, DeckCardLists deckList) throws GameException {
|
||||
if (table.getState() != TableState.SIDEBOARDING) {
|
||||
if (table.getState() != TableState.SIDEBOARDING && table.getState() != TableState.CONSTRUCTING) {
|
||||
return false;
|
||||
}
|
||||
MatchPlayer player = match.getPlayer(sessionPlayerMap.get(sessionId));
|
||||
String playerName;
|
||||
if (table.getState() == TableState.SIDEBOARDING) {
|
||||
MatchPlayer player = match.getPlayer(sessionPlayerMap.get(sessionId));
|
||||
playerName = player.getPlayer().getName();
|
||||
}
|
||||
else {
|
||||
DraftPlayer player = draft.getPlayer(sessionPlayerMap.get(sessionId));
|
||||
playerName = player.getPlayer().getName();
|
||||
}
|
||||
Deck deck = Deck.load(deckList);
|
||||
if (!Main.server.isTestMode() && !validDeck(deck)) {
|
||||
throw new GameException(player.getPlayer().getName() + " has an invalid deck for this format");
|
||||
throw new GameException(playerName + " has an invalid deck for this format");
|
||||
}
|
||||
submitDeck(sessionPlayerMap.get(sessionId), deck);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void submitDeck(UUID playerId, Deck deck) {
|
||||
MatchPlayer player = match.getPlayer(playerId);
|
||||
player.submitDeck(deck);
|
||||
if (table.getState() == TableState.SIDEBOARDING) {
|
||||
MatchPlayer player = match.getPlayer(playerId);
|
||||
player.submitDeck(deck);
|
||||
}
|
||||
else if (table.getState() == TableState.CONSTRUCTING) {
|
||||
DraftPlayer player = draft.getPlayer(playerId);
|
||||
player.submitDeck(deck);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean watchTable(UUID sessionId) {
|
||||
|
|
@ -199,7 +217,6 @@ public class TableController {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
public boolean replayTable(UUID sessionId) {
|
||||
if (table.getState() != TableState.FINISHED) {
|
||||
return false;
|
||||
|
|
@ -280,6 +297,15 @@ public class TableController {
|
|||
}
|
||||
}
|
||||
|
||||
private void construct() {
|
||||
table.construct();
|
||||
for (DraftPlayer player: draft.getPlayers()) {
|
||||
player.setConstructing();
|
||||
player.getPlayer().construct(table, player.getDeck());
|
||||
}
|
||||
while (!draft.isDoneConstructing()){}
|
||||
}
|
||||
|
||||
private void construct(UUID playerId, Deck deck) {
|
||||
SessionManager sessionManager = SessionManager.getInstance();
|
||||
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
|
|
@ -306,6 +332,11 @@ public class TableController {
|
|||
}
|
||||
}
|
||||
|
||||
public void endDraft() {
|
||||
construct();
|
||||
|
||||
}
|
||||
|
||||
public void swapSeats(int seatNum1, int seatNum2) {
|
||||
if (table.getState() == TableState.STARTING) {
|
||||
if (seatNum1 >= 0 && seatNum2 >= 0 && seatNum1 < table.getSeats().length && seatNum2 < table.getSeats().length) {
|
||||
|
|
|
|||
|
|
@ -134,6 +134,10 @@ public class TableManager {
|
|||
controllers.get(tableId).endGame();
|
||||
}
|
||||
|
||||
public void endDraft(UUID tableId) {
|
||||
controllers.get(tableId).endDraft();
|
||||
}
|
||||
|
||||
public GameReplay createReplay(UUID tableId) {
|
||||
return controllers.get(tableId).createReplay();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue