mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
* Draft - Added "Quit Tournament" button to draft panel. Minor formatting.
This commit is contained in:
parent
024ec1169a
commit
8d2f4cc9ac
26 changed files with 340 additions and 157 deletions
|
|
@ -40,6 +40,7 @@ import mage.cards.repository.CardRepository;
|
|||
import mage.cards.repository.ExpansionInfo;
|
||||
import mage.cards.repository.ExpansionRepository;
|
||||
import mage.game.GameException;
|
||||
import mage.game.Table;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.interfaces.Action;
|
||||
|
|
@ -659,6 +660,22 @@ public class MageServerImpl implements MageServer {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void quitDraft(final UUID draftId, final String sessionId) throws MageException {
|
||||
execute("quitDraft", sessionId, new Action() {
|
||||
@Override
|
||||
public void execute() {
|
||||
UUID tableId = DraftManager.getInstance().getControllerByDraftId(draftId).getTableId();
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
Table table = TableManager.getInstance().getTable(tableId);
|
||||
if (table.isTournament()) {
|
||||
UUID tournamentId = table.getTournament().getId();
|
||||
TournamentManager.getInstance().quit(tournamentId, userId);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("undo", sessionId, new Action() {
|
||||
|
|
|
|||
|
|
@ -28,10 +28,15 @@
|
|||
|
||||
package mage.server;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import mage.MageException;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.players.net.UserData;
|
||||
import mage.players.net.UserGroup;
|
||||
import mage.server.util.ConfigSettings;
|
||||
import mage.view.UserDataView;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jboss.remoting.callback.AsynchInvokerCallbackHandler;
|
||||
|
|
@ -39,12 +44,6 @@ import org.jboss.remoting.callback.Callback;
|
|||
import org.jboss.remoting.callback.HandleCallbackException;
|
||||
import org.jboss.remoting.callback.InvokerCallbackHandler;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import mage.server.util.ConfigSettings;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -53,13 +52,13 @@ public class Session {
|
|||
|
||||
private static final Logger logger = Logger.getLogger(Session.class);
|
||||
|
||||
private String sessionId;
|
||||
private final String sessionId;
|
||||
private UUID userId;
|
||||
private String host;
|
||||
private int messageId = 0;
|
||||
private Date timeConnected;
|
||||
private final Date timeConnected;
|
||||
private boolean isAdmin = false;
|
||||
private AsynchInvokerCallbackHandler callbackHandler;
|
||||
private final AsynchInvokerCallbackHandler callbackHandler;
|
||||
|
||||
public Session(String sessionId, InvokerCallbackHandler callbackHandler) {
|
||||
this.sessionId = sessionId;
|
||||
|
|
@ -134,30 +133,42 @@ public class Session {
|
|||
}
|
||||
|
||||
private void updateAvatar(String userName, UserData userData) {
|
||||
//TODO: move to separate class
|
||||
//TODO: move to separate class
|
||||
//TODO: add for checking for private key
|
||||
if (userName.equals("nantuko")) {
|
||||
userData.setAvatarId(1000);
|
||||
} else if (userName.equals("i_no_k")) {
|
||||
userData.setAvatarId(1002);
|
||||
} else if (userName.equals("Askael")) {
|
||||
userData.setAvatarId(1004);
|
||||
} else if (userName.equals("North")) {
|
||||
userData.setAvatarId(1006);
|
||||
} else if (userName.equals("BetaSteward")) {
|
||||
userData.setAvatarId(1008);
|
||||
} else if (userName.equals("Arching")) {
|
||||
userData.setAvatarId(1010);
|
||||
} else if (userName.equals("loki")) {
|
||||
userData.setAvatarId(1012);
|
||||
} else if (userName.equals("Alive")) {
|
||||
userData.setAvatarId(1014);
|
||||
} else if (userName.equals("Rahan")) {
|
||||
userData.setAvatarId(1016);
|
||||
} else if (userName.equals("Ayrat")) {
|
||||
userData.setAvatarId(1018);
|
||||
} else if (userName.equals("Bandit")) {
|
||||
userData.setAvatarId(1020);
|
||||
switch (userName) {
|
||||
case "nantuko":
|
||||
userData.setAvatarId(1000);
|
||||
break;
|
||||
case "i_no_k":
|
||||
userData.setAvatarId(1002);
|
||||
break;
|
||||
case "Askael":
|
||||
userData.setAvatarId(1004);
|
||||
break;
|
||||
case "North":
|
||||
userData.setAvatarId(1006);
|
||||
break;
|
||||
case "BetaSteward":
|
||||
userData.setAvatarId(1008);
|
||||
break;
|
||||
case "Arching":
|
||||
userData.setAvatarId(1010);
|
||||
break;
|
||||
case "loki":
|
||||
userData.setAvatarId(1012);
|
||||
break;
|
||||
case "Alive":
|
||||
userData.setAvatarId(1014);
|
||||
break;
|
||||
case "Rahan":
|
||||
userData.setAvatarId(1016);
|
||||
break;
|
||||
case "Ayrat":
|
||||
userData.setAvatarId(1018);
|
||||
break;
|
||||
case "Bandit":
|
||||
userData.setAvatarId(1020);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public class SessionManager {
|
|||
public static SessionManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
private ConcurrentHashMap<String, Session> sessions = new ConcurrentHashMap<String, Session>();
|
||||
private final ConcurrentHashMap<String, Session> sessions = new ConcurrentHashMap<>();
|
||||
|
||||
public Session getSession(String sessionId) {
|
||||
if (sessions == null || sessionId == null) {
|
||||
|
|
@ -116,7 +116,7 @@ public class SessionManager {
|
|||
}
|
||||
|
||||
public Map<String, Session> getSessions() {
|
||||
Map<String, Session> map = new HashMap<String, Session>();
|
||||
Map<String, Session> map = new HashMap<>();
|
||||
for (Map.Entry<String, Session> entry : sessions.entrySet()) {
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
|
@ -139,10 +139,7 @@ public class SessionManager {
|
|||
}
|
||||
|
||||
public boolean isValidSession(String sessionId) {
|
||||
if (sessions.containsKey(sessionId)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return sessions.containsKey(sessionId);
|
||||
}
|
||||
|
||||
public User getUser(String sessionId) {
|
||||
|
|
|
|||
|
|
@ -168,11 +168,11 @@ public class TableController {
|
|||
return false;
|
||||
}
|
||||
tournament.addPlayer(player, seat.getPlayerType());
|
||||
table.joinTable(player, seat);
|
||||
user.addTable(player.getId(), table);
|
||||
table.joinTable(player, seat);
|
||||
logger.debug("player joined " + player.getId());
|
||||
//only inform human players and add them to sessionPlayerMap
|
||||
if (seat.getPlayer().isHuman()) {
|
||||
user.addTable(player.getId(), table);
|
||||
user.joinedTable(table.getRoomId(), table.getId(), true);
|
||||
userPlayerMap.put(userId, player.getId());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,11 +55,11 @@ public class DraftController {
|
|||
private static final Logger logger = Logger.getLogger(GameController.class);
|
||||
public static final String INIT_FILE_PATH = "config" + File.separator + "init.txt";
|
||||
|
||||
private ConcurrentHashMap<UUID, DraftSession> draftSessions = new ConcurrentHashMap<UUID, DraftSession>();
|
||||
private ConcurrentHashMap<UUID, UUID> userPlayerMap;
|
||||
private UUID draftSessionId;
|
||||
private Draft draft;
|
||||
private UUID tableId;
|
||||
private final ConcurrentHashMap<UUID, DraftSession> draftSessions = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<UUID, UUID> userPlayerMap;
|
||||
private final UUID draftSessionId;
|
||||
private final Draft draft;
|
||||
private final UUID tableId;
|
||||
|
||||
public DraftController(Draft draft, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId) {
|
||||
draftSessionId = UUID.randomUUID();
|
||||
|
|
@ -130,10 +130,20 @@ public class DraftController {
|
|||
checkStart();
|
||||
}
|
||||
|
||||
public DraftSession getDraftSession(UUID playerId) {
|
||||
if (draftSessions.containsKey(playerId)) {
|
||||
return draftSessions.get(playerId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean replacePlayer(Player oldPlayer, Player newPlayer) {
|
||||
if (draft.replacePlayer(oldPlayer, newPlayer)) {
|
||||
draftSessions.get(oldPlayer.getId()).setKilled();
|
||||
draftSessions.remove(oldPlayer.getId());
|
||||
if (draft.replacePlayer(oldPlayer, newPlayer)) {
|
||||
DraftSession draftSession = draftSessions.get(oldPlayer.getId());
|
||||
if (draftSession != null) {
|
||||
draftSession.draftOver(); // closes the draft panel of the replaced player
|
||||
draftSessions.remove(oldPlayer.getId());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class DraftManager {
|
|||
|
||||
private DraftManager() {}
|
||||
|
||||
private ConcurrentHashMap<UUID, DraftController> draftControllers = new ConcurrentHashMap<UUID, DraftController>();
|
||||
private final ConcurrentHashMap<UUID, DraftController> draftControllers = new ConcurrentHashMap<>();
|
||||
|
||||
public UUID createDraftSession(Draft draft, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId) {
|
||||
DraftController draftController = new DraftController(draft, userPlayerMap, tableId);
|
||||
|
|
@ -84,6 +84,10 @@ public class DraftManager {
|
|||
draftControllers.remove(draftId);
|
||||
}
|
||||
|
||||
public DraftController getControllerByDraftId(UUID draftId) {
|
||||
return draftControllers.get(draftId);
|
||||
}
|
||||
|
||||
public DraftController getController(UUID tableId) {
|
||||
for (DraftController controller: draftControllers.values()) {
|
||||
if (controller.getTableId().equals(tableId)) {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,9 @@ import mage.server.TableController;
|
|||
import mage.server.TableManager;
|
||||
import mage.server.User;
|
||||
import mage.server.UserManager;
|
||||
import mage.server.draft.DraftController;
|
||||
import mage.server.draft.DraftManager;
|
||||
import mage.server.draft.DraftSession;
|
||||
import mage.server.game.GamesRoomManager;
|
||||
import mage.server.util.ThreadExecutor;
|
||||
import mage.view.ChatMessage.MessageColor;
|
||||
|
|
@ -75,8 +77,6 @@ public class TournamentController {
|
|||
private ConcurrentHashMap<UUID, UUID> userPlayerMap = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<UUID, TournamentSession> tournamentSessions = new ConcurrentHashMap<>();
|
||||
|
||||
private boolean abort = false;
|
||||
|
||||
public TournamentController(Tournament tournament, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId) {
|
||||
this.userPlayerMap = userPlayerMap;
|
||||
chatId = ChatManager.getInstance().createChatSession();
|
||||
|
|
@ -99,14 +99,14 @@ public class TournamentController {
|
|||
startDraft(event.getDraft());
|
||||
break;
|
||||
case CONSTRUCT:
|
||||
if (!abort) {
|
||||
if (!isAbort()) {
|
||||
construct();
|
||||
} else {
|
||||
endTournament();
|
||||
}
|
||||
break;
|
||||
case START_MATCH:
|
||||
if (!abort) {
|
||||
if (!isAbort()) {
|
||||
initTournament(); // set state
|
||||
startMatch(event.getPair(), event.getMatchOptions());
|
||||
}
|
||||
|
|
@ -193,9 +193,12 @@ public class TournamentController {
|
|||
}
|
||||
|
||||
private void endTournament() {
|
||||
for (TournamentPlayer player: tournament.getPlayers()) {
|
||||
player.setStateAtTournamentEnd();
|
||||
}
|
||||
for (final TournamentSession tournamentSession: tournamentSessions.values()) {
|
||||
tournamentSession.tournamentOver();
|
||||
tournamentSession.removeTournament();
|
||||
tournamentSession.removeTournamentForUser();
|
||||
}
|
||||
this.tournamentSessions.clear();
|
||||
TableManager.getInstance().endTournament(tableId, tournament);
|
||||
|
|
@ -286,7 +289,15 @@ public class TournamentController {
|
|||
if (tPlayer.getState().equals(TournamentPlayerState.DRAFTING)) {
|
||||
info = "during Draft phase";
|
||||
if (!checkToReplaceDraftPlayerByAi(userId, tPlayer)) {
|
||||
this.abortTournament();
|
||||
this.abortDraftTournament();
|
||||
} else {
|
||||
DraftController draftController = DraftManager.getInstance().getController(tableId);
|
||||
if (draftController != null) {
|
||||
DraftSession draftSession = draftController.getDraftSession(playerId);
|
||||
if (draftSession != null) {
|
||||
DraftManager.getInstance().kill(draftSession.getDraftId(), userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (tPlayer.getState().equals(TournamentPlayerState.CONSTRUCTING)) {
|
||||
info = "during Construction phase";
|
||||
|
|
@ -315,13 +326,18 @@ public class TournamentController {
|
|||
if (humans > 1) {
|
||||
String replacePlayerName = "Draftbot";
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user != null) {
|
||||
replacePlayerName = "Draftbot (" + user.getName() + ")";
|
||||
}
|
||||
TableController tableController = TableManager.getInstance().getController(tableId);
|
||||
if (tableController != null) {
|
||||
if (user != null) {
|
||||
replacePlayerName = "Draftbot (" + user.getName() + ")";
|
||||
}
|
||||
tableController.replaceDraftPlayer(leavingPlayer.getPlayer(), replacePlayerName, "Computer - draftbot", 5);
|
||||
ChatManager.getInstance().broadcast(chatId, "", leavingPlayer.getPlayer().getName() + " was replaced by draftbot", MessageColor.BLACK, true, null);
|
||||
if (user != null) {
|
||||
user.removeDraft(leavingPlayer.getPlayer().getId());
|
||||
user.removeTable(leavingPlayer.getPlayer().getId());
|
||||
user.removeTournament(leavingPlayer.getPlayer().getId());
|
||||
}
|
||||
ChatManager.getInstance().broadcast(chatId, "", leavingPlayer.getPlayer().getName() + " was replaced by draftbot", MessageColor.BLACK, true, MessageType.STATUS);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -341,8 +357,12 @@ public class TournamentController {
|
|||
return new TournamentView(tournament);
|
||||
}
|
||||
|
||||
private void abortTournament() {
|
||||
this.abort = true;
|
||||
private void abortDraftTournament() {
|
||||
tournament.setAbort(true);
|
||||
DraftManager.getInstance().getController(tableId).abortDraft();
|
||||
}
|
||||
|
||||
public boolean isAbort() {
|
||||
return tournament.isAbort();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ public class TournamentSession {
|
|||
}
|
||||
}
|
||||
|
||||
public void removeTournament() {
|
||||
public void removeTournamentForUser() {
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user != null) {
|
||||
user.removeTournament(playerId);
|
||||
|
|
@ -163,7 +163,7 @@ public class TournamentSession {
|
|||
}
|
||||
|
||||
void tournamentOver() {
|
||||
//TODO: implement this
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue