Adjust what rooms the players are put into and add more logs.
This commit is contained in:
parent
5adefc7df3
commit
93d7782ee8
1 changed files with 27 additions and 10 deletions
|
|
@ -79,7 +79,7 @@ const modifyPlayer = (io: Server, socket: Socket, data: UpdatePlayer): void => {
|
|||
|
||||
// The player is joining a team for the first time
|
||||
if (!data.from) {
|
||||
game.log.silly(`Client included a "to" but not a "from" property`);
|
||||
game.log.silly(`${data.name} included a "to" but not a "from" property`);
|
||||
let team = game.teams[data.to.team - 1];
|
||||
|
||||
switch (data.to.role) {
|
||||
|
|
@ -97,7 +97,8 @@ const modifyPlayer = (io: Server, socket: Socket, data: UpdatePlayer): void => {
|
|||
game.log.silly(`${player.name} became a guesser`);
|
||||
|
||||
// Move the rooms the player is in
|
||||
player.socket.join(`${game.id}:${data.to.team}:guesser`)
|
||||
player.socket.join(`${game.id}:${data.to.team}:guesser`);
|
||||
player.socket.join(`${game.id}:*:guesser`);
|
||||
break;
|
||||
case "writer":
|
||||
if (team.writer) {
|
||||
|
|
@ -111,21 +112,23 @@ const modifyPlayer = (io: Server, socket: Socket, data: UpdatePlayer): void => {
|
|||
};
|
||||
// Change team object
|
||||
team.writer = player;
|
||||
game.log.silly(`${player.name} became the writer`);
|
||||
game.log.silly(`${player.name} became the writer for team ${data.to.team}`);
|
||||
|
||||
// Move the rooms the player is in
|
||||
player.socket.join(`${game.id}:${data.to.team}:writer`);
|
||||
player.socket.join(`${game.id}:*:writer`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the player is just swapping roles on the same team
|
||||
else if (data.from.team === data.to.team) {
|
||||
game.log.silly(`Client provided "to" and "from" objects for the same team.`)
|
||||
game.log.silly(`${data.name} provided "to" and "from" objects for the same team.`)
|
||||
let team = game.teams[data.to.team - 1];
|
||||
switch (data.to.role) {
|
||||
case "guesser":
|
||||
if (team.guessers.length >= 7) {
|
||||
game.log.debug(`Game cannot have more than 7 ${conf.game.guesser_name}`);
|
||||
socket.emit(`PlayerUpdate`, {
|
||||
status: 403,
|
||||
message: `A team can't have 8 or more ${conf.game.guesser_name}`,
|
||||
|
|
@ -135,13 +138,17 @@ const modifyPlayer = (io: Server, socket: Socket, data: UpdatePlayer): void => {
|
|||
}
|
||||
team.guessers.push(player);
|
||||
team.writer = null;
|
||||
game.log.silly(`${data.name} became a guesser on team ${data.to.team}.`);
|
||||
|
||||
// Move the rooms the player is in
|
||||
player.socket.join(`${game.id}:${data.to.team}:guesser`)
|
||||
player.socket.join(`${game.id}:${data.to.team}:guesser`);
|
||||
player.socket.join(`${game.id}:*:guesser`);
|
||||
player.socket.leave(`${game.id}:${data.from.team}:writer`);
|
||||
player.socket.leave(`${game.id}:*:writer`);
|
||||
break;
|
||||
case "writer":
|
||||
if (team.writer) {
|
||||
game.log.debug(`Game cannot have more than 1 ${conf.game.writer_name}`);
|
||||
socket.emit(`PlayerUpdate`, {
|
||||
status: 403,
|
||||
message: `Someone on that team is already the ${conf.game.writer_name}`,
|
||||
|
|
@ -152,26 +159,29 @@ const modifyPlayer = (io: Server, socket: Socket, data: UpdatePlayer): void => {
|
|||
// Change team object
|
||||
team.writer = player;
|
||||
team.guessers = team.guessers.filter(x => x.socket !== socket);
|
||||
game.log.silly(`${data.name} became the writer on team ${data.to.team}`);
|
||||
|
||||
// Move the rooms the player is in
|
||||
player.socket.join(`${game.id}:${data.to.team}:writer`);
|
||||
player.socket.leave(`${game.id}:${data.from.team}:guesser`)
|
||||
player.socket.join(`${game.id}:*:writer`);
|
||||
player.socket.leave(`${game.id}:${data.from.team}:guesser`);
|
||||
player.socket.leave(`${game.id}:*:guesser`);
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
// The player is swapping roles and teams
|
||||
else {
|
||||
game.log.silly(`Client provided both "to" and "from" for different teams.`);
|
||||
game.log.silly(`${data.name} provided both "to" and "from" for different teams.`);
|
||||
let oldTeam = game.teams[data.from.team - 1];
|
||||
let newTeam = game.teams[data.to.team - 1];
|
||||
|
||||
// Add the player to the new team to make sure that it's a valid move
|
||||
switch (data.to.role) {
|
||||
case "guesser":
|
||||
|
||||
// Ensure we don't get 8 guessers
|
||||
if (newTeam.guessers.length >= 7) {
|
||||
game.log.debug(`Game cannot have 8 or more ${conf.game.guesser_name} on a team.`);
|
||||
socket.emit(`PlayerUpdate`, {
|
||||
status: 403,
|
||||
message: `Cannot have 8 players as ${conf.game.guesser_name}s on a single team.`,
|
||||
|
|
@ -179,15 +189,17 @@ const modifyPlayer = (io: Server, socket: Socket, data: UpdatePlayer): void => {
|
|||
});
|
||||
return;
|
||||
};
|
||||
game.log.silly(`${data.name} became a ${conf.game.guesser_name} on team ${data.to.team}`);
|
||||
newTeam.guessers.push(player);
|
||||
player.socket.join(`${game.id}:${data.to.team}:guesser`)
|
||||
player.socket.join(`${game.id}:*:guesser`)
|
||||
break;
|
||||
|
||||
|
||||
case "writer":
|
||||
|
||||
// Ensure we don't already have a writer
|
||||
if (newTeam.writer) {
|
||||
game.log.debug(`Game cannot have more than 1 ${conf.game.writer_name} on a team.`);
|
||||
socket.emit(`PlayerUpdate`, {
|
||||
status: 403,
|
||||
message: `Someone on that team is already the ${conf.game.writer_name}`,
|
||||
|
|
@ -196,7 +208,8 @@ const modifyPlayer = (io: Server, socket: Socket, data: UpdatePlayer): void => {
|
|||
return;
|
||||
};
|
||||
newTeam.writer = player;
|
||||
player.socket.join(`${game.id}:${data.to.team}:guesser`)
|
||||
player.socket.join(`${game.id}:${data.to.team}:writer`);
|
||||
player.socket.join(`${game.id}:*:writer`);
|
||||
break;
|
||||
};
|
||||
|
||||
|
|
@ -204,12 +217,16 @@ const modifyPlayer = (io: Server, socket: Socket, data: UpdatePlayer): void => {
|
|||
// new team
|
||||
switch (data.from.role) {
|
||||
case "guesser":
|
||||
game.log.debug(`${player.name} left the ${conf.game.guesser_name}s of team ${oldTeam.id}`);
|
||||
oldTeam.guessers = oldTeam.guessers.filter(x => x.socket !== socket);
|
||||
player.socket.leave(`${game.id}:${data.from.team}:guesser`);
|
||||
player.socket.leave(`${game.id}:*:guesser`);
|
||||
break;
|
||||
case "writer":
|
||||
game.log.debug(`${player.name} stopped being the ${conf.game.writer_name} of team ${oldTeam.id}`);
|
||||
oldTeam.writer = null;
|
||||
player.socket.leave(`${game.id}:${data.from.team}:writer`);
|
||||
player.socket.leave(`${game.id}:*:writer`);
|
||||
break;
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue