mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
* Fixed a bug in table expired check. Changed expired check. Some fixed for table / tournament state handling.
This commit is contained in:
parent
7269660ff1
commit
8b331eefce
3 changed files with 77 additions and 26 deletions
|
|
@ -64,6 +64,7 @@ import mage.server.game.GameManager;
|
|||
import mage.server.game.PlayerFactory;
|
||||
import mage.server.services.LogKeys;
|
||||
import mage.server.services.impl.LogServiceImpl;
|
||||
import mage.server.tournament.TournamentController;
|
||||
import mage.server.tournament.TournamentFactory;
|
||||
import mage.server.tournament.TournamentManager;
|
||||
import mage.server.util.ConfigSettings;
|
||||
|
|
@ -782,28 +783,67 @@ public class TableController {
|
|||
return match;
|
||||
}
|
||||
|
||||
public boolean isMatchTableStillValid() {
|
||||
// check only normal match table
|
||||
if (!table.isTournament() && !table.isTournamentSubTable()) {
|
||||
int humanPlayers = 0;
|
||||
int validHumanPlayers = 0;
|
||||
if (match == null) {
|
||||
return false;
|
||||
public boolean isTournamentStillValid() {
|
||||
if (table.getTournament() != null) {
|
||||
TournamentController tournamentController = TournamentManager.getInstance().getTournamentController(table.getTournament().getId());
|
||||
if (tournamentController != null) {
|
||||
//TODO: Check tournament state
|
||||
}
|
||||
for(Map.Entry<UUID, UUID> userPlayerEntry: userPlayerMap.entrySet()) {
|
||||
MatchPlayer matchPlayer = match.getPlayer(userPlayerEntry.getValue());
|
||||
if (matchPlayer.getPlayer().isHuman()) {
|
||||
humanPlayers++;
|
||||
if (!matchPlayer.hasQuit()) {
|
||||
User user = UserManager.getInstance().getUser(userPlayerEntry.getKey());
|
||||
if (user != null && user.isExpired(null)) {
|
||||
validHumanPlayers++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isMatchTableStillValid() {
|
||||
// check only normal match table with state != Finished
|
||||
if (!table.isTournament()) {
|
||||
int humanPlayers = 0;
|
||||
int aiPlayers = 0 ;
|
||||
int validHumanPlayers = 0;
|
||||
if (match == null && !(table.getState().equals(TableState.WAITING) ||
|
||||
table.getState().equals(TableState.STARTING) ||
|
||||
table.getState().equals(TableState.READY_TO_START) )) {
|
||||
logger.debug("- Match table with no match:");
|
||||
logger.debug("-- matchId:" + match.getId() + " [" + match.getName() + "]");
|
||||
// return false;
|
||||
}
|
||||
if (match.isDoneSideboarding()) {
|
||||
if (match.getGame() == null) {
|
||||
// no sideboarding and not active game -> match seems to hang (maybe the Draw bug)
|
||||
logger.debug("- Match with no active game and not in sideboard state:");
|
||||
logger.debug("-- matchId:" + match.getId() + " [" + match.getName() + "]");
|
||||
// return false;
|
||||
}
|
||||
}
|
||||
// if at least 2 human players are valid (multiplayer) or all human players are valid the table is valid
|
||||
return validHumanPlayers >= 2 || validHumanPlayers == humanPlayers;
|
||||
// check for active players
|
||||
for(Map.Entry<UUID, UUID> userPlayerEntry: userPlayerMap.entrySet()) {
|
||||
MatchPlayer matchPlayer = match.getPlayer(userPlayerEntry.getValue());
|
||||
if (matchPlayer == null) {
|
||||
logger.debug("- Match player not found:");
|
||||
logger.debug("-- matchId:" + match.getId());
|
||||
logger.debug("-- userId:" + userPlayerEntry.getKey());
|
||||
logger.debug("-- playerId:" + userPlayerEntry.getValue());
|
||||
continue;
|
||||
}
|
||||
if (matchPlayer.getPlayer().isHuman()) {
|
||||
humanPlayers++;
|
||||
User user = UserManager.getInstance().getUser(userPlayerEntry.getKey());
|
||||
if (!matchPlayer.hasQuit()) {
|
||||
if (user == null) {
|
||||
logger.debug("- Active user of match is missing:");
|
||||
logger.debug("-- matchId:" + match.getId());
|
||||
logger.debug("-- userId:" + userPlayerEntry.getKey());
|
||||
logger.debug("-- playerId:" + userPlayerEntry.getValue());
|
||||
return false;
|
||||
}
|
||||
// user exits on the server and match player has not quit -> player is valid
|
||||
validHumanPlayers++;
|
||||
}
|
||||
} else {
|
||||
aiPlayers++;
|
||||
}
|
||||
}
|
||||
// if at least 2 human players are valid (multiplayer) or all human players are valid the table is valid or it's an AI match
|
||||
return validHumanPlayers >= 2 || validHumanPlayers == humanPlayers || aiPlayers > 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import java.util.UUID;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import mage.MageException;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.constants.TableState;
|
||||
import mage.constants.TournamentPlayerState;
|
||||
import mage.game.GameException;
|
||||
import mage.game.Table;
|
||||
|
|
@ -233,10 +234,12 @@ public class TournamentController {
|
|||
Table table = tableManager.createTable(GamesRoomManager.getInstance().getMainRoomId(), matchOptions);
|
||||
table.setTournamentSubTable(true);
|
||||
table.setTournament(tournament);
|
||||
table.setState(TableState.WAITING);
|
||||
TournamentPlayer player1 = pair.getPlayer1();
|
||||
TournamentPlayer player2 = pair.getPlayer2();
|
||||
tableManager.addPlayer(getPlayerUserId(player1.getPlayer().getId()), table.getId(), player1.getPlayer(), player1.getPlayerType(), player1.getDeck());
|
||||
tableManager.addPlayer(getPlayerUserId(player2.getPlayer().getId()), table.getId(), player2.getPlayer(), player2.getPlayerType(), player2.getDeck());
|
||||
table.setState(TableState.STARTING);
|
||||
tableManager.startTournamentSubMatch(null, table.getId());
|
||||
pair.setMatch(tableManager.getMatch(table.getId()));
|
||||
pair.setTableId(table.getId());
|
||||
|
|
@ -256,7 +259,9 @@ public class TournamentController {
|
|||
}
|
||||
|
||||
private void initTournament() {
|
||||
TableManager.getInstance().initTournament(tableId);
|
||||
if (!TableManager.getInstance().getTable(tableId).getState().equals(TableState.DUELING)) {
|
||||
TableManager.getInstance().initTournament(tableId);
|
||||
}
|
||||
}
|
||||
|
||||
private void construct(UUID playerId, int timeout) throws MageException {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue