diff --git a/assets/scripts/lobby/buttonEventListeners2.js b/assets/scripts/lobby/buttonEventListeners2.js
index 06985f283..87389286f 100644
--- a/assets/scripts/lobby/buttonEventListeners2.js
+++ b/assets/scripts/lobby/buttonEventListeners2.js
@@ -185,6 +185,7 @@ $('#createNewRoomButton').on('click', (data) => {
newRoomPassword: $('#newRoomPassword').val(),
gameMode: $($('.gameModeSelect')[1]).val(),
muteSpectators: $('.muteSpectators')[1].checked,
+ rebal9p: $('.rebal9p')[1].checked,
ranked: $($('.rankedSelect')[1]).val(),
};
@@ -192,6 +193,7 @@ $('#createNewRoomButton').on('click', (data) => {
$($('.maxNumPlayers')[0]).val(sendObj.maxNumPlayers);
$($('.gameModeSelect')[0]).val(sendObj.gameMode);
$('.muteSpectators')[0].checked = sendObj.muteSpectators;
+ $('.rebal9p')[0].checked = sendObj.rebal9p;
$($('.rankedSelect')[0]).val(sendObj.ranked);
if (inRoom === false) {
diff --git a/assets/scripts/lobby/sockets/sockets.js b/assets/scripts/lobby/sockets/sockets.js
index d47faa1d2..c68dd5cbb 100644
--- a/assets/scripts/lobby/sockets/sockets.js
+++ b/assets/scripts/lobby/sockets/sockets.js
@@ -783,6 +783,13 @@ $('.muteSpectators').on('change', (e) => {
socket.emit('update-room-muteSpectators', e.target.checked);
});
+$('.rebal9p').on('change', (e) => {
+ $('.rebal9p')[0].checked = e.target.checked;
+ $('.rebal9p')[1].checked = e.target.checked;
+
+ socket.emit('update-room-rebal9p', e.target.checked);
+});
+
// Update the new room menu with the gameModes available.
socket.on('leave-room-requested', () => {
leaveRoom();
diff --git a/src/gameplay/game.ts b/src/gameplay/game.ts
index 4c9e74b20..7419093bc 100644
--- a/src/gameplay/game.ts
+++ b/src/gameplay/game.ts
@@ -46,6 +46,7 @@ function Game(
gameMode_,
muteSpectators_,
ranked_,
+ rebal9p_,
callback_,
) {
this.callback = callback_;
@@ -177,6 +178,7 @@ function Game(
this.chatHistory = []; // Here because chatHistory records after game starts
this.muteSpectators = muteSpectators_;
+ this.rebal9p = rebal9p_;
}
// Game object inherits all the functions and stuff from Room
@@ -398,6 +400,12 @@ Game.prototype.startGame = function (options) {
}
// Now we initialise roles
+ const alliances = this.alliances.concat();
+ if (this.rebal9p) {
+ // Swap last two elements of alliances array
+ [alliances[8], alliances[9]] = [alliances[9], alliances[8]];
+ }
+
for (let i = 0; i < this.socketsOfPlayers.length; i++) {
this.playersInGame[i] = {};
// assign them the sockets but with shuffled.
@@ -409,7 +417,7 @@ Game.prototype.startGame = function (options) {
// set the role to be from the roles array with index of the value
// of the rolesAssignment which has been shuffled
- this.playersInGame[i].alliance = this.alliances[rolesAssignment[i]];
+ this.playersInGame[i].alliance = alliances[rolesAssignment[i]];
this.playerUsernamesInGame.push(
this.socketsOfPlayers[i].request.user.username,
@@ -1317,6 +1325,12 @@ Game.prototype.finishGame = function (toBeWinner) {
botUsernames = [];
}
+ let gameMode = this.gameMode;
+
+ if (this.playersInGame.length === 9 && this.rebal9p) {
+ gameMode = 'avalonCustom';
+ }
+
const objectToStore = {
timeGameStarted: this.startGameTime,
timeAssassinationStarted: this.startAssassinationTime,
@@ -1326,8 +1340,9 @@ Game.prototype.finishGame = function (toBeWinner) {
resistanceTeam: this.resistanceUsernames,
numberOfPlayers: this.playersInGame.length,
- gameMode: this.gameMode,
+ gameMode,
botUsernames,
+ rebal9p: this.rebal9p,
playerUsernamesOrdered: getUsernamesOfPlayersInGame(this),
playerUsernamesOrderedReversed: gameReverseArray(
@@ -1901,6 +1916,16 @@ Game.prototype.updateMuteSpectators = function (muteSpectators: boolean) {
);
};
+Game.prototype.updateRebal9p = function (rebal9p: boolean) {
+ this.rebal9p = rebal9p;
+
+ this.sendText(
+ this.allSockets,
+ `Rebalanced 9p option set to ${rebal9p}.`,
+ 'server-text'
+ );
+};
+
/*
ELO RATING CALCULATION:
diff --git a/src/gameplay/gameWrapper.js b/src/gameplay/gameWrapper.js
index aa9849beb..dfc12ffae 100644
--- a/src/gameplay/gameWrapper.js
+++ b/src/gameplay/gameWrapper.js
@@ -11,6 +11,7 @@ function GameWrapper(
muteSpectators_,
gameMode_,
ranked_,
+ rebal9p_,
callback_,
) {
// Get all the game properties
@@ -24,6 +25,7 @@ function GameWrapper(
muteSpectators_,
gameMode_,
ranked_,
+ rebal9p_,
callback_,
);
}
diff --git a/src/gameplay/playersReadyNotReady.js b/src/gameplay/playersReadyNotReady.js
index b09ee9e32..3a6c96ac3 100644
--- a/src/gameplay/playersReadyNotReady.js
+++ b/src/gameplay/playersReadyNotReady.js
@@ -144,6 +144,7 @@ playersReadyNotReady.prototype.hostTryStartGame = function (options, gameMode) {
rolesInStr += `
Ranked: ${this.ranked}`;
rolesInStr += `
Mute Spectators: ${this.muteSpectators}`;
+ rolesInStr += `
Rebalanced 9p: ${this.rebal9p}`;
for (let i = 0; i < this.socketsOfPlayers.length; i++) {
this.socketsOfPlayers[i].emit('game-starting', rolesInStr, gameMode);
diff --git a/src/models/gameRecord.js b/src/models/gameRecord.js
index 788b36326..3d821da21 100644
--- a/src/models/gameRecord.js
+++ b/src/models/gameRecord.js
@@ -9,6 +9,7 @@ const gameRecordSchema = new mongoose.Schema({
spyTeam: [String],
resistanceTeam: [String],
+ rebal9p: Boolean,
gameMode: String,
botUsernames: [String],
diff --git a/src/sockets/sockets.ts b/src/sockets/sockets.ts
index 6e2e330b7..ddcb81300 100644
--- a/src/sockets/sockets.ts
+++ b/src/sockets/sockets.ts
@@ -387,6 +387,7 @@ export let modCommands = {
dataObj.gameMode,
dataObj.muteSpectators,
false,
+ false,
socketCallback,
);
const privateStr = dataObj.newRoomPassword === '' ? '' : 'private ';
@@ -2126,6 +2127,7 @@ export const server = function (io: SocketServer): void {
socket.on('update-room-game-mode', updateRoomGameMode);
socket.on('update-room-ranked', updateRoomRanked);
socket.on('update-room-muteSpectators', updateRoomMuteSpectators);
+ socket.on('update-room-rebal9p', updateRoomRebal9p);
//* ***********************
// game data stuff
@@ -2762,6 +2764,7 @@ function newRoom(dataObj) {
dataObj.gameMode,
dataObj.muteSpectators,
rankedRoom,
+ dataObj.rebal9p,
socketCallback,
);
const privateStr = !privateRoom ? '' : 'private ';
@@ -2984,6 +2987,12 @@ function updateRoomMuteSpectators(muteSpectators) {
}
}
+function updateRoomRebal9p(rebal9p) {
+ if (rooms[this.request.user.inRoomId]) {
+ rooms[this.request.user.inRoomId].updateRebal9p(rebal9p);
+ }
+}
+
function updateRoomMaxPlayers(number) {
if (rooms[this.request.user.inRoomId]) {
rooms[this.request.user.inRoomId].updateMaxNumPlayers(this, number);
diff --git a/src/views/lobby.ejs b/src/views/lobby.ejs
index 1d0f4876e..69757d28f 100644
--- a/src/views/lobby.ejs
+++ b/src/views/lobby.ejs
@@ -970,6 +970,11 @@
+
+
+
+
+