mirror of
https://github.com/correl/mage.git
synced 2025-01-12 03:00:13 +00:00
* Tournament handling - Fixed player handling for swiss tournament. No more quit sound or stat eif player already finished the tournament correctly.
This commit is contained in:
parent
95b9507c0c
commit
0e71ac5e53
7 changed files with 75 additions and 46 deletions
|
@ -45,18 +45,18 @@ public class TournamentPlayerView implements Serializable, Comparable{
|
|||
private final int points;
|
||||
private final boolean quit;
|
||||
|
||||
TournamentPlayerView(TournamentPlayer player) {
|
||||
this.name = player.getPlayer().getName();
|
||||
StringBuilder sb = new StringBuilder(player.getState().toString());
|
||||
String stateInfo = player.getStateInfo();
|
||||
TournamentPlayerView(TournamentPlayer tournamentPlayer) {
|
||||
this.name = tournamentPlayer.getPlayer().getName();
|
||||
StringBuilder sb = new StringBuilder(tournamentPlayer.getState().toString());
|
||||
String stateInfo = tournamentPlayer.getStateInfo();
|
||||
if (!stateInfo.isEmpty()) {
|
||||
sb.append(" (").append(stateInfo).append(")");
|
||||
}
|
||||
sb.append(player.getDisconnectInfo());
|
||||
sb.append(tournamentPlayer.getDisconnectInfo());
|
||||
this.state = sb.toString();
|
||||
this.points = player.getPoints();
|
||||
this.results = player.getResults();
|
||||
this.quit = player.getState().equals(TournamentPlayerState.ELIMINATED) || player.getState().equals(TournamentPlayerState.CANCELED);
|
||||
this.points = tournamentPlayer.getPoints();
|
||||
this.results = tournamentPlayer.getResults();
|
||||
this.quit = !tournamentPlayer.isInTournament();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
|
|
@ -365,7 +365,7 @@ public class User {
|
|||
for (Map.Entry<UUID, Table> tableEntry : tables.entrySet()) {
|
||||
Table table = tableEntry.getValue();
|
||||
if (table.isTournament()) {
|
||||
if (!table.getTournament().getPlayer(tableEntry.getKey()).getEliminated()) {
|
||||
if (!table.getTournament().getPlayer(tableEntry.getKey()).isEliminated()) {
|
||||
switch (table.getState()) {
|
||||
case CONSTRUCTING:
|
||||
construct++;
|
||||
|
|
|
@ -296,34 +296,36 @@ public class TournamentController {
|
|||
TournamentPlayer tPlayer = tournament.getPlayer(playerId);
|
||||
if (tPlayer != null) {
|
||||
if (started) {
|
||||
ChatManager.getInstance().broadcast(chatId, "", tPlayer.getPlayer().getName() + " has quit the tournament", MessageColor.BLACK, true, MessageType.STATUS, SoundToPlay.PlayerLeft);
|
||||
String info;
|
||||
if (tournament.isDoneConstructing()) {
|
||||
info = new StringBuilder("during round ").append(tournament.getRounds().size()).toString();
|
||||
// quit active matches of that tournament
|
||||
TableManager.getInstance().userQuitTournamentSubTables(tournament.getId(), userId);
|
||||
} else {
|
||||
if (tPlayer.getState().equals(TournamentPlayerState.DRAFTING)) {
|
||||
info = "during Draft phase";
|
||||
if (!checkToReplaceDraftPlayerByAi(userId, tPlayer)) {
|
||||
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);
|
||||
if (tPlayer.isInTournament()) {
|
||||
ChatManager.getInstance().broadcast(chatId, "", tPlayer.getPlayer().getName() + " has quit the tournament", MessageColor.BLACK, true, MessageType.STATUS, SoundToPlay.PlayerLeft);
|
||||
String info;
|
||||
if (tournament.isDoneConstructing()) {
|
||||
info = new StringBuilder("during round ").append(tournament.getRounds().size()).toString();
|
||||
// quit active matches of that tournament
|
||||
TableManager.getInstance().userQuitTournamentSubTables(tournament.getId(), userId);
|
||||
} else {
|
||||
if (tPlayer.getState().equals(TournamentPlayerState.DRAFTING)) {
|
||||
info = "during Draft phase";
|
||||
if (!checkToReplaceDraftPlayerByAi(userId, tPlayer)) {
|
||||
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";
|
||||
} else {
|
||||
info = "";
|
||||
}
|
||||
} else if (tPlayer.getState().equals(TournamentPlayerState.CONSTRUCTING)) {
|
||||
info = "during Construction phase";
|
||||
} else {
|
||||
info = "";
|
||||
}
|
||||
tPlayer.setQuit(info);
|
||||
tournament.quit(playerId);
|
||||
}
|
||||
tPlayer.setQuit(info);
|
||||
tournament.quit(playerId);
|
||||
} else {
|
||||
tournament.leave(playerId);
|
||||
}
|
||||
|
@ -392,7 +394,7 @@ public class TournamentController {
|
|||
|
||||
private void checkPlayersState() {
|
||||
for (TournamentPlayer tournamentPlayer: tournament.getPlayers()) {
|
||||
if (!tournamentPlayer.getEliminated() && tournamentPlayer.getPlayer().isHuman()) {
|
||||
if (!tournamentPlayer.isEliminated() && tournamentPlayer.getPlayer().isHuman()) {
|
||||
if (tournamentSessions.containsKey(tournamentPlayer.getPlayer().getId())) {
|
||||
if (tournamentSessions.get(tournamentPlayer.getPlayer().getId()).isKilled()) {
|
||||
tournamentPlayer.setEliminated();
|
||||
|
|
|
@ -40,8 +40,8 @@ public class Round {
|
|||
|
||||
private final int roundNum;
|
||||
private final Tournament tournament;
|
||||
private final List<TournamentPairing> pairs = new ArrayList<TournamentPairing>();
|
||||
private final List<TournamentPlayer> playerByes = new ArrayList<TournamentPlayer>();
|
||||
private final List<TournamentPairing> pairs = new ArrayList<>();
|
||||
private final List<TournamentPlayer> playerByes = new ArrayList<>();
|
||||
|
||||
public Round(int roundNum, Tournament tournament) {
|
||||
this.roundNum = roundNum;
|
||||
|
@ -81,6 +81,10 @@ public class Round {
|
|||
if (tournament instanceof TournamentSingleElimination) {
|
||||
pair.eliminatePlayers();
|
||||
}
|
||||
// if it's the last round, finish all players for the tournament if their match is finished
|
||||
if (getRoundNumber() == tournament.getNumberRounds()) {
|
||||
pair.finishPlayersThatPlayedLastRound();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -225,7 +225,7 @@ public abstract class TournamentImpl implements Tournament {
|
|||
protected List<TournamentPlayer> getActivePlayers() {
|
||||
List<TournamentPlayer> activePlayers = new ArrayList<>();
|
||||
for (TournamentPlayer player: players.values()) {
|
||||
if (!player.getEliminated()) {
|
||||
if (!player.isEliminated()) {
|
||||
activePlayers.add(player);
|
||||
}
|
||||
}
|
||||
|
@ -440,17 +440,21 @@ public abstract class TournamentImpl implements Tournament {
|
|||
}
|
||||
|
||||
protected void winners() {
|
||||
// TODO: Generate StateInfo for Swiss pairing (1st, 2nd, ...)
|
||||
for(TournamentPlayer winner: this.getActivePlayers()) {
|
||||
winner.setState(TournamentPlayerState.FINISHED);
|
||||
if (options.getNumberRounds() == 0) { // if no swiss, last active is the winner
|
||||
if (isAbort()) {
|
||||
winner.setStateInfo("Tournament canceled");
|
||||
} else {
|
||||
winner.setStateInfo("Winner");
|
||||
}
|
||||
List<TournamentPlayer> winners = new ArrayList<>();
|
||||
int pointsWinner = Integer.MIN_VALUE;
|
||||
for(TournamentPlayer tournamentPlayer: this.getPlayers()) {
|
||||
if (pointsWinner < tournamentPlayer.getPoints()) {
|
||||
winners.clear();
|
||||
winners.add(tournamentPlayer);
|
||||
pointsWinner = tournamentPlayer.getPoints();
|
||||
} else if (pointsWinner == tournamentPlayer.getPoints()) {
|
||||
winners.add(tournamentPlayer);
|
||||
}
|
||||
}
|
||||
// set winner state for the players with the most points
|
||||
for (TournamentPlayer tournamentPlayer: winners) {
|
||||
tournamentPlayer.setStateInfo("Winner");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
package mage.game.tournament;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.constants.TournamentPlayerState;
|
||||
import mage.game.match.Match;
|
||||
import mage.game.match.MatchPlayer;
|
||||
|
||||
|
@ -86,6 +87,18 @@ public class TournamentPairing {
|
|||
}
|
||||
}
|
||||
}
|
||||
public void finishPlayersThatPlayedLastRound() {
|
||||
if (match.hasEnded()) {
|
||||
if (!player1.isEliminated()) {
|
||||
player1.setEliminated();
|
||||
player1.setState(TournamentPlayerState.FINISHED);
|
||||
}
|
||||
if (!player2.isEliminated()) {
|
||||
player2.setEliminated();
|
||||
player2.setState(TournamentPlayerState.FINISHED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void eliminateComputer() {
|
||||
if (!player1.getPlayer().isHuman()) {
|
||||
|
|
|
@ -83,7 +83,7 @@ public class TournamentPlayer {
|
|||
this.points = points;
|
||||
}
|
||||
|
||||
public boolean getEliminated() {
|
||||
public boolean isEliminated() {
|
||||
return eliminated;
|
||||
}
|
||||
|
||||
|
@ -209,5 +209,11 @@ public class TournamentPlayer {
|
|||
this.setState(TournamentPlayerState.FINISHED);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInTournament() {
|
||||
return !this.getState().equals(TournamentPlayerState.CANCELED)
|
||||
&& !this.getState().equals(TournamentPlayerState.ELIMINATED)
|
||||
&& !this.getState().equals(TournamentPlayerState.FINISHED);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue