Merge pull request #659 from SalavecJ/tournament_fixes
Tournament fixes
This commit is contained in:
@@ -145,7 +145,7 @@ public class TournamentRequestHandler extends LotroServerRequestHandler implemen
|
||||
Document doc = documentBuilder.newDocument();
|
||||
Element tournaments = doc.createElement("tournaments");
|
||||
|
||||
for (Tournament tournament : _tournamentService.getOldTournaments(ZonedDateTime.now().minus(RecentTournamentDuration))) {
|
||||
for (Tournament tournament : _tournamentService.getOldTournaments(ZonedDateTime.now().minus(RecentTournamentDuration)).reversed()) {
|
||||
Element tournamentElem = doc.createElement("tournament");
|
||||
|
||||
tournamentElem.setAttribute("id", tournament.getTournamentId());
|
||||
@@ -155,6 +155,10 @@ public class TournamentRequestHandler extends LotroServerRequestHandler implemen
|
||||
tournamentElem.setAttribute("round", String.valueOf(tournament.getCurrentRound()));
|
||||
tournamentElem.setAttribute("stage", tournament.getTournamentStage().getHumanReadable());
|
||||
|
||||
if (tournament.getTournamentStage().equals(Tournament.Stage.FINISHED) && tournament.getCurrentRound() == 0) {
|
||||
// do NOT include past tournaments with 0 games played (for example draft of one player against bots)
|
||||
continue;
|
||||
}
|
||||
tournaments.appendChild(tournamentElem);
|
||||
}
|
||||
|
||||
|
||||
@@ -409,6 +409,7 @@ var ChatBoxUI = Class.extend({
|
||||
if(this.tournamentCallback) {
|
||||
this.tournamentCallback(from, text);
|
||||
}
|
||||
from = "TournamentSystem";
|
||||
}
|
||||
var prefix = "<div class='msg-identifier'>";
|
||||
if (this.showTimestamps) {
|
||||
|
||||
@@ -35,13 +35,11 @@ var TournamentResultsUI = Class.extend({
|
||||
});
|
||||
},
|
||||
|
||||
loadedTournament:function (xml) {
|
||||
loadedTournament:function (xml, targetDiv) {
|
||||
var that = this;
|
||||
log(xml);
|
||||
var root = xml.documentElement;
|
||||
if (root.tagName == 'tournament') {
|
||||
$("#tournamentExtraInfo").html("");
|
||||
|
||||
var tournament = root;
|
||||
|
||||
var tournamentId = tournament.getAttribute("id");
|
||||
@@ -51,16 +49,16 @@ var TournamentResultsUI = Class.extend({
|
||||
var tournamentRound = tournament.getAttribute("round");
|
||||
var tournamentStage = tournament.getAttribute("stage");
|
||||
|
||||
$("#tournamentExtraInfo").append("<div class='tournamentName'>" + tournamentName + "</div>");
|
||||
|
||||
$("#tournamentExtraInfo").append("<div class='tournamentFormat'><b>Format:</b> " + tournamentFormat + "</div>");
|
||||
$("#tournamentExtraInfo").append("<div class='tournamentCollection'><b>Collection:</b> " + tournamentCollection + "</div>");
|
||||
targetDiv.append("<div class='tournamentFormat'><b>Format:</b> " + tournamentFormat + "</div>");
|
||||
targetDiv.append("<div class='tournamentCollection'><b>Collection:</b> " + tournamentCollection + "</div>");
|
||||
if (tournamentStage == "Playing games")
|
||||
$("#tournamentExtraInfo").append("<div class='tournamentRound'><b>Round:</b> " + tournamentRound + "</div>");
|
||||
targetDiv.append("<div class='tournamentRound'><b>Round:</b> " + tournamentRound + "</div>");
|
||||
|
||||
var standings = tournament.getElementsByTagName("tournamentStanding");
|
||||
if (standings.length > 0)
|
||||
$("#tournamentExtraInfo").append(this.createStandingsTable(standings, tournamentId, tournamentStage));
|
||||
targetDiv.append(this.createStandingsTable(standings, tournamentId, tournamentStage));
|
||||
|
||||
targetDiv.show();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -90,22 +88,25 @@ var TournamentResultsUI = Class.extend({
|
||||
$("#tournamentResults").append("<div class='tournamentRound'><b>Rounds:</b> " + tournamentRound + "</div>");
|
||||
|
||||
var detailsBut = $("<button>See details</button>").button();
|
||||
$("#tournamentResults").append(detailsBut);
|
||||
|
||||
var extraInfoDiv = $("<div class='tournamentExtraInfo' style='display:none;'></div>");
|
||||
$("#tournamentResults").append(extraInfoDiv);
|
||||
|
||||
detailsBut.click(
|
||||
(function (id) {
|
||||
(function (id, extraInfoTarget) {
|
||||
return function () {
|
||||
var btn = $(this);
|
||||
that.communication.getTournament(id,
|
||||
function (xml) {
|
||||
that.loadedTournament(xml);
|
||||
that.loadedTournament(xml, extraInfoTarget);
|
||||
btn.hide();
|
||||
});
|
||||
};
|
||||
})(tournamentId));
|
||||
$("#tournamentResults").append(detailsBut);
|
||||
})(tournamentId, extraInfoDiv));
|
||||
}
|
||||
if (tournaments.length == 0)
|
||||
$("#tournamentResults").append("<i>There is no running tournaments at the moment</i>");
|
||||
|
||||
$("#tournamentResults").append("<hr />");
|
||||
$("#tournamentResults").append("<div id='tournamentExtraInfo'></div>");
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -555,10 +555,11 @@ public class HallServer extends AbstractServer {
|
||||
if (tournament.getInfo().Parameters().requiresDeck) {
|
||||
lotroDeck = validateUserAndDeck(_formatLibrary.getFormat(tournament.getFormatCode()), player, deckName, tournament.getCollectionType());
|
||||
}
|
||||
|
||||
_tournamentService.recordTournamentPlayer(tournamentId, player.getName(), lotroDeck);
|
||||
tournament.issuePlayerMaterial(player.getName());
|
||||
if (_tournamentService.joinTournamentLate(tournamentId, player.getName(), lotroDeck)) {
|
||||
result = "Joined tournament <b>" + tournament.getTournamentName() + "</b> successfully.";
|
||||
} else {
|
||||
result = "Joining tournament <b>" + tournament.getTournamentName() + "</b> failed.";
|
||||
}
|
||||
hallChanged();
|
||||
}
|
||||
|
||||
@@ -582,13 +583,13 @@ public class HallServer extends AbstractServer {
|
||||
var submitted = tournament.playerSubmittedDeck(player.getName(), lotroDeck);
|
||||
|
||||
if(submitted) {
|
||||
result = "Registered deck '" + deckName + "' with tournament <b>" + tournament.getTournamentName() + "</b> successfully."
|
||||
+ "<br/><br/>If you make an update to your deck, you will need to register it here again for any changes to take effect.";
|
||||
result = "Registered deck '" + deckName + "' with tournament '" + tournament.getTournamentName() + "' successfully. "
|
||||
+ "If you make an update to your deck, you will need to register it here again for any changes to take effect.";
|
||||
_log.trace("Player '" + player.getName() + "' registered deck '" + deckName + "' for tournament '" + tournament.getTournamentName() + "' successfully.");
|
||||
}
|
||||
else {
|
||||
result = "Could not register deck with tournament <b>" + tournament.getTournamentName() + "</b>."
|
||||
+ "<br/><br/>Please contact an administrator if you think this was in error.";
|
||||
result = "Could not register deck with tournament '" + tournament.getTournamentName() + "'. "
|
||||
+ "Please contact an administrator if you think this was in error.";
|
||||
|
||||
_log.trace("Player '" + player.getName() + "' failed to register deck '" + deckName + "' for tournament '" + tournament.getTournamentName() + "'.");
|
||||
}
|
||||
|
||||
@@ -536,4 +536,26 @@ public abstract class BaseTournament implements Tournament {
|
||||
public String getTableDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean join(String playerName, LotroDeck lotroDeck) {
|
||||
// Assumes the deck is validated for the tournament or null if the tournament is limited
|
||||
writeLock.lock();
|
||||
try {
|
||||
if (!isJoinable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_players.contains(playerName)) {
|
||||
return false;
|
||||
}
|
||||
_tournamentService.recordTournamentPlayer(_tournamentId, playerName, lotroDeck);
|
||||
issuePlayerMaterial(playerName);
|
||||
_players.add(playerName);
|
||||
regeneratePlayerList();
|
||||
return true;
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,6 +206,7 @@ public interface Tournament {
|
||||
TournamentInfo getInfo();
|
||||
|
||||
boolean isJoinable();
|
||||
boolean join(String playerName, LotroDeck lotroDeck);
|
||||
long getSecondsRemaining() throws IllegalStateException;
|
||||
String getTableDescription();
|
||||
}
|
||||
|
||||
@@ -332,6 +332,15 @@ public class TournamentService {
|
||||
_tournamentPlayerDao.addPlayer(tournamentId, playerName, deck);
|
||||
}
|
||||
|
||||
public boolean joinTournamentLate(String tournamentId, String playerName, LotroDeck deck) {
|
||||
// Assumes the deck is validated for the tournament or null if the tournament is limited
|
||||
Tournament tournament = getTournamentById(tournamentId);
|
||||
if (tournament == null) {
|
||||
return false;
|
||||
}
|
||||
return tournament.join(playerName, deck);
|
||||
}
|
||||
|
||||
public void recordPlayerTournamentAbandon(String tournamentId, String playerName) {
|
||||
_tournamentPlayerDao.dropPlayer(tournamentId, playerName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user