");
if (notify) this.room.notifyOnce("Tournament created", "Room: " + this.room.title + "\nFormat: " + formatName + "\nType: " + type, 'tournament-create');
this.curTeamIndex = 0;
this.updateTeams();
break;
case 'join':
case 'leave':
if (this.$lastJoinLeaveMessage && !this.$lastJoinLeaveMessage.is(this.room.$chat.children().last())) {
this.$lastJoinLeaveMessage = null;
this.batchedJoins = [];
this.batchedLeaves = [];
}
if (!this.$lastJoinLeaveMessage) {
this.$lastJoinLeaveMessage = $('');
this.room.$chat.append(this.$lastJoinLeaveMessage);
}
if (cmd === 'join' && this.batchedJoins.indexOf(data[0]) < 0) {
this.batchedJoins.push(data[0]);
}
if (cmd === 'leave' && this.batchedLeaves.indexOf(data[0]) < 0) {
this.batchedLeaves.push(data[0]);
}
var message = [];
var joins = this.batchedJoins.slice(0, 5);
var leaves = this.batchedLeaves.slice(0, 5);
if (this.batchedJoins.length > 5) joins.push((this.batchedJoins.length - 5) + " others");
if (this.batchedLeaves.length > 5) leaves.push((this.batchedLeaves.length - 5) + " others");
if (joins.length > 0) message.push(arrayToPhrase(joins) + " joined the tournament");
if (leaves.length > 0) message.push(arrayToPhrase(leaves) + " left the tournament");
this.$lastJoinLeaveMessage.text(message.join("; ") + ".");
break;
case 'replace':
this.room.$chat.append("
" + BattleLog.escapeHTML(data[1]) + " has joined the tournament, replacing " + BattleLog.escapeHTML(data[0]) + ".
");
break;
case 'start':
this.room.closeNotification('tournament-create');
if (!this.info.isJoined) {
this.toggleBoxVisibility(false);
} else if (this.info.teambuilderFormat.substr(0, 4) === 'gen5' && !Dex.loadedSpriteData['bw']) {
Dex.loadSpriteData('bw');
}
var participants = data[0] ? " (" + data[0] + " players)" : "";
this.room.$chat.append("
The tournament has started!" + participants + "
");
break;
case 'disqualify':
this.room.$chat.append("
" + BattleLog.escapeHTML(data[0]) + " has been disqualified from the tournament.
");
break;
case 'autodq':
if (data[0] === 'off') {
this.room.$chat.append("
The tournament's automatic disqualify timer has been turned off.
");
} else if (data[0] === 'on') {
var minutes = (data[1] / 1000 / 60);
this.room.$chat.append("
The tournament's automatic disqualify timer has been set to " + minutes + " minute" + (minutes === 1 ? "" : "s") + ".
");
} else {
var seconds = Math.floor(data[1] / 1000);
app.addPopupMessage("Please respond to the tournament within " + seconds + " seconds or you may be automatically disqualified.");
if (notify) this.room.notifyOnce("Tournament Automatic Disqualification Warning", "Room: " + this.room.title + "\nSeconds: " + seconds, 'tournament-autodq-warning');
}
break;
case 'autostart':
if (data[0] === 'off') {
this.room.$chat.append("
The tournament's automatic start is now off.
");
} else if (data[0] === 'on') {
var minutes = (data[1] / 1000 / 60);
this.room.$chat.append("
The tournament will automatically start in " + minutes + " minute" + (minutes === 1 ? "" : "s") + ".
");
}
break;
case 'scouting':
if (data[0] === 'allow') {
this.room.$chat.append("
Scouting is now allowed (Tournament players can watch other tournament battles)
");
} else if (data[0] === 'disallow') {
this.room.$chat.append("
Scouting is now banned (Tournament players can't watch other tournament battles)
");
}
break;
case 'update':
$.extend(this.updates, JSON.parse(data.join('|')));
break;
case 'updateend':
$.extend(this.info, this.updates);
if (!this.info.isActive) {
this.$wrapper.addClass("active");
if (!this.info.isStarted || this.info.isJoined)
this.toggleBoxVisibility(true);
this.info.isActive = true;
}
if ('format' in this.updates || 'teambuilderFormat' in this.updates) {
if (!this.info.teambuilderFormat) this.info.teambuilderFormat = this.info.format;
this.$format.text(window.BattleFormats && BattleFormats[this.info.format] ? BattleFormats[this.info.format].name : this.info.format);
this.updateTeams();
}
if ('isJoined' in this.updates) {
this.updateTeams();
}
if ('generator' in this.updates)
this.$generator.text(this.info.generator);
if ('isStarted' in this.updates) {
this.$status.text(this.info.isStarted ? "In Progress" : "Signups");
}
// Update the toolbox
if ('isStarted' in this.updates || 'isJoined' in this.updates) {
this.$join.toggleClass('active', !this.info.isStarted && !this.info.isJoined);
this.$leave.toggleClass('active', !this.info.isStarted && this.info.isJoined);
this.$validate.toggleClass('active', this.info.isJoined && !this.info.challenging && !this.info.challenged && !(this.info.challenges && this.info.challenges.length));
this.$tools.toggleClass('active', !this.info.isStarted || this.info.isJoined);
}
// Update the bracket
if ('bracketData' in this.updates) {
var $bracket = this.generateBracket(this.info.bracketData);
this.$bracket.empty();
this.$bracket.removeClass('tournament-bracket-overflowing');
if ($bracket) {
this.$bracket.append($bracket);
this.updateLayout();
if (this.bracketPopup)
this.bracketPopup.updateBracket(this.generateBracket(this.info.bracketData));
}
}
if (this.info.isStarted && this.info.isJoined) {
// Update the challenges
if ('challenges' in this.updates) {
if (this.info.challenges.length > 0) {
this.$challengeUser.text("vs. " + this.info.challenges[0]);
this.$challengeUserMenu.toggle(this.info.challenges.length > 1);
this.$challengeUserMenu.html(this.renderChallengeUsers());
this.toggleBoxVisibility(true);
if (!this.$challenge.hasClass('active')) {
if (notify) this.room.notifyOnce("Tournament challenges available", "Room: " + this.room.title, 'tournament-challenges');
}
}
this.$challenge.toggleClass('active', this.info.challenges.length > 0);
}
if ('challengeBys' in this.updates) {
this.$challengeBy.toggleClass('active', this.info.challengeBys.length > 0);
if (this.info.challengeBys.length > 0)
this.$challengeBy.text((this.info.challenges.length > 0 ? "Or wait" : "Waiting") + " for " + arrayToPhrase(this.info.challengeBys, "or") + " to challenge you.");
}
if ('challenging' in this.updates) {
this.$challenging.toggleClass('active', !!this.info.challenging);
if (this.info.challenging) {
this.$challengingMessage.text("Waiting for " + this.info.challenging + "...");
}
}
if ('challenged' in this.updates) {
if (this.info.challenged) {
this.$challengedMessage.text("vs. " + this.info.challenged);
this.toggleBoxVisibility(true);
if (!this.$challenged.hasClass('active')) {
if (notify) this.room.notifyOnce("Tournament challenge from " + this.info.challenged, "Room: " + this.room.title, 'tournament-challenged');
}
}
this.$challenged.toggleClass('active', !!this.info.challenged);
}
this.$noMatches.toggleClass('active',
this.info.challenges.length === 0 && this.info.challengeBys.length === 0 && !this.info.challenging && !this.info.challenged);
}
this.updates = {};
break;
case 'battlestart':
var roomid = toRoomid(data[2]).toLowerCase();
this.room.$chat.append('
');
break;
case 'battleend':
var result = "drawn";
if (data[2] === 'win')
result = "won";
else if (data[2] === 'loss')
result = "lost";
var message = BattleLog.escapeHTML(data[0]) + " has " + result + " the match " + BattleLog.escapeHTML(data[3].split(',').join(' - ')) + " against " + BattleLog.escapeHTML(data[1]) +
(data[4] === 'fail' ? " but the tournament does not support drawing, so it did not count" : "") + ".";
var $battleMessage = data[5] ? this.room.$chat.find('.tournament-' + toRoomid(data[5]).toLowerCase()) : '';
if ($battleMessage && $battleMessage.length) {
$battleMessage.removeClass('tournament-message-battlestart').addClass('tournament-message-battleend').find('a').html(message);
} else {
this.room.$chat.append('
' + message + '
');
}
break;
case 'end':
var endData = JSON.parse(data[0]);
var $bracket = this.generateBracket(endData.bracketData);
if ($bracket) {
var $bracketMessage = $('').append($bracket);
this.room.$chat.append($bracketMessage);
if ($bracketMessage[0].offsetHeight < $bracketMessage[0].scrollHeight ||
$bracketMessage[0].offsetWidth < $bracketMessage[0].scrollWidth) {
$bracketMessage.addClass('tournament-message-end-bracket-overflowing');
makeDraggable($bracket, this.showBracketPopup.bind(this, endData.bracketData, true));
}
}
var type = endData.generator;
this.room.$chat.append("
Congratulations to " + BattleLog.escapeHTML(arrayToPhrase(endData.results[0])) + " for winning the " + BattleLog.escapeFormat(endData.format) + " " + BattleLog.escapeHTML(type) + " Tournament!
");
if (endData.results[1])
this.room.$chat.append("