mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
fixed multi-human drafting
This commit is contained in:
parent
5a785b9330
commit
e2fd0299c7
31 changed files with 160 additions and 107 deletions
|
|
@ -59,6 +59,7 @@ import mage.server.tournament.TournamentManager;
|
|||
import mage.server.util.ThreadExecutor;
|
||||
import mage.util.Logging;
|
||||
import mage.view.ChatMessage.MessageColor;
|
||||
import mage.view.DraftPickView;
|
||||
import mage.view.GameView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.TournamentView;
|
||||
|
|
@ -162,9 +163,9 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean joinTable(UUID sessionId, UUID roomId, UUID tableId, String name, DeckCardLists deckList) throws MageException, GameException {
|
||||
public boolean joinTable(UUID sessionId, UUID roomId, UUID tableId, String name, String playerType, DeckCardLists deckList) throws MageException, GameException {
|
||||
try {
|
||||
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTable(sessionId, tableId, name, deckList);
|
||||
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTable(sessionId, tableId, name, playerType, deckList);
|
||||
logger.info("Session " + sessionId + " joined table " + tableId);
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -177,9 +178,9 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean joinTournamentTable(UUID sessionId, UUID roomId, UUID tableId, String name) throws MageException, GameException {
|
||||
public boolean joinTournamentTable(UUID sessionId, UUID roomId, UUID tableId, String name, String playerType) throws MageException, GameException {
|
||||
try {
|
||||
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTournamentTable(sessionId, tableId, name);
|
||||
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTournamentTable(sessionId, tableId, name, playerType);
|
||||
logger.info("Session " + sessionId + " joined table " + tableId);
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -562,20 +563,14 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void sendCardPick(final UUID draftId, final UUID sessionId, final UUID cardPick) throws MageException {
|
||||
public DraftPickView sendCardPick(final UUID draftId, final UUID sessionId, final UUID cardPick) throws MageException {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DraftManager.getInstance().sendCardPick(draftId, sessionId, cardPick);
|
||||
}
|
||||
}
|
||||
);
|
||||
return DraftManager.getInstance().sendCardPick(draftId, sessionId, cardPick);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ public class TableController {
|
|||
chatId = ChatManager.getInstance().createChatSession();
|
||||
this.options = options;
|
||||
match = GameFactory.getInstance().createMatch(options.getGameType(), options);
|
||||
table = new Table(options.getGameType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getDeckType()), options.getPlayerTypes());
|
||||
table = new Table(options.getGameType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getDeckType()), options.getPlayerTypes(), false);
|
||||
init();
|
||||
}
|
||||
|
||||
|
|
@ -111,7 +111,7 @@ public class TableController {
|
|||
chatId = ChatManager.getInstance().createChatSession();
|
||||
this.tournamentOptions = options;
|
||||
tournament = TournamentFactory.getInstance().createTournament(options.getTournamentType(), options);
|
||||
table = new Table(options.getTournamentType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getMatchOptions().getDeckType()), options.getPlayerTypes());
|
||||
table = new Table(options.getTournamentType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getMatchOptions().getDeckType()), options.getPlayerTypes(), true);
|
||||
init();
|
||||
}
|
||||
|
||||
|
|
@ -136,11 +136,11 @@ public class TableController {
|
|||
);
|
||||
}
|
||||
|
||||
public synchronized boolean joinTournament(UUID sessionId, String name) throws GameException {
|
||||
public synchronized boolean joinTournament(UUID sessionId, String name, String playerType) throws GameException {
|
||||
if (table.getState() != TableState.WAITING) {
|
||||
return false;
|
||||
}
|
||||
Seat seat = table.getNextAvailableSeat();
|
||||
Seat seat = table.getNextAvailableSeat(playerType);
|
||||
if (seat == null) {
|
||||
throw new GameException("No available seats.");
|
||||
}
|
||||
|
|
@ -156,11 +156,11 @@ public class TableController {
|
|||
return true;
|
||||
}
|
||||
|
||||
public synchronized boolean joinTable(UUID sessionId, String name, DeckCardLists deckList) throws GameException {
|
||||
public synchronized boolean joinTable(UUID sessionId, String name, String playerType, DeckCardLists deckList) throws GameException {
|
||||
if (table.getState() != TableState.WAITING) {
|
||||
return false;
|
||||
}
|
||||
Seat seat = table.getNextAvailableSeat();
|
||||
Seat seat = table.getNextAvailableSeat(playerType);
|
||||
if (seat == null) {
|
||||
throw new GameException("No available seats.");
|
||||
}
|
||||
|
|
@ -181,11 +181,11 @@ public class TableController {
|
|||
return true;
|
||||
}
|
||||
|
||||
public void addPlayer(UUID sessionId, Player player, Deck deck) throws GameException {
|
||||
public void addPlayer(UUID sessionId, Player player, String playerType, Deck deck) throws GameException {
|
||||
if (table.getState() != TableState.WAITING) {
|
||||
return;
|
||||
}
|
||||
Seat seat = table.getNextAvailableSeat();
|
||||
Seat seat = table.getNextAvailableSeat(playerType);
|
||||
if (seat == null) {
|
||||
throw new GameException("No available seats.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,12 +86,12 @@ public class TableManager {
|
|||
return tables.values();
|
||||
}
|
||||
|
||||
public boolean joinTable(UUID sessionId, UUID tableId, String name, DeckCardLists deckList) throws GameException {
|
||||
return controllers.get(tableId).joinTable(sessionId, name, deckList);
|
||||
public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, DeckCardLists deckList) throws GameException {
|
||||
return controllers.get(tableId).joinTable(sessionId, name, playerType, deckList);
|
||||
}
|
||||
|
||||
public boolean joinTournament(UUID sessionId, UUID tableId, String name) throws GameException {
|
||||
return controllers.get(tableId).joinTournament(sessionId, name);
|
||||
public boolean joinTournament(UUID sessionId, UUID tableId, String name, String playerType) throws GameException {
|
||||
return controllers.get(tableId).joinTournament(sessionId, name, playerType);
|
||||
}
|
||||
|
||||
public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws GameException {
|
||||
|
|
@ -165,7 +165,7 @@ public class TableManager {
|
|||
controllers.get(tableId).construct();
|
||||
}
|
||||
|
||||
public void addPlayer(UUID sessionId, UUID tableId, Player player, Deck deck) throws GameException {
|
||||
controllers.get(tableId).addPlayer(sessionId, player, deck);
|
||||
public void addPlayer(UUID sessionId, UUID tableId, Player player, String playerType, Deck deck) throws GameException {
|
||||
controllers.get(tableId).addPlayer(sessionId, player, playerType, deck);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -184,8 +184,11 @@ public class DraftController {
|
|||
return this.draftSessionId;
|
||||
}
|
||||
|
||||
public void sendCardPick(UUID sessionId, UUID cardId) {
|
||||
draftSessions.get(sessionPlayerMap.get(sessionId)).sendCardPick(cardId);
|
||||
public DraftPickView sendCardPick(UUID sessionId, UUID cardId) {
|
||||
if (draftSessions.get(sessionPlayerMap.get(sessionId)).sendCardPick(cardId)) {
|
||||
return getDraftPickView(sessionPlayerMap.get(sessionId), 0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private synchronized void updateDraft() {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ package mage.server.draft;
|
|||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import mage.game.draft.Draft;
|
||||
import mage.view.DraftPickView;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -61,8 +62,8 @@ public class DraftManager {
|
|||
draftControllers.remove(gameId);
|
||||
}
|
||||
|
||||
public void sendCardPick(UUID draftId, UUID sessionId, UUID cardId) {
|
||||
draftControllers.get(draftId).sendCardPick(sessionId, cardId);
|
||||
public DraftPickView sendCardPick(UUID draftId, UUID sessionId, UUID cardId) {
|
||||
return draftControllers.get(draftId).sendCardPick(sessionId, cardId);
|
||||
}
|
||||
|
||||
public void removeSession(UUID sessionId) {
|
||||
|
|
|
|||
|
|
@ -151,9 +151,10 @@ public class DraftSession {
|
|||
killed = true;
|
||||
}
|
||||
|
||||
public void sendCardPick(UUID cardId) {
|
||||
public boolean sendCardPick(UUID cardId) {
|
||||
cancelTimeout();
|
||||
draft.addPick(playerId, cardId);
|
||||
return draft.addPick(playerId, cardId);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@ import mage.view.TableView;
|
|||
public interface GamesRoom extends Room {
|
||||
|
||||
public List<TableView> getTables();
|
||||
public boolean joinTable(UUID sessionId, UUID tableId, String name, DeckCardLists deckList) throws GameException;
|
||||
public boolean joinTournamentTable(UUID sessionId, UUID tableId, String name) throws GameException;
|
||||
public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, DeckCardLists deckList) throws GameException;
|
||||
public boolean joinTournamentTable(UUID sessionId, UUID tableId, String name, String playerType) throws GameException;
|
||||
public TableView createTable(UUID sessionId, MatchOptions options);
|
||||
public TableView createTournamentTable(UUID sessionId, TournamentOptions options);
|
||||
public void removeTable(UUID sessionId, UUID tableId);
|
||||
|
|
|
|||
|
|
@ -65,9 +65,9 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean joinTable(UUID sessionId, UUID tableId, String name, DeckCardLists deckList) throws GameException {
|
||||
public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, DeckCardLists deckList) throws GameException {
|
||||
if (tables.containsKey(tableId)) {
|
||||
return TableManager.getInstance().joinTable(sessionId, tableId, name, deckList);
|
||||
return TableManager.getInstance().joinTable(sessionId, tableId, name, playerType, deckList);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -81,9 +81,9 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean joinTournamentTable(UUID sessionId, UUID tableId, String name) throws GameException {
|
||||
public boolean joinTournamentTable(UUID sessionId, UUID tableId, String name, String playerType) throws GameException {
|
||||
if (tables.containsKey(tableId)) {
|
||||
return TableManager.getInstance().joinTournament(sessionId, tableId, name);
|
||||
return TableManager.getInstance().joinTournament(sessionId, tableId, name, playerType);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ public class TournamentController {
|
|||
checkStart();
|
||||
}
|
||||
|
||||
public void join(UUID sessionId) {
|
||||
public synchronized void join(UUID sessionId) {
|
||||
UUID playerId = sessionPlayerMap.get(sessionId);
|
||||
TournamentSession tournamentSession = new TournamentSession(tournament, sessionId, playerId);
|
||||
tournamentSessions.put(playerId, tournamentSession);
|
||||
|
|
@ -157,8 +157,8 @@ public class TournamentController {
|
|||
Table table = tableManager.createTable(sessionId, matchOptions);
|
||||
TournamentPlayer player1 = pair.getPlayer1();
|
||||
TournamentPlayer player2 = pair.getPlayer2();
|
||||
tableManager.addPlayer(getPlayerSessionId(player1.getPlayer().getId()), table.getId(), player1.getPlayer(), player1.getDeck());
|
||||
tableManager.addPlayer(getPlayerSessionId(player2.getPlayer().getId()), table.getId(), player2.getPlayer(), player2.getDeck());
|
||||
tableManager.addPlayer(getPlayerSessionId(player1.getPlayer().getId()), table.getId(), player1.getPlayer(), player1.getPlayerType(), player1.getDeck());
|
||||
tableManager.addPlayer(getPlayerSessionId(player2.getPlayer().getId()), table.getId(), player2.getPlayer(), player2.getPlayerType(), player2.getDeck());
|
||||
tableManager.startMatch(sessionId, null, table.getId());
|
||||
pair.setMatch(tableManager.getMatch(table.getId()));
|
||||
} catch (GameException ex) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue