Rename .players

.players -> .playerTable, .playerList -> .players
This commit is contained in:
Guangcong Luo 2019-05-12 12:54:13 +09:30
parent 0782a9ffcb
commit 93925a6308
18 changed files with 419 additions and 419 deletions

View File

@ -3609,7 +3609,7 @@ const commands = {
if (cmd.charAt(cmd.length - 1) === ',') cmd = cmd.slice(0, -1);
let targets = target.split(',');
function getPlayer(input) {
let player = room.battle.players[toId(input)];
let player = room.battle.playerTable[toId(input)];
if (player) return player.slot;
if (input.includes('1')) return 'p1';
if (input.includes('2')) return 'p2';
@ -3954,7 +3954,7 @@ const commands = {
return this.sendReply(`The game timer is ON (requested by ${[...timer.timerRequesters].join(', ')})`);
}
const force = user.can('timer', null, room);
if (!force && !room.game.players[user]) {
if (!force && !room.game.playerTable[user]) {
return this.errorReply(`Access denied.`);
}
if (this.meansNo(target) || target === 'stop') {

View File

@ -110,7 +110,7 @@ class HelpTicket extends Rooms.RoomGame {
* @param {User} user
*/
onLeave(user) {
if (user.userid in this.players) {
if (user.userid in this.playerTable) {
this.removePlayer(user);
return;
}
@ -158,7 +158,7 @@ class HelpTicket extends Rooms.RoomGame {
* @param {User} user
*/
forfeit(user) {
if (!(user.userid in this.players)) return;
if (!(user.userid in this.playerTable)) return;
this.removePlayer(user);
if (!this.ticket.open) return;
this.modnote(user, `${user.name} is no longer interested in this ticket.`);
@ -230,7 +230,7 @@ class HelpTicket extends Rooms.RoomGame {
this.modnote(staff, `${staff.name} closed this ticket.`);
notifyStaff(this.ticket.escalated);
this.room.pokeExpireTimer();
for (const ticketGameUser of Object.values(this.players)) {
for (const ticketGameUser of Object.values(this.playerTable)) {
this.removePlayer(ticketGameUser);
const user = Users(ticketGameUser.userid);
if (user) user.updateSearch();
@ -901,7 +901,7 @@ let commands = {
const ticketGame = /** @type {HelpTicket} */ (helpRoom.game);
ticketGame.modnote(user, `${user.name} opened a new ticket. Issue: ${ticket.type}`);
this.parse(`/join help-${user.userid}`);
if (!(user.userid in ticketGame.players)) {
if (!(user.userid in ticketGame.playerTable)) {
// User was already in the room, manually add them to the "game" so they get a popup if they try to leave
ticketGame.addPlayer(user);
}

View File

@ -188,7 +188,7 @@ const commands = {
let gameRooms = [];
for (const room of Rooms.rooms.values()) {
if (!room.game) continue;
if ((targetUser.userid in room.game.players && !targetUser.inRooms.has(room.id)) ||
if ((targetUser.userid in room.game.playerTable && !targetUser.inRooms.has(room.id)) ||
room.auth[targetUser.userid] === Users.PLAYER_SYMBOL) {
if (room.isPrivate && !canViewAlts) {
continue;

View File

@ -87,16 +87,16 @@ class Jeopardy extends Rooms.RoomGame {
}
this.roundstarted = true;
if (this.round === 1) {
for (let userID in this.players) {
let player = this.players[userID];
for (let userID in this.playerTable) {
let player = this.playerTable[userID];
this.points.set(player, 0);
}
}
this.state = 'selecting';
let lowest = [];
let minpoints;
for (let userID in this.players) {
let points = this.players[userID].points;
for (let userID in this.playerTable) {
let points = this.playerTable[userID].points;
if (!minpoints) {
lowest.push(userID);
minpoints = points;
@ -107,7 +107,7 @@ class Jeopardy extends Rooms.RoomGame {
lowest.push(userID);
}
}
this.curPlayer = this.players[lowest[Math.floor(lowest.length * Math.random())]];
this.curPlayer = this.playerTable[lowest[Math.floor(lowest.length * Math.random())]];
this.prevPlayer = this.curPlayer;
this.update();
this.nextPlayer();
@ -134,8 +134,8 @@ class Jeopardy extends Rooms.RoomGame {
if (this.question && !this.finals) {
buffer += `<table align="left"><tr><td bgcolor="${this.canBuzz ? "00FF00" : "0000FF"}" height="30px" width="30px"></td></tr></table>`;
}
for (let userID in this.players) {
let player = this.players[userID];
for (let userID in this.playerTable) {
let player = this.playerTable[userID];
buffer += `<center>${this.curPlayer && this.curPlayer.name === player.name ? "<b>" : ""}<font size=4>${Chat.escapeHTML(player.name)}(${(player.points || 0)})${this.curPlayer && this.curPlayer.name === player.name ? "</b>" : ""}</center><br />`;
}
buffer += "</body></html></div>";
@ -165,7 +165,7 @@ class Jeopardy extends Rooms.RoomGame {
select(target, user) {
if (this.state !== 'selecting') return "The game of Jeopardy is not in the selection phase.";
let player = this.players[user.userid];
let player = this.playerTable[user.userid];
if (!player) return "You are not in the game of Jeopardy.";
if (!this.curPlayer || this.curPlayer.userid !== user.userid) return "It is not your turn to select.";
let params = target.split(",");
@ -189,14 +189,14 @@ class Jeopardy extends Rooms.RoomGame {
}
clearwagers() {
for (let userID in this.players) {
this.players[userID].wager = null;
for (let userID in this.playerTable) {
this.playerTable[userID].wager = null;
}
}
clearbuzzes() {
for (let userID in this.players) {
this.players[userID].buzzed = false;
for (let userID in this.playerTable) {
this.playerTable[userID].buzzed = false;
}
}
@ -220,8 +220,8 @@ class Jeopardy extends Rooms.RoomGame {
}
allowAllBuzzes() {
for (let userID in this.players) {
this.players[userID].buzzedEarly = false;
for (let userID in this.playerTable) {
this.playerTable[userID].buzzedEarly = false;
}
}
@ -232,7 +232,7 @@ class Jeopardy extends Rooms.RoomGame {
buzz(user) {
if (this.state !== 'buzzing') return "You cannot buzz in at this time.";
let player = this.players[user.userid];
let player = this.playerTable[user.userid];
if (!player) return "You are not in the game of Jeopardy.";
if (player.buzzed) return "You have already buzzed in to the current question.";
if (!this.canBuzz) {
@ -269,7 +269,7 @@ class Jeopardy extends Rooms.RoomGame {
wager(amount, user) {
if (this.state !== "wagering" && (!this.finals || this.curPlayer.id !== user.userid)) return "You cannot wager at this time.";
let player = this.players[user.userid];
let player = this.playerTable[user.userid];
if (!player) return "You are not in the game of Jeopardy.";
amount = toId(amount);
let wager = (amount === 'all' ? player.points : parseInt(amount));
@ -282,8 +282,8 @@ class Jeopardy extends Rooms.RoomGame {
if (!this.finals) {
this.dailyDouble();
} else {
for (let userID in this.players) {
let player = this.players[userID];
for (let userID in this.playerTable) {
let player = this.playerTable[userID];
if (!player.wager) return;
}
clearTimeout(this.timeout);
@ -291,8 +291,8 @@ class Jeopardy extends Rooms.RoomGame {
}
}
finalWagers() {
for (let userID in this.players) {
let player = this.players[userID];
for (let userID in this.playerTable) {
let player = this.playerTable[userID];
if (!player.wager) player.wager = 0;
}
this.question = this.finalQuestion;
@ -302,7 +302,7 @@ class Jeopardy extends Rooms.RoomGame {
}
doFinals() {
this.order = Object.keys(this.players);
this.order = Object.keys(this.playerTable);
this.doFinalPlayer();
}
@ -311,8 +311,8 @@ class Jeopardy extends Rooms.RoomGame {
this.revealAnswer();
let highest = [];
let maxpoints;
for (let userID in this.players) {
let player = this.players[userID];
for (let userID in this.playerTable) {
let player = this.playerTable[userID];
let points = player.points;
if (!maxpoints) {
highest.push(player.name);
@ -328,7 +328,7 @@ class Jeopardy extends Rooms.RoomGame {
this.destroy();
return;
} else {
this.curPlayer = this.players[this.order.shift()];
this.curPlayer = this.playerTable[this.order.shift()];
let answer = this.curPlayer.finalanswer;
if (answer) {
this.room.add(`${this.curPlayer.name} has answered ${Chat.escapeHTML(answer)}!`);
@ -346,7 +346,7 @@ class Jeopardy extends Rooms.RoomGame {
answer(target, user) {
if (this.state !== 'answering') return "You cannot answer the question at this time.";
let player = this.players[user.userid];
let player = this.playerTable[user.userid];
if (!player) return "You are not in the game of Jeopardy.";
if (this.finals) {
if (player.finalanswer) return "You have already answered the final jeopardy";
@ -408,8 +408,8 @@ class Jeopardy extends Rooms.RoomGame {
}
everyBuzzed() {
for (let userID in this.players) {
if (!this.players[userID].buzzed) return false;
for (let userID in this.playerTable) {
if (!this.playerTable[userID].buzzed) return false;
}
return true;
}

View File

@ -206,7 +206,7 @@ class MafiaTracker extends Rooms.RoomGame {
this.cohosts = [];
/** @type {{[userid: string]: MafiaPlayer}} */
this.players = Object.create(null);
this.playerTable = Object.create(null);
/** @type {{[userid: string]: MafiaPlayer}} */
this.dead = Object.create(null);
/** @type {string[]} */
@ -272,8 +272,8 @@ class MafiaTracker extends Rooms.RoomGame {
if (canJoin) return user.sendTo(this.room, `|error|${canJoin}`);
if (!this.addPlayer(user)) return user.sendTo(this.room, `|error|You have already joined the game of ${this.title}.`);
if (this.subs.includes(user.userid)) this.subs.splice(this.subs.indexOf(user.userid), 1);
this.players[user.userid].updateHtmlRoom();
this.sendRoom(`${this.players[user.userid].name} has joined the game.`);
this.playerTable[user.userid].updateHtmlRoom();
this.sendRoom(`${this.playerTable[user.userid].name} has joined the game.`);
}
/**
@ -281,10 +281,10 @@ class MafiaTracker extends Rooms.RoomGame {
* @return {void}
*/
leave(user) {
if (!(user.userid in this.players)) return user.sendTo(this.room, `|error|You have not joined the game of ${this.title}.`);
if (!(user.userid in this.playerTable)) return user.sendTo(this.room, `|error|You have not joined the game of ${this.title}.`);
if (this.phase !== 'signups') return user.sendTo(this.room, `|error|The game of ${this.title} has already started.`);
this.players[user.userid].destroy();
delete this.players[user.userid];
this.playerTable[user.userid].destroy();
delete this.playerTable[user.userid];
this.playerCount--;
let subIndex = this.requestedSub.indexOf(user.userid);
if (subIndex !== -1) this.requestedSub.splice(subIndex, 1);
@ -510,8 +510,8 @@ class MafiaTracker extends Rooms.RoomGame {
}
if (this.playerCount < 2) return user.sendTo(this.room, `You need at least 2 players to start.`);
if (this.phase === 'IDEAlocked') {
for (const p in this.players) {
if (!this.players[p].role) return user.sendTo(this.room, `|error|Not all players have a role.`);
for (const p in this.playerTable) {
if (!this.playerTable[p].role) return user.sendTo(this.room, `|error|Not all players have a role.`);
}
} else {
if (!Object.keys(this.roles).length) return user.sendTo(this.room, `You need to set the roles before starting.`);
@ -535,15 +535,15 @@ class MafiaTracker extends Rooms.RoomGame {
distributeRoles() {
let roles = Dex.shuffle(this.roles.slice());
if (roles.length) {
for (let p in this.players) {
for (let p in this.playerTable) {
let role = /** @type {MafiaRole} */(roles.shift());
this.players[p].role = role;
this.playerTable[p].role = role;
let u = Users(p);
if (u && u.connected) u.send(`>${this.room.id}\n|notify|Your role is ${role.safeName}. For more details of your role, check your Role PM.`);
}
}
this.dead = {};
this.played = [this.hostid, ...this.cohosts, ...Object.keys(this.players)];
this.played = [this.hostid, ...this.cohosts, ...Object.keys(this.playerTable)];
this.sendRoom(`The roles have been distributed.`, {declare: true});
this.updatePlayers();
}
@ -556,10 +556,10 @@ class MafiaTracker extends Rooms.RoomGame {
getPartners(alignment, player) {
if (!player || !player.role || ['town', 'solo'].includes(player.role.alignment)) return "";
let partners = [];
for (let p in this.players) {
for (let p in this.playerTable) {
if (p === player.userid) continue;
const role = this.players[p].role;
if (role && role.alignment === player.role.alignment) partners.push(this.players[p].name);
const role = this.playerTable[p].role;
if (role && role.alignment === player.role.alignment) partners.push(this.playerTable[p].name);
}
return partners.join(", ");
}
@ -573,7 +573,7 @@ class MafiaTracker extends Rooms.RoomGame {
if (this.phase !== 'night' && !initial) return;
if (this.timer) this.setDeadline(0);
if (extension === null) {
this.hammerCount = Math.floor(Object.keys(this.players).length / 2) + 1;
this.hammerCount = Math.floor(Object.keys(this.playerTable).length / 2) + 1;
this.lynches = Object.create(null);
this.hasPlurality = null;
this.clearLynches();
@ -605,9 +605,9 @@ class MafiaTracker extends Rooms.RoomGame {
}
this.sendRoom(`Night ${this.dayNum}. PM the host your action, or idle.`, {declare: true});
const hasPlurality = this.getPlurality();
if (!early && hasPlurality) this.sendRoom(`Plurality is on ${this.players[hasPlurality] ? this.players[hasPlurality].name : 'No Lynch'}`);
if (!early && hasPlurality) this.sendRoom(`Plurality is on ${this.playerTable[hasPlurality] ? this.playerTable[hasPlurality].name : 'No Lynch'}`);
if (!early && !initial) this.sendRoom(`|raw|<div class="infobox">${this.lynchBox()}</div>`);
if (initial) this.hammerCount = Math.floor(Object.keys(this.players).length / 2) + 1;
if (initial) this.hammerCount = Math.floor(Object.keys(this.playerTable).length / 2) + 1;
this.updatePlayers();
}
@ -618,10 +618,10 @@ class MafiaTracker extends Rooms.RoomGame {
*/
lynch(userid, target) {
if (this.phase !== 'day') return this.sendUser(userid, `|error|You can only lynch during the day.`);
let player = this.players[userid];
let player = this.playerTable[userid];
if (!player && this.dead[userid] && this.dead[userid].restless) player = this.dead[userid];
if (!player) return;
if (!(target in this.players) && target !== 'nolynch') return this.sendUser(userid, `|error|${target} is not a valid player.`);
if (!(target in this.playerTable) && target !== 'nolynch') return this.sendUser(userid, `|error|${target} is not a valid player.`);
if (!this.enableNL && target === 'nolynch') return this.sendUser(userid, `|error|No Lynch is not allowed.`);
if (target === player.userid && !this.selfEnabled) return this.sendUser(userid, `|error|Self lynching is not allowed.`);
if (target === player.userid && (this.hammerCount - 1 > (this.lynches[target] ? this.lynches[target].count : 0)) && this.selfEnabled === 'hammer') return this.sendUser(userid, `|error|You may only lynch yourself when you placing the hammer vote.`);
@ -640,10 +640,10 @@ class MafiaTracker extends Rooms.RoomGame {
lynch.lynchers.push(userid);
}
player.lynching = target;
let name = player.lynching === 'nolynch' ? 'No Lynch' : this.players[player.lynching].name;
let name = player.lynching === 'nolynch' ? 'No Lynch' : this.playerTable[player.lynching].name;
const targetUser = Users(userid);
if (previousLynch) {
this.sendRoom(`${(targetUser ? targetUser.name : userid)} has shifted their lynch from ${previousLynch === 'nolynch' ? 'No Lynch' : this.players[previousLynch].name} to ${name}`, {timestamp: true});
this.sendRoom(`${(targetUser ? targetUser.name : userid)} has shifted their lynch from ${previousLynch === 'nolynch' ? 'No Lynch' : this.playerTable[previousLynch].name} to ${name}`, {timestamp: true});
} else {
this.sendRoom(name === 'No Lynch' ? `${(targetUser ? targetUser.name : userid)} has abstained from lynching.` : `${(targetUser ? targetUser.name : userid)} has lynched ${name}.`, {timestamp: true});
}
@ -652,7 +652,7 @@ class MafiaTracker extends Rooms.RoomGame {
// HAMMER
this.sendRoom(`Hammer! ${target === 'nolynch' ? 'Nobody' : Chat.escapeHTML(name)} was lynched!`, {declare: true});
this.sendRoom(`|raw|<div class="infobox">${this.lynchBox()}</div>`);
if (target !== 'nolynch') this.eliminate(this.players[target], 'kill');
if (target !== 'nolynch') this.eliminate(this.playerTable[target], 'kill');
this.night(true);
return;
}
@ -667,7 +667,7 @@ class MafiaTracker extends Rooms.RoomGame {
*/
unlynch(userid, force = false) {
if (this.phase !== 'day' && !force) return this.sendUser(userid, `|error|You can only lynch during the day.`);
let player = this.players[userid];
let player = this.playerTable[userid];
if (!player && this.dead[userid] && this.dead[userid].restless) player = this.dead[userid];
if (!player || !player.lynching) return this.sendUser(userid, `|error|You are not lynching anyone.`);
if (player.lastLynch + 2000 >= Date.now() && !force) return this.sendUser(userid, `|error|You must wait another ${Chat.toDurationString((player.lastLynch + 2000) - Date.now()) || '1 second'} before you can change your lynch.`);
@ -682,7 +682,7 @@ class MafiaTracker extends Rooms.RoomGame {
lynch.lynchers.splice(lynch.lynchers.indexOf(userid), 1);
}
const targetUser = Users(userid);
if (!force) this.sendRoom(player.lynching === 'nolynch' ? `${(targetUser ? targetUser.name : userid)} is no longer abstaining from lynching.` : `${(targetUser ? targetUser.name : userid)} has unlynched ${this.players[player.lynching].name}.`, {timestamp: true});
if (!force) this.sendRoom(player.lynching === 'nolynch' ? `${(targetUser ? targetUser.name : userid)} is no longer abstaining from lynching.` : `${(targetUser ? targetUser.name : userid)} has unlynched ${this.playerTable[player.lynching].name}.`, {timestamp: true});
player.lynching = '';
player.lastLynch = Date.now();
this.hasPlurality = null;
@ -703,7 +703,7 @@ class MafiaTracker extends Rooms.RoomGame {
return this.lynches[b].count - this.lynches[a].count;
});
for (const key of list) {
buf += `${this.lynches[key].count}${plur === key ? '*' : ''} ${this.players[key] ? this.players[key].safeName : 'No Lynch'} (${this.lynches[key].lynchers.map(a => this.players[a] ? this.players[a].safeName : a).join(', ')})<br />`;
buf += `${this.lynches[key].count}${plur === key ? '*' : ''} ${this.playerTable[key] ? this.playerTable[key].safeName : 'No Lynch'} (${this.lynches[key].lynchers.map(a => this.playerTable[a] ? this.playerTable[a].safeName : a).join(', ')})<br />`;
}
return buf;
}
@ -714,7 +714,7 @@ class MafiaTracker extends Rooms.RoomGame {
* @param {number} mod
*/
applyLynchModifier(user, target, mod) {
const targetPlayer = this.players[target] || this.dead[target];
const targetPlayer = this.playerTable[target] || this.dead[target];
if (!targetPlayer) return this.sendUser(user, `|error|${target} is not in the game of mafia.`);
if (target in this.dead && !targetPlayer.restless) return this.sendUser(user, `|error|${target} is not alive or a restless spirit, and therefore cannot lynch.`);
const oldMod = this.lynchModifiers[target];
@ -744,7 +744,7 @@ class MafiaTracker extends Rooms.RoomGame {
* @param {number} mod
*/
applyHammerModifier(user, target, mod) {
if (!(target in this.players || target === 'nolynch')) return this.sendUser(user, `|error|${target} is not in the game of mafia.`);
if (!(target in this.playerTable || target === 'nolynch')) return this.sendUser(user, `|error|${target} is not in the game of mafia.`);
const oldMod = this.hammerModifiers[target];
if (mod === oldMod || ((isNaN(mod) || mod === 0) && oldMod === undefined)) {
if (isNaN(mod) || mod === 0) return this.sendUser(user, `|error|${target} already has no hammer modifier.`);
@ -769,7 +769,7 @@ class MafiaTracker extends Rooms.RoomGame {
* @param {User} user
*/
clearLynchModifiers(user) {
for (const player of [...Object.keys(this.players), ...Object.keys(this.dead)]) {
for (const player of [...Object.keys(this.playerTable), ...Object.keys(this.dead)]) {
if (this.lynchModifiers[player]) this.applyLynchModifier(user, player, 1);
}
}
@ -777,7 +777,7 @@ class MafiaTracker extends Rooms.RoomGame {
* @param {User} user
*/
clearHammerModifiers(user) {
for (const player of ['nolynch', ...Object.keys(this.players)]) {
for (const player of ['nolynch', ...Object.keys(this.playerTable)]) {
if (this.hammerModifiers[player]) this.applyHammerModifier(user, player, 0);
}
}
@ -800,7 +800,7 @@ class MafiaTracker extends Rooms.RoomGame {
* @return {void}
*/
resetHammer() {
this.setHammer(Math.floor(Object.keys(this.players).length / 2) + 1);
this.setHammer(Math.floor(Object.keys(this.playerTable).length / 2) + 1);
}
/**
@ -872,14 +872,14 @@ class MafiaTracker extends Rooms.RoomGame {
* @return {void}
*/
eliminate(player, ability = 'kill') {
if (!(player.userid in this.players)) return;
if (!(player.userid in this.playerTable)) return;
if (!this.started) {
// Game has not started, simply kick the player
this.sendRoom(`${player.safeName} was kicked from the game!`, {declare: true});
if (this.hostRequestedSub.includes(player.userid)) this.hostRequestedSub.splice(this.hostRequestedSub.indexOf(player.userid), 1);
if (this.requestedSub.includes(player.userid)) this.requestedSub.splice(this.requestedSub.indexOf(player.userid), 1);
player.destroy();
delete this.players[player.userid];
delete this.playerTable[player.userid];
this.playerCount--;
player.updateHtmlRoom();
return;
@ -918,7 +918,7 @@ class MafiaTracker extends Rooms.RoomGame {
}
}
this.clearLynches(player.userid);
delete this.players[player.userid];
delete this.playerTable[player.userid];
let subIndex = this.requestedSub.indexOf(player.userid);
if (subIndex !== -1) this.requestedSub.splice(subIndex, 1);
subIndex = this.hostRequestedSub.indexOf(player.userid);
@ -938,7 +938,7 @@ class MafiaTracker extends Rooms.RoomGame {
*/
revive(user, toRevive, force = false) {
if (this.phase === 'IDEApicking') return user.sendTo(this.room, `|error|You cannot add or remove players while IDEA roles are being picked.`);
if (toRevive in this.players) {
if (toRevive in this.playerTable) {
user.sendTo(this.room, `|error|The user ${toRevive} is already a living player.`);
return;
}
@ -947,7 +947,7 @@ class MafiaTracker extends Rooms.RoomGame {
if (deadPlayer.treestump) deadPlayer.treestump = false;
if (deadPlayer.restless) deadPlayer.restless = false;
this.sendRoom(`${deadPlayer.safeName} was revived!`, {declare: true});
this.players[deadPlayer.userid] = deadPlayer;
this.playerTable[deadPlayer.userid] = deadPlayer;
const targetRole = deadPlayer.role;
if (targetRole) {
this.roles.push(targetRole);
@ -991,7 +991,7 @@ class MafiaTracker extends Rooms.RoomGame {
}
if (this.subs.includes(targetUser.userid)) this.subs.splice(this.subs.indexOf(targetUser.userid), 1);
this.played.push(targetUser.userid);
this.players[targetUser.userid] = player;
this.playerTable[targetUser.userid] = player;
this.sendRoom(`${Chat.escapeHTML(targetUser.name)} has been added to the game by ${Chat.escapeHTML(user.name)}!`, {declare: true});
}
this.playerCount++;
@ -1050,7 +1050,7 @@ class MafiaTracker extends Rooms.RoomGame {
* @return {void}
*/
sub(player, replacement) {
let oldPlayer = this.players[player];
let oldPlayer = this.playerTable[player];
if (!oldPlayer) return; // should never happen
const newUser = Users(replacement);
@ -1066,15 +1066,15 @@ class MafiaTracker extends Rooms.RoomGame {
newPlayer.lynching = oldPlayer.lynching;
oldPlayer.lynching = '';
}
this.players[newPlayer.userid] = newPlayer;
this.players[oldPlayer.userid].destroy();
delete this.players[oldPlayer.userid];
this.playerTable[newPlayer.userid] = newPlayer;
this.playerTable[oldPlayer.userid].destroy();
delete this.playerTable[oldPlayer.userid];
// Transfer lynches on the old player to the new one
if (this.lynches[oldPlayer.userid]) {
this.lynches[newPlayer.userid] = this.lynches[oldPlayer.userid];
delete this.lynches[oldPlayer.userid];
for (let p in this.players) {
if (this.players[p].lynching === oldPlayer.userid) this.players[p].lynching = newPlayer.userid;
for (let p in this.playerTable) {
if (this.playerTable[p].lynching === oldPlayer.userid) this.playerTable[p].lynching = newPlayer.userid;
}
for (let p in this.dead) {
if (this.dead[p].restless && this.dead[p].lynching === oldPlayer.userid) this.dead[p].lynching = newPlayer.userid;
@ -1188,8 +1188,8 @@ class MafiaTracker extends Rooms.RoomGame {
}
Dex.shuffle(roles);
this.IDEA.waitingPick = [];
for (const p in this.players) {
const player = this.players[p];
for (const p in this.playerTable) {
const player = this.playerTable[p];
player.role = null;
player.IDEA = {
choices: roles.splice(0, this.IDEA.data.choices),
@ -1224,7 +1224,7 @@ class MafiaTracker extends Rooms.RoomGame {
let buf = '';
if (this.phase !== 'IDEApicking') return 'The game is not in the IDEA picking phase.';
if (!this.IDEA || !this.IDEA.data) return this.sendRoom(`Trying to pick an IDEA role with no module running, target: ${JSON.stringify(selection)}. Please report this to a mod.`);
const player = this.players[user.userid];
const player = this.playerTable[user.userid];
if (!player.IDEA) return this.sendRoom(`Trying to pick an IDEA role with no player IDEA object, user: ${user.userid}. Please report this to a mod.`);
selection = selection.map(toId);
if (selection.length === 1 && this.IDEA.data.picks.length === 1) selection = [this.IDEA.data.picks[0], selection[0]];
@ -1267,8 +1267,8 @@ class MafiaTracker extends Rooms.RoomGame {
ideaFinalizePicks() {
if (!this.IDEA || !this.IDEA.data) return this.sendRoom(`Tried to finalize IDEA picks with no IDEA module running, please report this to a mod.`);
let randed = [];
for (const p in this.players) {
const player = this.players[p];
for (const p in this.playerTable) {
const player = this.playerTable[p];
if (!player.IDEA) return this.sendRoom(`Trying to pick an IDEA role with no player IDEA object, user: ${player.userid}. Please report this to a mod.`);
let randPicked = false;
let role = [];
@ -1310,10 +1310,10 @@ class MafiaTracker extends Rooms.RoomGame {
}
}
this.IDEA.discardsHtml = `<b>Discards:</b><br />`;
for (const p of Object.keys(this.players).sort()) {
const IDEA = this.players[p].IDEA;
for (const p of Object.keys(this.playerTable).sort()) {
const IDEA = this.playerTable[p].IDEA;
if (!IDEA) return this.sendRoom(`No IDEA data for player ${p} when finalising IDEAs. Please report this to a mod.`);
this.IDEA.discardsHtml += `<b>${this.players[p].safeName}:</b> ${IDEA.choices.join(', ')}<br />`;
this.IDEA.discardsHtml += `<b>${this.playerTable[p].safeName}:</b> ${IDEA.choices.join(', ')}<br />`;
}
this.phase = 'IDEAlocked';
@ -1327,15 +1327,15 @@ class MafiaTracker extends Rooms.RoomGame {
* @return {void}
*/
sendPlayerList() {
this.room.add(`|c:|${(Math.floor(Date.now() / 1000))}|~|**Players (${this.playerCount})**: ${Object.keys(this.players).map(p => this.players[p].name).join(', ')}`).update();
this.room.add(`|c:|${(Math.floor(Date.now() / 1000))}|~|**Players (${this.playerCount})**: ${Object.keys(this.playerTable).map(p => this.playerTable[p].name).join(', ')}`).update();
}
/**
* @return {void}
*/
updatePlayers() {
for (const p in this.players) {
this.players[p].updateHtmlRoom();
for (const p in this.playerTable) {
this.playerTable[p].updateHtmlRoom();
}
for (const p in this.dead) {
if (this.dead[p].restless || this.dead[p].treestump) this.dead[p].updateHtmlRoom();
@ -1401,12 +1401,12 @@ class MafiaTracker extends Rooms.RoomGame {
if (!user || !user.connected) return `User not found.`;
const targetString = self ? `You are` : `${user.userid} is`;
if (!this.room.users[user.userid]) return `${targetString} not in the room.`;
if (this.players[user.userid]) return `${targetString} already in the game.`;
if (this.playerTable[user.userid]) return `${targetString} already in the game.`;
if (this.hostid === user.userid) return `${targetString} the host.`;
if (this.cohosts.includes(user.userid)) return `${targetString} a cohost.`;
if (!force) {
for (const alt of user.getAltUsers(true)) {
if (this.players[alt.userid] || this.played.includes(alt.userid)) return `${self ? `You already have` : `${user.userid} already has`} an alt in the game.`;
if (this.playerTable[alt.userid] || this.played.includes(alt.userid)) return `${self ? `You already have` : `${user.userid} already has`} an alt in the game.`;
if (this.hostid === alt.userid || this.cohosts.includes(alt.userid)) return `${self ? `You have` : `${user.userid} has`} an alt as a game host.`;
}
}
@ -1437,7 +1437,7 @@ class MafiaTracker extends Rooms.RoomGame {
}
this.selfEnabled = setting;
if (!setting) {
for (const player of Object.values(this.players)) {
for (const player of Object.values(this.playerTable)) {
if (player.lynching === player.userid) this.unlynch(player.userid, true);
}
}
@ -1459,7 +1459,7 @@ class MafiaTracker extends Rooms.RoomGame {
*/
clearLynches(target = '') {
if (target) delete this.lynches[target];
for (const player of Object.values(this.players)) {
for (const player of Object.values(this.playerTable)) {
if (!target || (player.lynching === target)) player.lynching = '';
}
for (const player of Object.values(this.dead)) {
@ -1483,7 +1483,7 @@ class MafiaTracker extends Rooms.RoomGame {
}
if (user.isStaff || (this.room.auth && this.room.auth[user.userid] && this.room.auth[user.userid] !== '+') || this.hostid === user.userid || this.cohosts.includes(user.userid) || !this.started) return false;
if (!this.players[user.userid] && (!this.dead[user.userid] || !this.dead[user.userid].treestump)) return `You cannot talk while a game of ${this.title} is going on.`;
if (!this.playerTable[user.userid] && (!this.dead[user.userid] || !this.dead[user.userid].treestump)) return `You cannot talk while a game of ${this.title} is going on.`;
if (this.phase === 'night') return `You cannot talk at night.`;
return false;
}
@ -1501,8 +1501,8 @@ class MafiaTracker extends Rooms.RoomGame {
* @return {void}
*/
onJoin(user) {
if (user.userid in this.players) {
return this.players[user.userid].updateHtmlRoom();
if (user.userid in this.playerTable) {
return this.playerTable[user.userid].updateHtmlRoom();
}
if (user.userid === this.hostid) return this.updateHost();
}
@ -1522,7 +1522,7 @@ class MafiaTracker extends Rooms.RoomGame {
removeBannedUser(user) {
// Player was banned, attempt to sub now
// If we can't sub now, make subbing them out the top priority
if (!(user.userid in this.players)) return;
if (!(user.userid in this.playerTable)) return;
this.requestedSub.unshift(user.userid);
this.nextSub();
}
@ -1533,7 +1533,7 @@ class MafiaTracker extends Rooms.RoomGame {
*/
forfeit(user) {
// Add the player to the sub list.
if (!(user.userid in this.players)) return;
if (!(user.userid in this.playerTable)) return;
this.requestedSub.push(user.userid);
this.nextSub();
}
@ -1548,7 +1548,7 @@ class MafiaTracker extends Rooms.RoomGame {
if (this.room.id === 'mafia' && this.started) {
// Intead of using this.played, which shows players who have subbed out as well
// We check who played through to the end when recording playlogs
const played = Object.keys(this.players).concat(Object.keys(this.dead));
const played = Object.keys(this.playerTable).concat(Object.keys(this.dead));
const month = new Date().toLocaleString("en-us", {month: "numeric", year: "numeric"});
if (!logs.plays[month]) logs.plays[month] = {};
for (const player of played) {
@ -1575,8 +1575,8 @@ class MafiaTracker extends Rooms.RoomGame {
if (this.IDEA.timer) clearTimeout(this.IDEA.timer);
this.room.game = null;
this.room = /** @type {any} */ (null);
for (let i in this.players) {
this.players[i].destroy();
for (let i in this.playerTable) {
this.playerTable[i].destroy();
}
for (let i in this.dead) {
this.dead[i].destroy();
@ -1594,16 +1594,16 @@ const pages = {
const room = /** @type {ChatRoom} */ (Rooms(roomid));
if (!room || !room.users[user.userid] || !room.game || room.game.gameid !== 'mafia' || room.game.ended) return this.close();
const game = /** @type {MafiaTracker} */ (room.game);
const isPlayer = user.userid in game.players;
const isPlayer = user.userid in game.playerTable;
const isHost = user.userid === game.hostid || game.cohosts.includes(user.userid);
this.title = game.title;
let buf = `<div class="pad broadcast-blue">`;
buf += `<button class="button" name="send" value="/join view-mafia-${room.id}" style="float:left"><i class="fa fa-refresh"></i> Refresh</button>`;
buf += `<br/><br/><h1 style="text-align:center;">${game.title}</h1><h3>Host: ${game.host}</h3>`;
buf += `<p style="font-weight:bold;">Players (${game.playerCount}): ${Object.keys(game.players).sort().map(p => game.players[p].safeName).join(', ')}</p><hr/>`;
buf += `<p style="font-weight:bold;">Players (${game.playerCount}): ${Object.keys(game.playerTable).sort().map(p => game.playerTable[p].safeName).join(', ')}</p><hr/>`;
if (isPlayer && game.phase === 'IDEApicking') {
buf += `<p><b>IDEA information:</b><br />`;
const IDEA = game.players[user.userid].IDEA;
const IDEA = game.playerTable[user.userid].IDEA;
if (!IDEA) return game.sendRoom(`IDEA picking phase but no IDEA object for user: ${user.userid}. Please report this to a mod.`);
for (const pick of Object.keys(IDEA.picks)) {
buf += `<b>${pick}:</b> `;
@ -1652,10 +1652,10 @@ const pages = {
}
}
if (isPlayer) {
const role = game.players[user.userid].role;
const role = game.playerTable[user.userid].role;
if (role) {
buf += `<h3>${game.players[user.userid].safeName}, you are a ${game.players[user.userid].getRole()}</h3>`;
if (!['town', 'solo'].includes(role.alignment)) buf += `<p><span style="font-weight:bold">Partners</span>: ${game.getPartners(role.alignment, game.players[user.userid])}</p>`;
buf += `<h3>${game.playerTable[user.userid].safeName}, you are a ${game.playerTable[user.userid].getRole()}</h3>`;
if (!['town', 'solo'].includes(role.alignment)) buf += `<p><span style="font-weight:bold">Partners</span>: ${game.getPartners(role.alignment, game.playerTable[user.userid])}</p>`;
buf += `<p><details><summary class="button" style="text-align:left; display:inline-block">Role Details</summary>`;
buf += `<table><tr><td style="text-align:center;">${role.image || `<img width="75" height="75" src="//play.pokemonshowdown.com/fx/mafia-villager.png"/>`}</td><td style="text-align:left;width:100%"><ul>${role.memo.map(m => `<li>${m}</li>`).join('')}</ul></td></tr></table>`;
buf += `</details></p>`;
@ -1664,18 +1664,18 @@ const pages = {
if (game.phase === "day") {
buf += `<h3>Lynches (Hammer: ${game.hammerCount}) <button class="button" name="send" value="/join view-mafia-${room.id}"><i class="fa fa-refresh"></i> Refresh</button></h3>`;
let plur = game.getPlurality();
for (const key of Object.keys(game.players).concat((game.enableNL ? ['nolynch'] : []))) {
for (const key of Object.keys(game.playerTable).concat((game.enableNL ? ['nolynch'] : []))) {
if (game.lynches[key]) {
buf += `<p style="font-weight:bold">${game.lynches[key].count}${plur === key ? '*' : ''} ${game.players[key] ? game.players[key].safeName : 'No Lynch'} (${game.lynches[key].lynchers.map(a => game.players[a] ? game.players[a].safeName : a).join(', ')}) `;
buf += `<p style="font-weight:bold">${game.lynches[key].count}${plur === key ? '*' : ''} ${game.playerTable[key] ? game.playerTable[key].safeName : 'No Lynch'} (${game.lynches[key].lynchers.map(a => game.playerTable[a] ? game.playerTable[a].safeName : a).join(', ')}) `;
} else {
buf += `<p style="font-weight:bold">0 ${game.players[key] ? game.players[key].safeName : 'No Lynch'} `;
buf += `<p style="font-weight:bold">0 ${game.playerTable[key] ? game.playerTable[key].safeName : 'No Lynch'} `;
}
const isSpirit = (game.dead[user.userid] && game.dead[user.userid].restless);
if (isPlayer || isSpirit) {
if (isPlayer && game.players[user.userid].lynching === key || isSpirit && game.dead[user.userid].lynching === key) {
buf += `<button class="button" name="send" value="/mafia unlynch ${room.id}">Unlynch ${game.players[key] ? game.players[key].safeName : 'No Lynch'}</button>`;
if (isPlayer && game.playerTable[user.userid].lynching === key || isSpirit && game.dead[user.userid].lynching === key) {
buf += `<button class="button" name="send" value="/mafia unlynch ${room.id}">Unlynch ${game.playerTable[key] ? game.playerTable[key].safeName : 'No Lynch'}</button>`;
} else if ((game.selfEnabled && !isSpirit) || user.userid !== key) {
buf += `<button class="button" name="send" value="/mafia lynch ${room.id}, ${key}">Lynch ${game.players[key] ? game.players[key].safeName : 'No Lynch'}</button>`;
buf += `<button class="button" name="send" value="/mafia lynch ${room.id}, ${key}">Lynch ${game.playerTable[key] ? game.playerTable[key].safeName : 'No Lynch'}</button>`;
}
} else if (isHost) {
const lynch = game.lynches[key];
@ -1711,8 +1711,8 @@ const pages = {
buf += `<p>To set a deadline, use <strong>/mafia deadline [minutes]</strong>.<br />To clear the deadline use <strong>/mafia deadline off</strong>.</p><hr/></details></p>`;
buf += `<p><details><summary class="button" style="text-align:left; display:inline-block">Player Options</summary>`;
buf += `<h3>Player Options</h3>`;
for (let p in game.players) {
let player = game.players[p];
for (let p in game.playerTable) {
let player = game.playerTable[p];
buf += `<p><details><summary class="button" style="text-align:left; display:inline-block"><span style="font-weight:bold;">`;
buf += `${player.safeName} (${player.role ? player.getRole(true) : ''})${game.lynchModifiers[p] !== undefined ? `(lynches worth ${game.getLynchValue(p)})` : ''}</summary>`;
buf += `<button class="button" name="send" value="/mafia kill ${room.id}, ${player.userid}">Kill</button> `;
@ -2108,7 +2108,7 @@ const commands = {
}
if (!targetRoom.game || targetRoom.game.gameid !== 'mafia') return user.sendTo(targetRoom, `|error|There is no game of mafia running in this room.`);
const game = /** @type {MafiaTracker} */ (targetRoom.game);
if (!(user.userid in game.players)) return user.sendTo(targetRoom, '|error|You are not a player in the game.');
if (!(user.userid in game.playerTable)) return user.sendTo(targetRoom, '|error|You are not a player in the game.');
if (game.phase !== 'IDEApicking') return user.sendTo(targetRoom, `|error|The game is not in the IDEA picking phase.`);
game.ideaPick(user, args);
},
@ -2227,7 +2227,7 @@ const commands = {
if (!targetRoom.game || targetRoom.game.gameid !== 'mafia') return user.sendTo(targetRoom, `|error|There is no game of mafia running in this room.`);
const game = /** @type {MafiaTracker} */ (targetRoom.game);
if (!this.canTalk(null, targetRoom)) return;
if (!(user.userid in game.players) && (!(user.userid in game.dead) || !game.dead[user.userid].restless)) return user.sendTo(targetRoom, `|error|You are not in the game of ${game.title}.`);
if (!(user.userid in game.playerTable) && (!(user.userid in game.dead) || !game.dead[user.userid].restless)) return user.sendTo(targetRoom, `|error|You are not in the game of ${game.title}.`);
game.lynch(user.userid, toId(args.join('')));
},
lynchhelp: [`/mafia lynch [player|nolynch] - Vote to lynch the specified player or to not lynch anyone.`],
@ -2245,7 +2245,7 @@ const commands = {
if (!targetRoom.game || targetRoom.game.gameid !== 'mafia') return user.sendTo(targetRoom, `|error|There is no game of mafia running in this room.`);
const game = /** @type {MafiaTracker} */ (targetRoom.game);
if (!this.canTalk(null, targetRoom)) return;
if (!(user.userid in game.players) && (!(user.userid in game.dead) || !game.dead[user.userid].restless)) return user.sendTo(targetRoom, `|error|You are not in the game of ${targetRoom.game.title}.`);
if (!(user.userid in game.playerTable) && (!(user.userid in game.dead) || !game.dead[user.userid].restless)) return user.sendTo(targetRoom, `|error|You are not in the game of ${targetRoom.game.title}.`);
game.unlynch(user.userid);
},
unlynchhelp: [`/mafia unlynch - Withdraw your lynch vote. Fails if you're not voting to lynch anyone`],
@ -2300,7 +2300,7 @@ const commands = {
if (!targetRoom.game || targetRoom.game.gameid !== 'mafia') return user.sendTo(targetRoom, `|error|There is no game of mafia running in this room.`);
const game = /** @type {MafiaTracker} */ (targetRoom.game);
if (game.hostid !== user.userid && !game.cohosts.includes(user.userid) && !this.can('mute', null, room)) return;
const player = game.players[toId(args.join(''))];
const player = game.playerTable[toId(args.join(''))];
if (!player) return user.sendTo(targetRoom, `|error|"${args.join(',')}" is not a living player.`);
if (game.phase === 'IDEApicking') return this.errorReply(`You cannot add or remove players while IDEA roles are being picked.`); // needs to be here since eliminate doesn't pass the user
game.eliminate(player, cmd);
@ -2524,7 +2524,7 @@ const commands = {
if (this.broadcasting) {
game.sendPlayerList();
} else {
this.sendReplyBox(`Players (${game.playerCount}): ${Object.keys(game.players).map(p => game.players[p].safeName).join(', ')}`);
this.sendReplyBox(`Players (${game.playerCount}): ${Object.keys(game.playerTable).map(p => game.playerTable[p].safeName).join(', ')}`);
}
},
@ -2555,7 +2555,7 @@ const commands = {
const game = /** @type {MafiaTracker} */ (room.game);
if (game.hostid !== user.userid && !game.cohosts.includes(user.userid)) return this.errorReply(`Only the host can view roles.`);
if (!game.started) return this.errorReply(`The game has not started.`);
const players = [...Object.values(game.players), ...Object.values(game.dead)];
const players = [...Object.values(game.playerTable), ...Object.values(game.dead)];
this.sendReplyBox(players.map(p => `${p.safeName}: ${p.role ? (p.role.alignment === 'solo' ? 'Solo ' : '') + p.role.safeName : 'No role'}`).join('<br/>'));
},
@ -2584,12 +2584,12 @@ const commands = {
let action = toId(args.shift());
switch (action) {
case 'in':
if (user.userid in game.players) {
if (user.userid in game.playerTable) {
// Check if they have requested to be subbed out.
if (!game.requestedSub.includes(user.userid)) return user.sendTo(targetRoom, `|error|You have not requested to be subbed out.`);
game.requestedSub.splice(game.requestedSub.indexOf(user.userid), 1);
user.sendTo(room, `|error|You have cancelled your request to sub out.`);
game.players[user.userid].updateHtmlRoom();
game.playerTable[user.userid].updateHtmlRoom();
} else {
if (!this.canTalk(null, targetRoom)) return;
if (game.subs.includes(user.userid)) return user.sendTo(targetRoom, `|error|You are already on the sub list.`);
@ -2603,10 +2603,10 @@ const commands = {
}
break;
case 'out':
if (user.userid in game.players) {
if (user.userid in game.playerTable) {
if (game.requestedSub.includes(user.userid)) return user.sendTo(targetRoom, `|error|You have already requested to be subbed out.`);
game.requestedSub.push(user.userid);
game.players[user.userid].updateHtmlRoom();
game.playerTable[user.userid].updateHtmlRoom();
game.nextSub();
} else {
if (game.hostid === user.userid || game.cohosts.includes(user.userid)) return user.sendTo(targetRoom, `|error|The host cannot sub out of the game.`);
@ -2619,7 +2619,7 @@ const commands = {
case 'next':
if (game.hostid !== user.userid && !game.cohosts.includes(user.userid) && !this.can('mute', null, room)) return;
let toSub = args.shift();
if (!(toId(toSub) in game.players)) return user.sendTo(targetRoom, `|error|${toSub} is not in the game.`);
if (!(toId(toSub) in game.playerTable)) return user.sendTo(targetRoom, `|error|${toSub} is not in the game.`);
if (!game.subs.length) {
if (game.hostRequestedSub.indexOf(toId(toSub)) !== -1) return user.sendTo(targetRoom, `|error|${toSub} is already on the list to be subbed out.`);
user.sendTo(targetRoom, `|error|There are no subs to replace ${toSub}, they will be subbed if a sub is available before they speak next.`);
@ -2655,7 +2655,7 @@ const commands = {
if (game.hostid !== user.userid && !game.cohosts.includes(user.userid) && !this.can('mute', null, room)) return;
const toSubOut = action;
const toSubIn = toId(args.shift());
if (!(toSubOut in game.players)) return user.sendTo(targetRoom, `|error|${toSubOut} is not in the game.`);
if (!(toSubOut in game.playerTable)) return user.sendTo(targetRoom, `|error|${toSubOut} is not in the game.`);
const targetUser = Users(toSubIn);
if (!targetUser) return user.sendTo(targetRoom, `|error|The user "${toSubIn}" was not found.`);
@ -2719,7 +2719,7 @@ const commands = {
if (!room.users[targetUser.userid]) return this.errorReply(`${targetUser.name} is not in this room, and cannot be hosted.`);
if (game.hostid === targetUser.userid) return this.errorReply(`${targetUser.name} is already the host.`);
if (game.cohosts.includes(targetUser.userid)) return this.errorReply(`${targetUser.name} is already a cohost.`);
if (targetUser.userid in game.players) return this.errorReply(`The host cannot be ingame.`);
if (targetUser.userid in game.playerTable) return this.errorReply(`The host cannot be ingame.`);
if (targetUser.userid in game.dead) {
if (!cmd.includes('force')) return this.errorReply(`${targetUser.name} could potentially be revived. To continue anyway, use /mafia force${cmd} ${target}.`);
if (game.dead[targetUser.userid].lynching) game.unlynch(targetUser.userid);
@ -2801,8 +2801,8 @@ const commands = {
// Support /mafia role showing your current role if you're in a game
const game = /** @type {MafiaTracker} */ (room.game);
if (!game || game.id !== 'mafia') return this.errorReply(`There is no game of mafia running in this room. If you meant to display information about a role, use /mafia role [role name]`);
if (!(user.userid in game.players)) return this.errorReply(`You are not in the game of ${game.title}.`);
const role = game.players[user.userid].role;
if (!(user.userid in game.playerTable)) return this.errorReply(`You are not in the game of ${game.title}.`);
const role = game.playerTable[user.userid].role;
if (!role) return this.errorReply(`You do not have a role yet.`);
return this.sendReplyBox(`Your role is: ${role.safeName}`);
}
@ -2885,7 +2885,7 @@ const commands = {
for (let faction of args) {
faction = toId(faction);
let inFaction = [];
for (const user of [...Object.values(game.players), ...Object.values(game.dead)]) {
for (const user of [...Object.values(game.playerTable), ...Object.values(game.dead)]) {
if (user.role && toId(user.role.alignment) === faction) {
toGiveTo.push(user.userid);
inFaction.push(user.userid);

View File

@ -101,7 +101,7 @@ class ScavGame extends Rooms.RoomGame {
joinGame(user) {
if (!this.childGame) return user.sendTo(this.room, "There is no hunt to join yet.");
if (!this.canJoinGame(user)) return user.sendTo(this.room, "You are not allowed to join this hunt.");
if ((user.userid in this.players) || this._joinGame(user)) { // if user is already in this parent game, or if the user is able to join this parent game
if ((user.userid in this.playerTable) || this._joinGame(user)) { // if user is already in this parent game, or if the user is able to join this parent game
if (this.childGame && this.childGame.joinGame) return this.childGame.joinGame(user);
}
}
@ -116,13 +116,13 @@ class ScavGame extends Rooms.RoomGame {
// renaming in the parent game
onRename(user, oldUserid, isJoining, isForceRenamed) {
if (!this.allowRenames || (!user.named && !isForceRenamed)) {
if (!(user.userid in this.players)) {
if (!(user.userid in this.playerTable)) {
user.games.delete(this.id);
user.updateSearch();
}
return;
}
if (!(oldUserid in this.players)) return;
if (!(oldUserid in this.playerTable)) return;
this.renamePlayer(user, oldUserid);
if (this.childGame && this.childGame.onRename) this.childGame.onRename(user, oldUserid, isJoining, isForceRenamed);
}
@ -136,8 +136,8 @@ class ScavGame extends Rooms.RoomGame {
}
this.room.game = null;
this.room = null;
for (let i in this.players) {
this.players[i].destroy();
for (let i in this.playerTable) {
this.playerTable[i].destroy();
}
}
@ -197,13 +197,13 @@ class ScavGame extends Rooms.RoomGame {
}
eliminate(userid) {
if (!(userid in this.players)) return false;
let name = this.players[userid].name;
if (!(userid in this.playerTable)) return false;
let name = this.playerTable[userid].name;
this.players[userid].destroy();
this.playerTable[userid].destroy();
if (this.childGame && this.childGame.eliminate) this.childGame.eliminate(userid);
delete this.players[userid];
delete this.playerTable[userid];
this.playerCount--;
if (this.leaderboard) {
@ -223,7 +223,7 @@ class KOGame extends ScavGame {
}
canJoinGame(user) {
return this.round === 1 || (user.userid in this.players);
return this.round === 1 || (user.userid in this.playerTable);
}
onStartEvent() {
@ -231,7 +231,7 @@ class KOGame extends ScavGame {
if (this.round === 1) {
this.announce(`Knockout Games - Round 1. Everyone is welcome to join!`);
} else {
let participants = Object.keys(this.players).map(p => this.players[p].name);
let participants = Object.keys(this.playerTable).map(p => this.playerTable[p].name);
this.announce(`Knockout Games - Round ${this.round}. Only the following ${participants.length} players are allowed to join: ${participants.join(', ')}.`);
}
}
@ -247,14 +247,14 @@ class KOGame extends ScavGame {
if (this.round === 1) {
// prune the players that havent finished
for (let i in this.players) {
if (!(i in this.childGame.players) || !this.childGame.players[i].completed) this.eliminate(i); // user hasnt finished.
for (let i in this.playerTable) {
if (!(i in this.childGame.playerTable) || !this.childGame.playerTable[i].completed) this.eliminate(i); // user hasnt finished.
}
this.announce(`Congratulations to ${Chat.toListString(Object.keys(this.players).map(i => this.players[i].name))}! They have completed the first round, and have moved on to the next round!`);
this.announce(`Congratulations to ${Chat.toListString(Object.keys(this.playerTable).map(i => this.playerTable[i].name))}! They have completed the first round, and have moved on to the next round!`);
return;
}
let unfinished = Object.keys(this.players).filter(id => !completed.includes(id));
let unfinished = Object.keys(this.playerTable).filter(id => !completed.includes(id));
if (!unfinished.length) {
unfinished = completed.slice(-1);
@ -262,9 +262,9 @@ class KOGame extends ScavGame {
let eliminated = unfinished.map(id => this.eliminate(id)).filter(n => n); // this.eliminate() returns the players name.
if (Object.keys(this.players).length <= 1) {
if (Object.keys(this.playerTable).length <= 1) {
// game over
let winner = this.players[Object.keys(this.players)[0]];
let winner = this.playerTable[Object.keys(this.playerTable)[0]];
if (winner) {
this.announce(`Congratulations to ${winner.name} for winning the Knockout Games!`);
@ -275,7 +275,7 @@ class KOGame extends ScavGame {
return;
}
this.announce(`${Chat.toListString(eliminated.map(n => `<em>${n}</em>`))} ${Chat.plural(eliminated, 'have', 'has')} been eliminated! ${Chat.toListString(Object.keys(this.players).map(p => `<em>${this.players[p].name}</em>`))} have successfully completed the last hunt and have moved on to the next round!`);
this.announce(`${Chat.toListString(eliminated.map(n => `<em>${n}</em>`))} ${Chat.plural(eliminated, 'have', 'has')} been eliminated! ${Chat.toListString(Object.keys(this.playerTable).map(p => `<em>${this.playerTable[p].name}</em>`))} have successfully completed the last hunt and have moved on to the next round!`);
}
}
@ -285,7 +285,7 @@ class ScavengerGames extends ScavGame {
}
canJoinGame(user) {
return this.round === 1 || (user.userid in this.players);
return this.round === 1 || (user.userid in this.playerTable);
}
onStartEvent() {
@ -293,7 +293,7 @@ class ScavengerGames extends ScavGame {
if (this.round === 1) {
this.announce(`Scavenger Games - Round 1. Everyone is welcome to join!`);
} else {
let participants = Object.keys(this.players).map(p => this.players[p].name);
let participants = Object.keys(this.playerTable).map(p => this.playerTable[p].name);
this.announce(`Scavenger Games - Round ${this.round}. Only the following ${participants.length} players are allowed to join: ${participants.join(', ')}. You have one minute to complete the hunt!`);
setImmediate(() => this.childGame.setTimer(1));
}
@ -310,20 +310,20 @@ class ScavengerGames extends ScavGame {
if (this.round === 1) {
// prune the players that havent finished
for (let i in this.players) {
if (!(i in this.childGame.players) || !this.childGame.players[i].completed) this.eliminate(i); // user hasnt finished.
for (let i in this.playerTable) {
if (!(i in this.childGame.playerTable) || !this.childGame.playerTable[i].completed) this.eliminate(i); // user hasnt finished.
}
this.announce(`Congratulations to ${Chat.toListString(Object.keys(this.players).map(i => this.players[i].name))}! They have completed the first round, and have moved on to the next round!`);
this.announce(`Congratulations to ${Chat.toListString(Object.keys(this.playerTable).map(i => this.playerTable[i].name))}! They have completed the first round, and have moved on to the next round!`);
return;
}
let unfinished = Object.keys(this.players).filter(id => !completed.includes(id));
let unfinished = Object.keys(this.playerTable).filter(id => !completed.includes(id));
let eliminated = unfinished.map(id => this.eliminate(id)).filter(n => n); // this.eliminate() returns the players name.
if (Object.keys(this.players).length <= 1) {
if (Object.keys(this.playerTable).length <= 1) {
// game over
let winner = this.players[Object.keys(this.players)[0]];
let winner = this.playerTable[Object.keys(this.playerTable)[0]];
if (winner) {
this.announce(`Congratulations to ${winner.name} for winning the Knockout Games!`);
@ -334,7 +334,7 @@ class ScavengerGames extends ScavGame {
return;
}
this.announce(`${Chat.toListString(eliminated.map(n => `<em>${n}</em>`))} ${Chat.plural(eliminated, 'have', 'has')} been eliminated! ${Chat.toListString(Object.keys(this.players).map(p => `<em>${this.players[p].name}</em>`))} have successfully completed the last hunt and have moved on to the next round!`);
this.announce(`${Chat.toListString(eliminated.map(n => `<em>${n}</em>`))} ${Chat.plural(eliminated, 'have', 'has')} been eliminated! ${Chat.toListString(Object.keys(this.playerTable).map(p => `<em>${this.playerTable[p].name}</em>`))} have successfully completed the last hunt and have moved on to the next round!`);
}
}
@ -445,8 +445,8 @@ class JumpStart extends ScavGame {
}
if (this.round === 1) {
// prune the players that havent finished
for (let i in this.players) {
if (!(i in this.childGame.players) || !this.childGame.players[i].completed) this.eliminate(i); // user hasnt finished.
for (let i in this.playerTable) {
if (!(i in this.childGame.playerTable) || !this.childGame.playerTable[i].completed) this.eliminate(i); // user hasnt finished.
}
this.announce(`The early distribution of hints will start in one minute!`);
@ -498,8 +498,8 @@ class PointRally extends ScavGame {
if (this.childGame && this.childGame.destroy) this.childGame.destroy();
this.room.game = null;
this.room = null;
for (let i in this.players) {
this.players[i].destroy();
for (let i in this.playerTable) {
this.playerTable[i].destroy();
}
}
}
@ -520,12 +520,12 @@ class Incognito extends ScavGame {
onSubmit(user, value) {
if (this.childGame && this.childGame.onSubmit) {
// intercept handling of the last question
if (user.userid in this.childGame.players && this.childGame.players[user.userid].currentQuestion + 1 >= this.childGame.questions.length) {
if (user.userid in this.childGame.playerTable && this.childGame.playerTable[user.userid].currentQuestion + 1 >= this.childGame.questions.length) {
let hunt = this.childGame;
value = toId(value);
let player = hunt.players[user.userid];
let player = hunt.playerTable[user.userid];
if (player.completed) {
if (!this.blind) return;
return player.sendRoom(`That may or may not be the right answer - if you aren't confident, you can try again!`);

View File

@ -263,7 +263,7 @@ class ScavengerHunt extends Rooms.RoomGame {
}
leaveGame(user) {
let player = this.players[user.userid];
let player = this.playerTable[user.userid];
if (!player) return user.sendTo(this.room, "You have not joined the scavenger hunt.");
if (player.completed) return user.sendTo(this.room, "You have already completed this scavenger hunt.");
@ -306,8 +306,8 @@ class ScavengerHunt extends Rooms.RoomGame {
this.questions[number][question_answer] = value;
this.announce(`The ${question_answer} for question ${number + 1} has been edited.`);
if (question_answer === 'hint') {
for (let p in this.players) {
this.players[p].onNotifyChange(number);
for (let p in this.playerTable) {
this.playerTable[p].onNotifyChange(number);
}
}
return true;
@ -331,13 +331,13 @@ class ScavengerHunt extends Rooms.RoomGame {
}
onSubmit(user, value) {
if (!(user.userid in this.players)) {
if (!(user.userid in this.playerTable)) {
if (!this.parentGame && !this.joinGame(user)) return false;
if (this.parentGame && !this.parentGame.joinGame(user)) return false;
}
value = toId(value);
let player = this.players[user.userid];
let player = this.playerTable[user.userid];
if (player.completed) return false;
this.validatePlayer(player);
@ -356,9 +356,9 @@ class ScavengerHunt extends Rooms.RoomGame {
}
onSendQuestion(user) {
if (!(user.userid in this.players) || this.hosts.some(h => h.userid === user.userid)) return false;
if (!(user.userid in this.playerTable) || this.hosts.some(h => h.userid === user.userid)) return false;
let player = this.players[user.userid];
let player = this.playerTable[user.userid];
if (player.completed) return false;
let current = player.getCurrentQuestion();
@ -371,8 +371,8 @@ class ScavengerHunt extends Rooms.RoomGame {
let qLimit = 0;
if (this.hosts.some(h => h.userid === user.userid) || user.userid === this.staffHostId) {
qLimit = this.questions.length;
} else if (user.userid in this.players) {
let player = this.players[user.userid];
} else if (user.userid in this.playerTable) {
let player = this.playerTable[user.userid];
qLimit = player.currentQuestion;
}
@ -460,13 +460,13 @@ class ScavengerHunt extends Rooms.RoomGame {
onTallyLeaderboard() {
// update player leaderboard with the statistics
for (let p in this.players) {
let player = this.players[p];
for (let p in this.playerTable) {
let player = this.playerTable[p];
PlayerLeaderboard.addPoints(player.name, 'join', 1);
if (player.completed) PlayerLeaderboard.addPoints(player.name, 'finish', 1);
}
for (let id in this.leftHunt) {
if (id in this.players) continue; // this should never happen, but just in case;
if (id in this.playerTable) continue; // this should never happen, but just in case;
PlayerLeaderboard.addPoints(id, 'join', 1, true);
}
@ -507,8 +507,8 @@ class ScavengerHunt extends Rooms.RoomGame {
if (this.timer) {
clearTimeout(this.timer);
}
for (let i in this.players) {
this.players[i].destroy();
for (let i in this.playerTable) {
this.playerTable[i].destroy();
}
// destroy this game
if (this.parentGame) {
@ -559,13 +559,13 @@ class ScavengerHunt extends Rooms.RoomGame {
}
eliminate(userid) {
if (!(userid in this.players)) return false;
let player = this.players[userid];
if (!(userid in this.playerTable)) return false;
let player = this.playerTable[userid];
if (player.completed) return true; // do not remove players that have completed - they should still get to see the answers
player.destroy();
delete this.players[userid];
delete this.playerTable[userid];
return true;
}
@ -590,7 +590,7 @@ class ScavengerHunt extends Rooms.RoomGame {
}
hasFinished(user) {
return this.players[user.userid] && this.players[user.userid].completed;
return this.playerTable[user.userid] && this.playerTable[user.userid].completed;
}
getUniqueConnections(user) {
@ -899,7 +899,7 @@ let commands = {
let str = `<div class="ladder" style="overflow-y: scroll; max-height: 300px;"><table style="width: 100%"><th><b>Question</b></th><th><b>Users on this Question</b></th>`;
for (let i = 0; i < game.questions.length; i++) {
let questionNum = i + 1;
let players = Object.values(game.players).filter(player => player.currentQuestion === i && !player.completed);
let players = Object.values(game.playerTable).filter(player => player.currentQuestion === i && !player.completed);
if (!players.length) {
str += `<tr><td>${questionNum}</td><td>None</td>`;
} else {

View File

@ -363,19 +363,19 @@ class Trivia extends Rooms.RoomGame {
* @return {string | undefined}
*/
addPlayer(user) {
if (this.players[user.userid]) return 'You have already signed up for this game.';
if (this.playerTable[user.userid]) return 'You have already signed up for this game.';
for (let id in user.prevNames) {
if (this.players[id]) return 'You have already signed up for this game.';
if (this.playerTable[id]) return 'You have already signed up for this game.';
}
if (this.kickedUsers.has(user.userid)) {
return 'You were kicked from the game and thus cannot join it again.';
}
for (let id in user.prevNames) {
if (this.players[id]) return 'You have already signed up for this game.';
if (this.playerTable[id]) return 'You have already signed up for this game.';
if (this.kickedUsers.has(id)) return 'You were kicked from the game and cannot join until the next game.';
}
for (let id in this.players) {
for (let id in this.playerTable) {
let tarUser = Users.get(id);
if (tarUser) {
if (tarUser.prevNames[user.userid]) return 'You have already signed up for this game.';
@ -413,7 +413,7 @@ class Trivia extends Rooms.RoomGame {
* @return {boolean}
*/
onConnect(user) {
let player = this.players[user.userid];
let player = this.playerTable[user.userid];
if (!player || !player.isAbsent) return false;
player.toggleAbsence();
@ -423,8 +423,8 @@ class Trivia extends Rooms.RoomGame {
// At least let the game start first!!
if (this.phase === SIGNUP_PHASE) return false;
for (let i in this.players) {
this.players[i].clearAnswer();
for (let i in this.playerTable) {
this.playerTable[i].clearAnswer();
}
this.broadcast(
@ -442,7 +442,7 @@ class Trivia extends Rooms.RoomGame {
onLeave(user) {
// The user cannot participate, but their score should be kept
// regardless in cases of disconnects.
let player = this.players[user.userid];
let player = this.playerTable[user.userid];
if (!player || player.isAbsent) return false;
player.toggleAbsence();
@ -514,7 +514,7 @@ class Trivia extends Rooms.RoomGame {
* @return {string}
*/
kick(tarUser, user) {
if (!this.players[tarUser.userid]) {
if (!this.playerTable[tarUser.userid]) {
if (this.kickedUsers.has(tarUser.userid)) return `User ${tarUser.name} has already been kicked from the game.`;
for (let id in tarUser.prevNames) {
@ -554,7 +554,7 @@ class Trivia extends Rooms.RoomGame {
* @return {string | undefined}
*/
leave(user) {
if (!this.players[user.userid]) {
if (!this.playerTable[user.userid]) {
return 'You are not a player in the current game.';
}
super.removePlayer(user);
@ -674,8 +674,8 @@ class Trivia extends Rooms.RoomGame {
buffer += '<br />' + this.getWinningMessage(winners);
this.broadcast('The answering period has ended!', buffer);
for (const userid in this.players) {
let player = this.players[userid];
for (const userid in this.playerTable) {
let player = this.playerTable[userid];
if (!player.points) continue;
for (const leaderboard of [triviaData.leaderboard, triviaData.altLeaderboard]) {
@ -697,8 +697,8 @@ class Trivia extends Rooms.RoomGame {
cachedLadder.invalidateCache();
cachedAltLadder.invalidateCache();
for (let i in this.players) {
let player = this.players[i];
for (let i in this.playerTable) {
let player = this.playerTable[i];
let user = Users.get(player.userid);
if (!user) continue;
user.sendTo(
@ -724,9 +724,9 @@ class Trivia extends Rooms.RoomGame {
getTopPlayers({max = null, requirePoints = true}) {
const ranks = [];
for (const userid in this.players) {
for (const userid in this.playerTable) {
const user = Users.get(userid);
const player = this.players[userid];
const player = this.playerTable[userid];
if ((requirePoints && !player.points) || !user) continue;
ranks.push({userid, player, name: user.name});
}
@ -798,7 +798,7 @@ class FirstModeTrivia extends Trivia {
* @return {string | undefined}
*/
answerQuestion(answer, user) {
let player = this.players[user.userid];
let player = this.playerTable[user.userid];
if (!player) return 'You are not a player in the current trivia game.';
if (this.phase !== QUESTION_PHASE) return 'There is no question to answer.';
if (player.answer) return 'You have already attempted to answer the current question.';
@ -820,8 +820,8 @@ class FirstModeTrivia extends Trivia {
return;
}
for (let i in this.players) {
this.players[i].clearAnswer();
for (let i in this.playerTable) {
this.playerTable[i].clearAnswer();
}
this.broadcast('The answering period has ended!', buffer);
@ -838,8 +838,8 @@ class FirstModeTrivia extends Trivia {
tallyAnswers() {
this.phase = INTERMISSION_PHASE;
for (let i in this.players) {
let player = this.players[i];
for (let i in this.playerTable) {
let player = this.playerTable[i];
player.clearAnswer();
}
@ -866,7 +866,7 @@ class TimerModeTrivia extends Trivia {
* @return {string | undefined}
*/
answerQuestion(answer, user) {
let player = this.players[user.userid];
let player = this.playerTable[user.userid];
if (!player) return 'You are not a player in the current trivia game.';
if (this.phase !== QUESTION_PHASE) return 'There is no question to answer.';
@ -905,8 +905,8 @@ class TimerModeTrivia extends Trivia {
let now = hrtimeToNanoseconds(process.hrtime());
let askedAt = hrtimeToNanoseconds(this.askedAt);
let totalDiff = now - askedAt;
for (let i in this.players) {
let player = this.players[i];
for (let i in this.playerTable) {
let player = this.playerTable[i];
if (!player.isCorrect) {
player.clearAnswer();
continue;
@ -974,7 +974,7 @@ class NumberModeTrivia extends Trivia {
* @return {string | undefined}
*/
answerQuestion(answer, user) {
let player = this.players[user.userid];
let player = this.playerTable[user.userid];
if (!player) return 'You are not a player in the current trivia game.';
if (this.phase !== QUESTION_PHASE) return 'There is no question to answer.';
@ -998,10 +998,10 @@ class NumberModeTrivia extends Trivia {
this.phase = INTERMISSION_PHASE;
let buffer;
let innerBuffer = Object.keys(this.players)
.filter(id => this.players[id].isCorrect)
let innerBuffer = Object.keys(this.playerTable)
.filter(id => this.playerTable[id].isCorrect)
.map(id => {
let player = this.players[id];
let player = this.playerTable[id];
return [Chat.escapeHTML(player.name), hrtimeToNanoseconds(player.currentAnsweredAt)];
})
.sort((a, b) => a[1] - b[1]);
@ -1009,8 +1009,8 @@ class NumberModeTrivia extends Trivia {
let points = this.calculatePoints(innerBuffer.length);
if (points) {
let winner = false;
for (let i in this.players) {
let player = this.players[i];
for (let i in this.playerTable) {
let player = this.playerTable[i];
if (player.isCorrect) player.incrementPoints(points, this.questionNumber);
if (player.points >= this.getCap()) {
@ -1026,8 +1026,8 @@ class NumberModeTrivia extends Trivia {
if (winner) return this.win(buffer);
} else {
for (let i in this.players) {
let player = this.players[i];
for (let i in this.playerTable) {
let player = this.playerTable[i];
player.clearAnswer();
}
@ -1062,7 +1062,7 @@ class WeakestLink extends Trivia {
start() {
super.start();
this.curPlayer = this.players[Object.keys(this.players)[0]];
this.curPlayer = this.playerTable[Object.keys(this.playerTable)[0]];
}
sendQuestion(question) {
@ -1077,7 +1077,7 @@ class WeakestLink extends Trivia {
}
onBank(user) {
let player = this.players[user.userid];
let player = this.playerTable[user.userid];
if (!player) return 'You are not a participant in the current game';
if (this.phase !== 'banking') return 'You cannot bank at this time.';
if (this.curPlayer.userid !== player.userid) return 'It is not your turn to bank.';
@ -1090,7 +1090,7 @@ class WeakestLink extends Trivia {
}
answerQuestion(answer, user) {
let player = this.players[user.userid];
let player = this.playerTable[user.userid];
if (!player) return 'You are not a player in the current trivia game.';
if (this.phase !== QUESTION_PHASE) return 'There is no question to answer.';
clearTimeout(this.phaseTimeout);
@ -1114,14 +1114,14 @@ class WeakestLink extends Trivia {
`${this.curPlayer.name} ${answer.length === 0 ? "did not answer" : "answered " + ((isCorrect ? "correctly" : "incorrectly") + " with " + answer)}`
);
this.playerindex++;
if (this.playerindex === Object.keys(this.players).length) {
if (this.playerindex === Object.keys(this.playerTable).length) {
this.playerindex = 0;
if (this.finals) {
this.numFinals++;
if (this.numFinals >= NUM_FINALS_QUESTIONS) {
let oplayer;
for (let userID in this.players) {
let player = this.players[userID];
for (let userID in this.playerTable) {
let player = this.playerTable[userID];
if (player !== this.curPlayer) {
oplayer = player;
break;
@ -1142,10 +1142,10 @@ class WeakestLink extends Trivia {
}
}
}
this.curPlayer = this.players[Object.keys(this.players)[this.playerindex]];
this.curPlayer = this.playerTable[Object.keys(this.playerTable)[this.playerindex]];
this.phase = 'banking';
this.broadcast(
`Players: ${Object.keys(this.players).map(p => (this.curPlayer.userid === p ? "<em>" + this.players[p].name + "</em>" : this.players[p].name) + (this.finals ? "(" + this.players[p].correctAnswers + ")" : "")).join(", ")}`,
`Players: ${Object.keys(this.playerTable).map(p => (this.curPlayer.userid === p ? "<em>" + this.playerTable[p].name + "</em>" : this.playerTable[p].name) + (this.finals ? "(" + this.playerTable[p].correctAnswers + ")" : "")).join(", ")}`,
`Bank: ${this.bank}<br />Amount to bank: ${this.amountToBank}`
);
this.setPhaseTimeout(() => this.askQuestion(), 5 * 1000);
@ -1159,16 +1159,16 @@ class WeakestLink extends Trivia {
clearTimeout(this.phaseTimeout);
this.phase = "voting";
this.broadcast(
`Players: ${Object.keys(this.players).map(p => this.players[p].name).join(", ")}`,
`Players: ${Object.keys(this.playerTable).map(p => this.playerTable[p].name).join(", ")}`,
`Bank: ${this.bank}<br />Vote for who you would like to eliminate with /trivia vote [user]`
);
}
vote(target, user) {
let player = this.players[user.userid];
let player = this.playerTable[user.userid];
if (!player) return 'You are not a participant in the current game.';
if (this.phase !== "voting") return "You cannot vote at this time.";
let targPlayer = this.players[toId(target)];
let targPlayer = this.playerTable[toId(target)];
if (!targPlayer) return `No player named '${target}' is currently in the game.`;
if (targPlayer.userid === player.userid) return "You cannot vote to eliminate yourself.";
player.vote = targPlayer;
@ -1180,15 +1180,15 @@ class WeakestLink extends Trivia {
tallyVotes() {
let votes = {};
for (let userID in this.players) {
let id = this.players[userID].vote.userid;
for (let userID in this.playerTable) {
let id = this.playerTable[userID].vote.userid;
if (!(id in votes)) votes[id] = 0;
votes[id]++;
}
let maxNum = 0;
let maxVotes = [];
for (let userID in this.players) {
let curPlayer = this.players[userID];
for (let userID in this.playerTable) {
let curPlayer = this.playerTable[userID];
let numVotes = votes[userID] || 0;
if (numVotes > maxNum) {
maxNum = numVotes;
@ -1211,24 +1211,24 @@ class WeakestLink extends Trivia {
startRound() {
this.phase = INTERMISSION_PHASE;
if (Object.keys(this.players).length === 2) {
if (Object.keys(this.playerTable).length === 2) {
this.finals = true;
this.numFinals = 0;
}
this.roundstarted = false;
if (this.finals) {
this.curPlayer = this.players[Object.keys(this.players)[0]];
this.curPlayer = this.playerTable[Object.keys(this.playerTable)[0]];
} else {
this.curPlayer = this.strongestPlayer();
}
for (let userID in this.players) {
let player = this.players[userID];
for (let userID in this.playerTable) {
let player = this.playerTable[userID];
player.points = 0;
player.correctAnswers = 0;
}
this.playerindex = Object.keys(this.players).indexOf(this.curPlayer.userid);
this.playerindex = Object.keys(this.playerTable).indexOf(this.curPlayer.userid);
this.broadcast(
`Players: ${Object.keys(this.players).map(p => this.players[p].name).join(", ")}`,
`Players: ${Object.keys(this.playerTable).map(p => this.playerTable[p].name).join(", ")}`,
`Bank: ${this.bank}<br />The ${this.finals ? "next" : "final"} round will begin in 30 seconds, and it will be ${this.curPlayer.name}'s turn to answer.`
);
this.timeout = setTimeout(() => this.askQuestion(), 30 * 1000);
@ -1241,8 +1241,8 @@ class WeakestLink extends Trivia {
strongestPlayer() {
let maxAnswers = 0;
let maxPlayer = [];
for (let userID in this.players) {
let player = this.players[userID];
for (let userID in this.playerTable) {
let player = this.playerTable[userID];
if (player.correctAnswers > maxAnswers) {
maxPlayer = [player];
maxAnswers = player.correctAnswers;
@ -1269,19 +1269,19 @@ class WeakestLink extends Trivia {
}
checkVotes() {
for (let userID in this.players) {
let player = this.players[userID];
for (let userID in this.playerTable) {
let player = this.playerTable[userID];
if (!player.vote) return false;
}
return true;
}
decide(target, user) {
let player = this.players[user.userid];
let player = this.playerTable[user.userid];
if (!player) return 'You are not participating in the current game.';
if (this.phase !== 'deciding') return 'You cannot decide who to eliminate at this time.';
if (this.curPlayer !== player) return 'It is not your turn to decide who to eliminate';
let targPlayer = this.players[toId(target)];
let targPlayer = this.playerTable[toId(target)];
if (!targPlayer) return 'That player is not in the game.';
if (this.potentialElims.indexOf(targPlayer) === -1) return 'That player cannot be eliminated.';
this.sendToRoom(`${this.curPlayer.name} has decided to eliminate ${targPlayer.name}!`);
@ -1471,7 +1471,7 @@ const commands = {
let buffer = `There is a trivia game in progress, and it is in its ${game.phase} phase.<br />` +
`Mode: ${game.mode} | Category: ${game.category} | Score cap: ${game.getCap()}`;
let player = game.players[tarUser.userid];
let player = game.playerTable[tarUser.userid];
if (player) {
if (!this.broadcasting) {
buffer += `<br />Current score: ${player.points} | Correct Answers: ${player.correctAnswers}`;
@ -1910,7 +1910,7 @@ const commands = {
if (!this.can('broadcast', null, room)) return;
if (!this.runBroadcast()) return;
if (room.game.phase !== 'voting') return this.sendReplyBox("The game is not currently in the voting phase");
return this.sendReplyBox(`The following players have yet to vote: ${Object.values(room.game.players).filter(pl => !pl.vote).map(pl => pl.name).join(", ")}`);
return this.sendReplyBox(`The following players have yet to vote: ${Object.values(room.game.playerTable).filter(pl => !pl.vote).map(pl => pl.name).join(", ")}`);
},
checkvoteshelp: [`/trivia checkvotes - Check which players have not yet voted.`],

View File

@ -99,10 +99,10 @@ class UnoGame extends Rooms.RoomGame {
// TypeScript bug: no `T extends RoomGamePlayer`
/** @type {{[userid: string]: UnoGamePlayer}} */
this.players = Object.create(null);
this.playerTable = Object.create(null);
// TypeScript bug: no `T extends RoomGamePlayer`
/** @type {UnoGamePlayer[]} */
this.playerList = [];
this.players = [];
if (room.gameNumber) {
room.gameNumber++;
@ -174,8 +174,8 @@ class UnoGame extends Rooms.RoomGame {
this.onNextPlayer(); // determines the first player
// give cards to the players
for (let i in this.players) {
this.players[i].hand.push(...this.drawCard(7));
for (let i in this.playerTable) {
this.playerTable[i].hand.push(...this.drawCard(7));
}
// top card of the deck.
@ -231,18 +231,18 @@ class UnoGame extends Rooms.RoomGame {
* @return {false | void}
*/
onRename(user, oldUserid, isJoining, isForceRenamed) {
if (!(oldUserid in this.players) || user.userid === oldUserid) return false;
if (!(oldUserid in this.playerTable) || user.userid === oldUserid) return false;
if (!user.named && !isForceRenamed) {
user.games.delete(this.id);
user.updateSearch();
return; // dont set users to their guest accounts.
}
this.players[user.userid] = this.players[oldUserid];
if (user.userid !== oldUserid) delete this.players[oldUserid]; // only run if it's a rename that involves a change of userid
this.playerTable[user.userid] = this.playerTable[oldUserid];
if (user.userid !== oldUserid) delete this.playerTable[oldUserid]; // only run if it's a rename that involves a change of userid
// update the user's name information
this.players[user.userid].name = user.name;
this.players[user.userid].userid = user.userid;
this.playerTable[user.userid].name = user.name;
this.playerTable[user.userid].userid = user.userid;
if (this.awaitUno && this.awaitUno === oldUserid) this.awaitUno = user.userid;
if (this.currentPlayerid === oldUserid) this.currentPlayerid = user.userid;
@ -253,13 +253,13 @@ class UnoGame extends Rooms.RoomGame {
* @return {string | false}
*/
eliminate(userid) {
if (!(userid in this.players)) return false;
if (!(userid in this.playerTable)) return false;
let name = this.players[userid].name;
let name = this.playerTable[userid].name;
if (this.playerCount === 2) {
this.removePlayer(this.players[userid]);
this.onWin(this.players[Object.keys(this.players)[0]]);
this.removePlayer(this.playerTable[userid]);
this.onWin(this.playerTable[Object.keys(this.playerTable)[0]]);
return name;
}
@ -280,9 +280,9 @@ class UnoGame extends Rooms.RoomGame {
if (this.awaitUno === userid) this.awaitUno = null;
// put that player's cards into the discard pile to prevent cards from being permanently lost
this.discards.push(...this.players[userid].hand);
this.discards.push(...this.playerTable[userid].hand);
this.removePlayer(this.players[userid]);
this.removePlayer(this.playerTable[userid]);
return name;
}
@ -295,13 +295,13 @@ class UnoGame extends Rooms.RoomGame {
this.room.add(msg).update();
} else {
// send to the players first
for (let i in this.players) {
this.players[i].sendRoom(msg);
for (let i in this.playerTable) {
this.playerTable[i].sendRoom(msg);
}
// send to spectators
for (let i in this.spectators) {
if (i in this.players) continue; // don't double send to users already in the game.
if (i in this.playerTable) continue; // don't double send to users already in the game.
let user = Users.getExact(i);
if (user) user.sendTo(this.id, msg);
}
@ -313,12 +313,12 @@ class UnoGame extends Rooms.RoomGame {
* @return {string[]}
*/
getPlayers(showCards) {
let playerList = Object.keys(this.players);
let playerList = Object.keys(this.playerTable);
if (!showCards) {
return playerList.sort().map(id => Chat.escapeHTML(this.players[id].name));
return playerList.sort().map(id => Chat.escapeHTML(this.playerTable[id].name));
}
if (this.direction === -1) playerList = playerList.reverse();
return playerList.map(id => `${(this.currentPlayerid === id ? '<strong>' : '')}${Chat.escapeHTML(this.players[id].name)} (${this.players[id].hand.length}) ${(this.currentPlayerid === id ? '</strong>' : "")}`);
return playerList.map(id => `${(this.currentPlayerid === id ? '<strong>' : '')}${Chat.escapeHTML(this.playerTable[id].name)} (${this.playerTable[id].hand.length}) ${(this.currentPlayerid === id ? '</strong>' : "")}`);
}
/**
@ -348,7 +348,7 @@ class UnoGame extends Rooms.RoomGame {
if (!starting) this.onNextPlayer();
if (this.timer) clearTimeout(this.timer);
let player = this.players[this.currentPlayerid];
let player = this.playerTable[this.currentPlayerid];
this.sendToRoom(`|c:|${(Math.floor(Date.now() / 1000))}|~|${player.name}'s turn.`);
this.state = 'play';
@ -365,7 +365,7 @@ class UnoGame extends Rooms.RoomGame {
onNextPlayer() {
// if none is set
if (!this.currentPlayerid) {
let userList = Object.keys(this.players);
let userList = Object.keys(this.playerTable);
this.currentPlayerid = userList[Math.floor(this.playerCount * Math.random())];
}
@ -376,7 +376,7 @@ class UnoGame extends Rooms.RoomGame {
* @return {string}
*/
getNextPlayer() {
let userList = Object.keys(this.players);
let userList = Object.keys(this.playerTable);
let player = userList[(userList.indexOf(this.currentPlayerid) + this.direction)];
@ -468,31 +468,31 @@ class UnoGame extends Rooms.RoomGame {
break;
case 'Skip':
this.onNextPlayer();
this.sendToRoom(this.players[this.currentPlayerid].name + "'s turn has been skipped.");
this.sendToRoom(this.playerTable[this.currentPlayerid].name + "'s turn has been skipped.");
break;
case '+2':
this.onNextPlayer();
this.sendToRoom(this.players[this.currentPlayerid].name + " has been forced to draw 2 cards.");
this.onDrawCard(this.players[this.currentPlayerid], 2);
this.sendToRoom(this.playerTable[this.currentPlayerid].name + " has been forced to draw 2 cards.");
this.onDrawCard(this.playerTable[this.currentPlayerid], 2);
break;
case '+4':
this.players[this.currentPlayerid].sendRoom(colorDisplay);
this.playerTable[this.currentPlayerid].sendRoom(colorDisplay);
this.state = 'color';
// apply to the next in line, since the current player still has to choose the color
let next = this.getNextPlayer();
this.sendToRoom(this.players[next].name + " has been forced to draw 4 cards.");
this.onDrawCard(this.players[next], 4);
this.sendToRoom(this.playerTable[next].name + " has been forced to draw 4 cards.");
this.onDrawCard(this.playerTable[next], 4);
this.isPlusFour = true;
this.timer = setTimeout(() => {
this.sendToRoom(`${this.players[this.currentPlayerid].name} has been automatically disqualified.`);
this.sendToRoom(`${this.playerTable[this.currentPlayerid].name} has been automatically disqualified.`);
this.eliminate(this.currentPlayerid);
}, this.maxTime * 1000);
break;
case 'Wild':
this.players[this.currentPlayerid].sendRoom(colorDisplay);
this.playerTable[this.currentPlayerid].sendRoom(colorDisplay);
this.state = 'color';
this.timer = setTimeout(() => {
this.sendToRoom(`${this.players[this.currentPlayerid].name} has been automatically disqualified.`);
this.sendToRoom(`${this.playerTable[this.currentPlayerid].name} has been automatically disqualified.`);
this.eliminate(this.currentPlayerid);
}, this.maxTime * 1000);
break;
@ -578,8 +578,8 @@ class UnoGame extends Rooms.RoomGame {
if (this.awaitUno) {
// if the previous player hasn't hit UNO before the next player plays something, they are forced to draw 2 cards;
if (this.awaitUno !== this.currentPlayerid) {
this.sendToRoom(`${this.players[this.awaitUno].name} forgot to say UNO! and is forced to draw 2 cards.`);
this.onDrawCard(this.players[this.awaitUno], 2);
this.sendToRoom(`${this.playerTable[this.awaitUno].name} forgot to say UNO! and is forced to draw 2 cards.`);
this.onDrawCard(this.playerTable[this.awaitUno], 2);
}
this.awaitUno = null;
this.unoId = null;
@ -591,9 +591,9 @@ class UnoGame extends Rooms.RoomGame {
* @return {false | void}
*/
onSendHand(user) {
if (!(user.userid in this.players) || this.state === 'signups') return false;
if (!(user.userid in this.playerTable) || this.state === 'signups') return false;
this.players[user.userid].sendDisplay();
this.playerTable[user.userid].sendDisplay();
}
/**
@ -610,8 +610,8 @@ class UnoGame extends Rooms.RoomGame {
this.sendToRoom(`|uhtmlchange|uno-${this.room.gameNumber}|<div class="infobox">The game of UNO has ended.</div>`, true);
// deallocate games for each player.
for (let i in this.players) {
this.players[i].destroy();
for (let i in this.playerTable) {
this.playerTable[i].destroy();
}
delete this.room.game;
}
@ -842,7 +842,7 @@ const commands = {
const game = /** @type {UnoGame} */ (room.game);
if (!game || game.gameid !== 'uno') return this.errorReply("There is no UNO game going on in this room right now.");
/** @type {UnoGamePlayer | undefined} */
let player = game.players[user.userid];
let player = game.playerTable[user.userid];
if (!player) return this.errorReply(`You are not in the game of UNO.`);
let error = game.onPlay(player, target);
if (error) this.errorReply(error);
@ -852,7 +852,7 @@ const commands = {
const game = /** @type {UnoGame} */ (room.game);
if (!game || game.gameid !== 'uno') return this.errorReply("There is no UNO game going on in this room right now.");
/** @type {UnoGamePlayer | undefined} */
let player = game.players[user.userid];
let player = game.playerTable[user.userid];
if (!player) return this.errorReply(`You are not in the game of UNO.`);
let error = game.onDraw(player);
if (error) return this.errorReply("You have already drawn a card this turn.");
@ -863,7 +863,7 @@ const commands = {
if (!game || game.gameid !== 'uno') return this.errorReply("There is no UNO game going on in this room right now.");
if (game.currentPlayerid !== user.userid) return this.errorReply("It is currently not your turn.");
/** @type {UnoGamePlayer | undefined} */
let player = game.players[user.userid];
let player = game.playerTable[user.userid];
if (!player) return this.errorReply(`You are not in the game of UNO.`);
if (!player.cardLock) return this.errorReply("You cannot pass until you draw a card.");
if (game.state === 'color') return this.errorReply("You cannot pass until you choose a color.");
@ -876,7 +876,7 @@ const commands = {
const game = /** @type {UnoGame} */ (room.game);
if (!game || game.gameid !== 'uno') return false;
/** @type {UnoGamePlayer | undefined} */
let player = game.players[user.userid];
let player = game.playerTable[user.userid];
if (!player) return this.errorReply(`You are not in the game of UNO.`);
/** @type {Color} */
let color;
@ -892,7 +892,7 @@ const commands = {
const game = /** @type {UnoGame} */ (room.game);
if (!game || game.gameid !== 'uno') return false;
/** @type {UnoGamePlayer | undefined} */
let player = game.players[user.userid];
let player = game.playerTable[user.userid];
if (!player) return this.errorReply(`You are not in the game of UNO.`);
game.onUno(player, target);
},

View File

@ -486,7 +486,7 @@ class Ladder extends LadderStore {
let out = undefined;
for (const roomid of user.games) {
const room = Rooms(roomid);
if (!room || !room.battle || !room.battle.players[user.userid]) continue;
if (!room || !room.battle || !room.battle.playerTable[user.userid]) continue;
const battle = /** @type {RoomBattle} */ (room.battle);
if (battle.requestCount <= 16) {
// it's fine as long as it's before turn 5
@ -496,7 +496,7 @@ class Ladder extends LadderStore {
if (Dex.getFormat(battle.format).allowMultisearch) {
continue;
}
const player = battle.players[user.userid];
const player = battle.playerTable[user.userid];
if (!player.request.isWait) return roomid;
out = null;
}

View File

@ -197,7 +197,7 @@ class RoomBattleTimer {
}, timerSettings);
if (this.settings.maxPerTurn <= 0) this.settings.maxPerTurn = Infinity;
for (const player of this.battle.playerList) {
for (const player of this.battle.players) {
player.secondsLeft = this.settings.starting + this.settings.grace;
player.turnSecondsLeft = -1;
player.dcSecondsLeft = this.settings.dcTimerBank ? DISCONNECTION_BANK_TIME : DISCONNECTION_TIME;
@ -211,10 +211,10 @@ class RoomBattleTimer {
this.timerRequesters.add(userid);
return false;
}
if (requester && this.battle.players[requester.userid] && this.lastDisabledByUser === requester.userid) {
if (requester && this.battle.playerTable[requester.userid] && this.lastDisabledByUser === requester.userid) {
const remainingCooldownMs = (this.lastDisabledTime || 0) + TIMER_COOLDOWN - Date.now();
if (remainingCooldownMs > 0) {
this.battle.players[requester.userid].sendRoom(`|inactiveoff|The timer can't be re-enabled so soon after disabling it (${Math.ceil(remainingCooldownMs / SECONDS)} seconds remaining).`);
this.battle.playerTable[requester.userid].sendRoom(`|inactiveoff|The timer can't be re-enabled so soon after disabling it (${Math.ceil(remainingCooldownMs / SECONDS)} seconds remaining).`);
return false;
}
}
@ -249,7 +249,7 @@ class RoomBattleTimer {
nextRequest(isFirst = false) {
if (this.timer) clearTimeout(this.timer);
if (!this.timerRequesters.size) return;
const players = this.battle.playerList;
const players = this.battle.players;
if (players.some(player => player.secondsLeft <= 0)) return;
const maxTurnTime = (isFirst ? this.settings.maxFirstTurn : 0) || this.settings.maxPerTurn;
@ -291,7 +291,7 @@ class RoomBattleTimer {
if (this.timer) clearTimeout(this.timer);
if (this.battle.ended) return;
const room = this.battle.room;
for (const player of this.battle.playerList) {
for (const player of this.battle.players) {
if (player.request.isWait) continue;
if (player.connected) {
player.secondsLeft -= TICK_TIME;
@ -330,7 +330,7 @@ class RoomBattleTimer {
}
}
checkActivity() {
for (const player of this.battle.playerList) {
for (const player of this.battle.players) {
const isConnected = !!(player && player.active);
if (isConnected === player.connected) continue;
@ -377,7 +377,7 @@ class RoomBattleTimer {
}
}
checkTimeout() {
const players = this.battle.playerList;
const players = this.battle.players;
if (players.every(player => player.turnSecondsLeft <= 0)) {
if (!this.settings.timeoutAutoChoose || players.every(player => player.secondsLeft <= 0)) {
this.battle.room.add(`|-message|All players are inactive.`).update();
@ -438,10 +438,10 @@ class RoomBattle extends RoomGames.RoomGame {
// TypeScript bug: no `T extends RoomGamePlayer`
/** @type {{[userid: string]: RoomBattlePlayer}} */
this.players = Object.create(null);
this.playerTable = Object.create(null);
// TypeScript bug: no `T extends RoomGamePlayer`
/** @type {RoomBattlePlayer[]} */
this.playerList = [];
this.players = [];
this.playerCap = this.gameType === 'multi' || this.gameType === 'free-for-all' ? 4 : 2;
/** @type {RoomBattlePlayer} */
@ -537,7 +537,7 @@ class RoomBattle extends RoomGames.RoomGame {
* @param {string} data
*/
choose(user, data) {
const player = this.players[user.userid];
const player = this.playerTable[user.userid];
const [choice, rqid] = data.split('|', 2);
if (!player) return;
let request = player.request;
@ -545,7 +545,7 @@ class RoomBattle extends RoomGames.RoomGame {
player.sendRoom(`|error|[Invalid choice] There's nothing to choose`);
return;
}
const allPlayersWait = this.playerList.every(player => !!player.request.isWait);
const allPlayersWait = this.players.every(player => !!player.request.isWait);
if (allPlayersWait || // too late
(rqid && rqid !== '' + request.rqid)) { // WAY too late
player.sendRoom(`|error|[Invalid choice] Sorry, too late to make a different move; the next turn has already started`);
@ -562,7 +562,7 @@ class RoomBattle extends RoomGames.RoomGame {
* @param {string} data
*/
undo(user, data) {
const player = this.players[user.userid];
const player = this.playerTable[user.userid];
const [, rqid] = data.split('|', 2);
if (!player) return;
let request = player.request;
@ -570,7 +570,7 @@ class RoomBattle extends RoomGames.RoomGame {
player.sendRoom(`|error|[Invalid choice] There's nothing to cancel`);
return;
}
const allPlayersWait = this.playerList.every(player => !!player.request.isWait);
const allPlayersWait = this.players.every(player => !!player.request.isWait);
if (allPlayersWait || // too late
(rqid && rqid !== '' + request.rqid)) { // WAY too late
player.sendRoom(`|error|[Invalid choice] Sorry, too late to cancel; the next turn has already started`);
@ -592,7 +592,7 @@ class RoomBattle extends RoomGames.RoomGame {
/** @type {SideID[]} */
let validSlots = [];
for (const player of this.playerList) {
for (const player of this.players) {
if (!player.userid) validSlots.push(player.slot);
}
@ -626,7 +626,7 @@ class RoomBattle extends RoomGames.RoomGame {
user.popup(`Players can't be swapped out in a ${this.room.tour ? "tournament" : "rated"} battle.`);
return false;
}
const player = this.players[user.userid];
const player = this.playerTable[user.userid];
if (!player) {
user.popup(`Failed to leave battle - you're not a player.`);
return false;
@ -807,7 +807,7 @@ class RoomBattle extends RoomGames.RoomGame {
// this handles joining a battle in which a user is a participant,
// where the user has already identified before attempting to join
// the battle
const player = this.players[user.userid];
const player = this.playerTable[user.userid];
if (!player) return;
player.updateChannel(connection || user);
const request = player.request;
@ -833,13 +833,13 @@ class RoomBattle extends RoomGames.RoomGame {
*/
onRename(user, oldUserid, isJoining, isForceRenamed) {
if (user.userid === oldUserid) return;
if (!this.players) {
if (!this.playerTable) {
// !! should never happen but somehow still does
user.games.delete(this.id);
return;
}
if (!(oldUserid in this.players)) {
if (user.userid in this.players) {
if (!(oldUserid in this.playerTable)) {
if (user.userid in this.playerTable) {
// this handles a user renaming themselves into a user in the
// battle (e.g. by using /nick)
this.onConnect(user);
@ -847,18 +847,18 @@ class RoomBattle extends RoomGames.RoomGame {
return;
}
if (!this.allowRenames) {
let player = this.players[oldUserid];
let player = this.playerTable[oldUserid];
if (player) {
const message = isForceRenamed ? " lost by having an inappropriate name." : " forfeited by changing their name.";
this.forfeitPlayer(player, message);
}
if (!(user.userid in this.players)) {
if (!(user.userid in this.playerTable)) {
user.games.delete(this.id);
}
return;
}
if (user.userid in this.players) return;
let player = this.players[oldUserid];
if (user.userid in this.playerTable) return;
let player = this.playerTable[oldUserid];
if (player) {
this.updatePlayer(player, user);
}
@ -872,7 +872,7 @@ class RoomBattle extends RoomGames.RoomGame {
* @param {User} user
*/
onJoin(user) {
let player = this.players[user.userid];
let player = this.playerTable[user.userid];
if (player && !player.active) {
player.active = true;
this.timer.checkActivity();
@ -884,7 +884,7 @@ class RoomBattle extends RoomGames.RoomGame {
* @param {User} user
*/
onLeave(user) {
let player = this.players[user.userid];
let player = this.playerTable[user.userid];
if (player && player.active) {
player.sendRoom(`|request|null`);
player.active = false;
@ -901,7 +901,7 @@ class RoomBattle extends RoomGames.RoomGame {
this.tie();
return true;
}
let player = this.players[user.userid];
let player = this.playerTable[user.userid];
if (!player) return false;
this.stream.write(`>forcewin ${player.slot}`);
}
@ -919,8 +919,8 @@ class RoomBattle extends RoomGames.RoomGame {
if (typeof user !== 'string') user = user.userid;
else user = toId(user);
if (!(user in this.players)) return false;
return this.forfeitPlayer(this.players[user], message);
if (!(user in this.playerTable)) return false;
return this.forfeitPlayer(this.playerTable[user], message);
}
/**
@ -966,7 +966,7 @@ class RoomBattle extends RoomGames.RoomGame {
}
makePlayer(/** @type {User} */ user) {
const num = this.playerList.length + 1;
const num = this.players.length + 1;
return new RoomBattlePlayer(user, this, num);
}
@ -999,7 +999,7 @@ class RoomBattle extends RoomGames.RoomGame {
start() {
// on start
this.started = true;
const users = this.playerList.map(player => {
const users = this.players.map(player => {
const user = player.getUser();
if (!user) throw new Error(`User ${player.name} not found on ${this.id} battle creation`);
return user;
@ -1021,11 +1021,11 @@ class RoomBattle extends RoomGames.RoomGame {
}
clearPlayers() {
for (const player of this.playerList) {
for (const player of this.players) {
player.destroy();
}
this.players = {};
this.playerList = [];
this.playerTable = {};
this.players = [];
// @ts-ignore
this.p1 = null;
// @ts-ignore

View File

@ -102,9 +102,9 @@ class RoomGame {
*
* @type {{[userid: string]: RoomGamePlayer}}
*/
this.players = Object.create(null);
this.playerTable = Object.create(null);
/** @type {RoomGamePlayer[]} */
this.playerList = [];
this.players = [];
this.playerCount = 0;
this.playerCap = 0;
this.ended = false;
@ -115,13 +115,13 @@ class RoomGame {
destroy() {
this.room.game = null;
this.room = /** @type {any} */ (null);
for (const player of this.playerList) {
for (const player of this.players) {
player.destroy();
}
// @ts-ignore
this.playerList = null;
// @ts-ignore
this.players = null;
// @ts-ignore
this.playerTable = null;
}
/**
@ -130,15 +130,15 @@ class RoomGame {
*/
addPlayer(user = null, ...rest) {
if (typeof user !== 'string' && user) {
if (user.userid in this.players) return null;
if (user.userid in this.playerTable) return null;
}
if (this.playerCap > 0 && this.playerCount >= this.playerCap) return null;
let player = this.makePlayer(user, ...rest);
if (!player) return null;
if (typeof user === 'string') user = null;
this.playerList.push(player);
this.players.push(player);
if (user) {
this.players[user.userid] = player;
this.playerTable[user.userid] = player;
this.playerCount++;
}
return player;
@ -151,12 +151,12 @@ class RoomGame {
updatePlayer(player, user) {
if (!this.allowRenames) return;
if (player.userid) {
delete this.players[player.userid];
delete this.playerTable[player.userid];
}
if (user) {
player.userid = user.userid;
player.name = user.name;
this.players[player.userid] = player;
this.playerTable[player.userid] = player;
this.room.auth[player.userid] = Users.PLAYER_SYMBOL;
} else {
player.userid = '';
@ -168,7 +168,7 @@ class RoomGame {
* @param {any[]} rest
*/
makePlayer(user, ...rest) {
const num = this.playerList.length ? this.playerList[this.playerList.length - 1].num : 1;
const num = this.players.length ? this.players[this.players.length - 1].num : 1;
return new RoomGamePlayer(user, this, num);
}
@ -179,14 +179,14 @@ class RoomGame {
if (player instanceof Users.User) {
// API changed
// TODO: deprecate
player = this.players[player.userid];
player = this.playerTable[player.userid];
if (!player) throw new Error("Player not found");
}
if (!this.allowRenames) return false;
const playerIndex = this.playerList.indexOf(player);
const playerIndex = this.players.indexOf(player);
if (playerIndex < 0) return false;
if (player.userid) delete this.players[player.userid];
this.playerList.splice(playerIndex, 1);
if (player.userid) delete this.playerTable[player.userid];
this.players.splice(playerIndex, 1);
player.destroy();
this.playerCount--;
return true;
@ -198,12 +198,12 @@ class RoomGame {
*/
renamePlayer(user, oldUserid) {
if (user.userid === oldUserid) {
this.players[user.userid].name = user.name;
this.playerTable[user.userid].name = user.name;
} else {
this.players[user.userid] = this.players[oldUserid];
this.players[user.userid].userid = user.userid;
this.players[user.userid].name = user.name;
delete this.players[oldUserid];
this.playerTable[user.userid] = this.playerTable[oldUserid];
this.playerTable[user.userid].userid = user.userid;
this.playerTable[user.userid].name = user.name;
delete this.playerTable[oldUserid];
}
}
@ -276,13 +276,13 @@ class RoomGame {
*/
onRename(user, oldUserid, isJoining, isForceRenamed) {
if (!this.allowRenames || (!user.named && !isForceRenamed)) {
if (!(user.userid in this.players)) {
if (!(user.userid in this.playerTable)) {
user.games.delete(this.id);
user.updateSearch();
}
return;
}
if (!(oldUserid in this.players)) return;
if (!(oldUserid in this.playerTable)) return;
this.renamePlayer(user, oldUserid);
}

View File

@ -1485,9 +1485,9 @@ class GameRoom extends BasicChatRoom {
* @param {User} user
*/
getLogForUser(user) {
if (!(user.userid in this.game.players)) return this.getLog();
if (!(user.userid in this.game.playerTable)) return this.getLog();
// @ts-ignore
return this.getLog(this.game.players[user.userid].num);
return this.getLog(this.game.playerTable[user.userid].num);
}
/**
* @param {User?} excludeUser

View File

@ -117,7 +117,7 @@ class Elimination {
this.isDrawingSupported = false;
this.isBracketFrozen = false;
/** @type {TournamentPlayer[]} */
this.playerList = [];
this.players = [];
maxSubtrees = maxSubtrees || 1;
if (typeof maxSubtrees === 'string' && maxSubtrees.toLowerCase() === 'infinity') {
@ -162,7 +162,7 @@ class Elimination {
freezeBracket(players) {
if (!players.length) throw new Error(`No players in tournament`);
this.playerList = players;
this.players = players;
this.isBracketFrozen = true;
/** @typedef {{root: ElimNode, currentLayerLeafNodes: ElimNode[], nextLayerLeafNodes: ElimNode[]}} ElimTree */
@ -358,7 +358,7 @@ class Elimination {
if (!['win', 'loss'].includes(result)) return 'InvalidMatchResult';
if (!this.playerList.includes(p1) || !this.playerList.includes(p2)) return 'UserNotAdded';
if (!this.players.includes(p1) || !this.players.includes(p2)) return 'UserNotAdded';
let targetNode = this.treeRoot.find(node => {
if (node.state === 'available' && (
@ -454,7 +454,7 @@ class Elimination {
if (!currentNode) break;
}
if (this.playerList.length - 1 === this.maxSubtrees && currentNode) {
if (this.players.length - 1 === this.maxSubtrees && currentNode) {
results.push([currentNode.user]);
}

View File

@ -14,7 +14,7 @@ class RoundRobin {
this.isDrawingSupported = true;
this.isBracketFrozen = false;
/** @type {TournamentPlayer[]} */
this.playerList = [];
this.players = [];
this.isDoubles = !!isDoubles;
/** @type {Match?[][]} */
@ -49,7 +49,7 @@ class RoundRobin {
};
}
getBracketData() {
const players = this.playerList;
const players = this.players;
return {
type: 'table',
tableHeaders: {
@ -81,7 +81,7 @@ class RoundRobin {
* @param {TournamentPlayer[]} players
*/
freezeBracket(players) {
this.playerList = players;
this.players = players;
this.isBracketFrozen = true;
this.matches = players.map((p1, row) =>
@ -108,11 +108,11 @@ class RoundRobin {
disqualifyUser(user) {
if (!this.isBracketFrozen) return 'BracketNotFrozen';
let playerIndex = this.playerList.indexOf(user);
let playerIndex = this.players.indexOf(user);
for (const [col, match] of this.matches[playerIndex].entries()) {
if (!match || match.state !== 'available') continue;
const p2 = this.playerList[col];
const p2 = this.players[col];
match.state = 'finished';
match.result = 'loss';
match.score = [0, 1];
@ -124,7 +124,7 @@ class RoundRobin {
for (const [row, challenges] of this.matches.entries()) {
let match = challenges[playerIndex];
if (!match || match.state !== 'available') continue;
const p1 = this.playerList[row];
const p1 = this.players[row];
match.state = 'finished';
match.result = 'win';
match.score = [1, 0];
@ -142,9 +142,9 @@ class RoundRobin {
/** @type {[TournamentPlayer, TournamentPlayer][]} */
let matches = [];
for (const [row, challenges] of this.matches.entries()) {
const p1 = this.playerList[row];
const p1 = this.players[row];
for (const [col, match] of challenges.entries()) {
const p2 = this.playerList[col];
const p2 = this.players[col];
if (!match) continue;
if (match.state === 'available' && !p1.isBusy && !p2.isBusy) {
matches.push([p1, p2]);
@ -163,8 +163,8 @@ class RoundRobin {
if (!['win', 'loss', 'draw'].includes(result)) return 'InvalidMatchResult';
let row = this.playerList.indexOf(p1);
let col = this.playerList.indexOf(p2);
let row = this.players.indexOf(p1);
let col = this.players.indexOf(p2);
if (row < 0 || col < 0) return 'UserNotAdded';
let match = this.matches[row][col];
@ -183,7 +183,7 @@ class RoundRobin {
getResults() {
if (!this.isTournamentEnded()) return 'TournamentNotEnded';
let sortedScores = this.playerList.sort(
let sortedScores = this.players.sort(
(p1, p2) => p1.score - p2.score
);

View File

@ -70,10 +70,10 @@ class Tournament extends Rooms.RoomGame {
// TypeScript bug: no `T extends RoomGamePlayer`
/** @type {{[userid: string]: TournamentPlayer}} */
this.players = Object.create(null);
this.playerTable = Object.create(null);
// TypeScript bug: no `T extends RoomGamePlayer`
/** @type {TournamentPlayer[]} */
this.playerList = [];
this.players = [];
this.id = room.id;
this.room = room;
@ -132,7 +132,7 @@ class Tournament extends Rooms.RoomGame {
}
getRemainingPlayers() {
return this.playerList.filter(player => !player.isDisqualified && !player.isEliminated);
return this.players.filter(player => !player.isDisqualified && !player.isEliminated);
}
/**
@ -201,7 +201,7 @@ class Tournament extends Rooms.RoomGame {
forceEnd() {
if (this.isTournamentStarted) {
if (this.autoDisqualifyTimer) clearTimeout(this.autoDisqualifyTimer);
for (const player of this.playerList) {
for (const player of this.players) {
const match = player.inProgressMatch;
if (match) {
match.room.tour = null;
@ -212,7 +212,7 @@ class Tournament extends Rooms.RoomGame {
} else if (this.autoStartTimer) {
clearTimeout(this.autoStartTimer);
}
for (const player of this.playerList) {
for (const player of this.players) {
player.unlinkUser();
}
this.room.add('|tournament|forceend');
@ -236,7 +236,7 @@ class Tournament extends Rooms.RoomGame {
);
return;
}
const isJoined = targetUser.userid in this.players;
const isJoined = targetUser.userid in this.playerTable;
/** @type {{format: string, generator: string, isStarted: boolean, isJoined: boolean, bracketData: string, teambuilderFormat?: string}} */
const update = {
format: this.format,
@ -249,12 +249,12 @@ class Tournament extends Rooms.RoomGame {
connection.sendTo(this.room, `|tournament|update|${JSON.stringify(update)}`);
if (this.isTournamentStarted && isJoined) {
const update2 = {
challenges: usersToNames(this.availableMatchesCache.challenges.get(this.players[targetUser.userid])),
challengeBys: usersToNames(this.availableMatchesCache.challengeBys.get(this.players[targetUser.userid])),
challenges: usersToNames(this.availableMatchesCache.challenges.get(this.playerTable[targetUser.userid])),
challengeBys: usersToNames(this.availableMatchesCache.challengeBys.get(this.playerTable[targetUser.userid])),
};
connection.sendTo(this.room, `|tournament|update|${JSON.stringify(update2)}`);
const pendingChallenge = this.players[targetUser.userid].pendingChallenge;
const pendingChallenge = this.playerTable[targetUser.userid].pendingChallenge;
if (pendingChallenge) {
if (pendingChallenge.to) {
connection.sendTo(this.room, `|tournament|update|${JSON.stringify({challenging: pendingChallenge.to.name})}`);
@ -310,9 +310,9 @@ class Tournament extends Rooms.RoomGame {
*/
removeBannedUser(userid) {
userid = toId(userid);
if (!(userid in this.players)) return;
if (!(userid in this.playerTable)) return;
if (this.isTournamentStarted) {
const player = this.players[userid];
const player = this.playerTable[userid];
if (!player.isDisqualified) {
this.disqualifyUser(userid);
}
@ -333,7 +333,7 @@ class Tournament extends Rooms.RoomGame {
return;
}
if (user.userid in this.players) {
if (user.userid in this.playerTable) {
output.sendReply('|tournament|error|UserAlreadyAdded');
return;
}
@ -355,7 +355,7 @@ class Tournament extends Rooms.RoomGame {
}
if (!isAllowAlts) {
for (let otherPlayer of this.playerList) {
for (let otherPlayer of this.players) {
if (!otherPlayer) continue;
const otherUser = Users(otherPlayer.userid);
if (otherUser && otherUser.latestIp === user.latestIp) {
@ -373,7 +373,7 @@ class Tournament extends Rooms.RoomGame {
let player = /** @type {TournamentPlayer} */ (this.addPlayer(user));
if (!player) throw new Error("Failed to add player.");
this.players[user.userid] = player;
this.playerTable[user.userid] = player;
this.playerCount++;
this.room.add(`|tournament|join|${user.name}`);
user.sendTo(this.room, '|tournament|update|{"isJoined":true}');
@ -392,7 +392,7 @@ class Tournament extends Rooms.RoomGame {
* @param {User | string | null} user
*/
makePlayer(user) {
const num = this.playerList.length ? this.playerList[this.playerList.length - 1].num : 1;
const num = this.players.length ? this.players[this.players.length - 1].num : 1;
return new TournamentPlayer(user, this, num);
}
@ -401,18 +401,18 @@ class Tournament extends Rooms.RoomGame {
* @param {CommandContext} [output]
*/
removeUser(userid, output) {
if (!(userid in this.players)) {
if (!(userid in this.playerTable)) {
if (output) output.sendReply('|tournament|error|UserNotAdded');
return;
}
const error = this.generator.removeUser(this.players[userid]);
const error = this.generator.removeUser(this.playerTable[userid]);
if (typeof error === 'string') {
if (output) output.sendReply(`|tournament|error|${error}`);
return;
}
this.players[userid].destroy();
delete this.players[userid];
this.playerTable[userid].destroy();
delete this.playerTable[userid];
this.playerCount--;
const user = Users(userid);
this.room.add(`|tournament|leave|${user ? user.name : userid}`);
@ -426,12 +426,12 @@ class Tournament extends Rooms.RoomGame {
* @param {CommandContext} output
*/
replaceUser(user, replacementUser, output) {
if (!(user.userid in this.players)) {
if (!(user.userid in this.playerTable)) {
output.sendReply('|tournament|error|UserNotAdded');
return;
}
if (replacementUser.userid in this.players) {
if (replacementUser.userid in this.playerTable) {
output.sendReply('|tournament|error|UserAlreadyAdded');
return;
}
@ -448,13 +448,13 @@ class Tournament extends Rooms.RoomGame {
getBracketData() {
let data;
if (!this.isTournamentStarted) {
data = this.generator.getPendingBracketData(this.playerList);
data = this.generator.getPendingBracketData(this.players);
} else {
data = this.generator.getBracketData();
}
if (data.type === 'tree') {
if (!data.rootNode) {
data.users = usersToNames(this.playerList);
data.users = usersToNames(this.players);
return data;
}
let queue = [data.rootNode];
@ -520,15 +520,15 @@ class Tournament extends Rooms.RoomGame {
return false;
}
if (this.playerList.length < 2) {
if (this.players.length < 2) {
output.sendReply('|tournament|error|NotEnoughUsers');
return false;
}
this.generator.freezeBracket(this.playerList);
this.generator.freezeBracket(this.players);
const now = Date.now();
for (const user of this.playerList) {
for (const user of this.players) {
user.lastActionTime = now;
}
@ -555,7 +555,7 @@ class Tournament extends Rooms.RoomGame {
/** @type {Map<TournamentPlayer, boolean>} */
const oldAvailableMatches = new Map();
for (const user of this.playerList) {
for (const user of this.players) {
challenges.set(user, []);
challengeBys.set(user, []);
@ -578,7 +578,7 @@ class Tournament extends Rooms.RoomGame {
}
const now = Date.now();
for (const player of this.playerList) {
for (const player of this.players) {
if (oldAvailableMatches.get(player)) continue;
if (player.availableMatches.size) player.lastActionTime = now;
@ -612,12 +612,12 @@ class Tournament extends Rooms.RoomGame {
return false;
}
if (!(userid in this.players)) {
if (!(userid in this.playerTable)) {
sendReply(`|tournament|error|UserNotAdded|${userid}`);
return false;
}
const player = this.players[userid];
const player = this.playerTable[userid];
if (player.isDisqualified) {
sendReply(`|tournament|error|AlreadyDisqualified|${userid}`);
return false;
@ -656,7 +656,7 @@ class Tournament extends Rooms.RoomGame {
}
let matchTo = null;
for (const playerFrom of this.playerList) {
for (const playerFrom of this.players) {
const match = playerFrom.inProgressMatch;
if (match && match.to === player) matchTo = playerFrom;
}
@ -732,7 +732,7 @@ class Tournament extends Rooms.RoomGame {
if (this.autoDisqualifyTimeout === Infinity) {
this.room.add('|tournament|autodq|off');
if (this.autoDisqualifyTimer) clearTimeout(this.autoDisqualifyTimer);
for (const player of this.playerList) player.autoDisqualifyWarned = false;
for (const player of this.players) player.autoDisqualifyWarned = false;
} else {
this.room.add(`|tournament|autodq|on|${this.autoDisqualifyTimeout}`);
if (this.isTournamentStarted) this.runAutoDisqualify();
@ -751,7 +751,7 @@ class Tournament extends Rooms.RoomGame {
if (this.autoDisqualifyTimer) clearTimeout(this.autoDisqualifyTimer);
const now = Date.now();
for (const player of this.playerList) {
for (const player of this.players) {
const time = player.lastActionTime;
let availableMatches = false;
if (player.availableMatches.size) availableMatches = true;
@ -800,18 +800,18 @@ class Tournament extends Rooms.RoomGame {
return;
}
if (!(user.userid in this.players)) {
if (!(user.userid in this.playerTable)) {
output.sendReply('|tournament|error|UserNotAdded');
return;
}
if (!(targetUserid in this.players)) {
if (!(targetUserid in this.playerTable)) {
output.sendReply('|tournament|error|InvalidMatch');
return;
}
const from = this.players[user.userid];
const to = this.players[targetUserid];
const from = this.playerTable[user.userid];
const to = this.playerTable[targetUserid];
const availableMatches = from.availableMatches;
if (!availableMatches || !availableMatches.has(to)) {
output.sendReply('|tournament|error|InvalidMatch');
@ -858,12 +858,12 @@ class Tournament extends Rooms.RoomGame {
return;
}
if (!(user.userid in this.players)) {
if (!(user.userid in this.playerTable)) {
if (output) output.sendReply('|tournament|error|UserNotAdded');
return;
}
const player = this.players[user.userid];
const player = this.playerTable[user.userid];
const challenge = player.pendingChallenge;
if (!challenge || !challenge.to) return;
@ -888,12 +888,12 @@ class Tournament extends Rooms.RoomGame {
return;
}
if (!(user.userid in this.players)) {
if (!(user.userid in this.playerTable)) {
output.sendReply('|tournament|error|UserNotAdded');
return;
}
const player = this.players[user.userid];
const player = this.playerTable[user.userid];
const challenge = player.pendingChallenge;
if (!challenge || !challenge.from) return;
@ -957,14 +957,14 @@ class Tournament extends Rooms.RoomGame {
* @param {string} oldUserid
*/
onRename(user, oldUserid) {
if (oldUserid in this.players) {
if (oldUserid in this.playerTable) {
if (user.userid === oldUserid) {
this.players[user.userid].name = user.name;
this.playerTable[user.userid].name = user.name;
} else {
this.players[user.userid] = this.players[oldUserid];
this.players[user.userid].userid = user.userid;
this.players[user.userid].name = user.name;
delete this.players[oldUserid];
this.playerTable[user.userid] = this.playerTable[oldUserid];
this.playerTable[user.userid].userid = user.userid;
this.playerTable[user.userid].name = user.name;
delete this.playerTable[oldUserid];
}
}
@ -993,9 +993,9 @@ class Tournament extends Rooms.RoomGame {
room.parent = null;
if (!room.battle) throw new Error("onBattleWin called without a battle");
const p1 = this.players[room.p1.userid];
const p2 = this.players[room.p2.userid];
const winner = this.players[winnerid];
const p1 = this.playerTable[room.p1.userid];
const p2 = this.playerTable[room.p2.userid];
const winner = this.playerTable[winnerid];
const score = room.battle.score || [0, 0];
let result = 'draw';
@ -1067,7 +1067,7 @@ class Tournament extends Rooms.RoomGame {
if (this.autoDisqualifyTimer) clearTimeout(this.autoDisqualifyTimer);
delete exports.tournaments[this.room.id];
this.room.game = null;
for (const player of this.playerList) {
for (const player of this.players) {
player.unlinkUser();
}
}

View File

@ -154,7 +154,7 @@ describe('Trivia', function () {
it('should make players leave the game', function () {
this.game.leave(this.user);
assert.strictEqual(this.game.players[this.user.userid], undefined);
assert.strictEqual(this.game.playerTable[this.user.userid], undefined);
});
it('should not make users who are not players leave the game', function () {
@ -196,7 +196,7 @@ describe('Trivia', function () {
game.phaseTimeout = null;
this.game = this.room.game = game;
this.player = this.room.game.players[this.user.userid];
this.player = this.room.game.playerTable[this.user.userid];
});
afterEach(function () {
@ -242,7 +242,7 @@ describe('Trivia', function () {
game.askQuestion();
this.game = this.room.game = game;
this.player = game.players[this.user.userid];
this.player = game.playerTable[this.user.userid];
});
afterEach(function () {
@ -306,7 +306,7 @@ describe('Trivia', function () {
game.askQuestion();
this.game = this.room.game = game;
this.player = game.players[this.user.userid];
this.player = game.playerTable[this.user.userid];
});
afterEach(function () {
@ -351,7 +351,7 @@ describe('Trivia', function () {
const hrtimeToNanoseconds = hrtime => hrtime[0] * 1e9 + hrtime[1];
let playerNs = hrtimeToNanoseconds(this.player.answeredAt);
let player2Ns = hrtimeToNanoseconds(this.game.players[this.user2.userid].answeredAt);
let player2Ns = hrtimeToNanoseconds(this.game.playerTable[this.user2.userid].answeredAt);
assert.ok(playerNs <= player2Ns);
done();
@ -381,7 +381,7 @@ describe('Trivia', function () {
game.askQuestion();
this.game = this.room.game = game;
this.player = game.players[this.user.userid];
this.player = game.playerTable[this.user.userid];
});
afterEach(function () {

View File

@ -28,8 +28,8 @@ describe('Simulator abstraction layer features', function () {
p1.forceRename("Missingno."); // Don't do this at home
room = Rooms.createBattle('', {p1, p2, p1team: packedTeam, p2team: packedTeam, allowRenames: false});
p1.resetName();
for (const player of room.battle.playerList) {
assert.strictEqual(player, room.battle.players[toId(player.name)]);
for (const player of room.battle.players) {
assert.strictEqual(player, room.battle.playerTable[toId(player.name)]);
}
});
});