Skip to content

Commit

Permalink
Fix bug where first game of day bonus wasn't applied (#1239)
Browse files Browse the repository at this point in the history
* Fix bug where first game of day bonus wasn't applied

* Update src/structures/game_session.ts

Co-authored-by: Brian Le <brainicism@gmail.com>

* Remove maps, make syncAllVoiceMembers async

Co-authored-by: Brian Le <brainicism@gmail.com>
  • Loading branch information
taahamahdi and Brainicism authored Mar 7, 2022
1 parent 514400c commit 806e03f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/events/client/voiceChannelSwitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default async function voiceChannelSwitchHandler(

if (!gameSession.finished) {
if (member.id !== process.env.BOT_CLIENT_ID) {
gameSession.setPlayerInVC(
await gameSession.setPlayerInVC(
member.id,
newChannel.id === gameSession.voiceChannelID
);
Expand Down
47 changes: 28 additions & 19 deletions src/structures/game_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
getLocalizedArtistName,
getLocalizedSongName,
getMultipleChoiceOptions,
isFirstGameOfDay,
userBonusIsActive,
} from "../helpers/game_utils";
import {
Expand Down Expand Up @@ -1170,7 +1171,7 @@ export default class GameSession {
* @param userID - The Discord user ID of the player to update
* @param inVC - Whether the player is currently in the voice channel
*/
setPlayerInVC(userID: string, inVC: boolean): void {
async setPlayerInVC(userID: string, inVC: boolean): Promise<void> {
if (
inVC &&
!this.scoreboard.getPlayerIDs().includes(userID) &&
Expand All @@ -1182,9 +1183,14 @@ export default class GameSession {
userID,
(
this.scoreboard as EliminationScoreboard
).getLivesOfWeakestPlayer()
).getLivesOfWeakestPlayer(),
await isFirstGameOfDay(userID)
)
: Player.fromUserID(
userID,
0,
await isFirstGameOfDay(userID)
)
: Player.fromUserID(userID)
);
}

Expand All @@ -1194,34 +1200,37 @@ export default class GameSession {
/**
* Add all players in VC that aren't tracked to the scoreboard, and update those who left
*/
syncAllVoiceMembers(): void {
async syncAllVoiceMembers(): Promise<void> {
const currentVoiceMembers = getCurrentVoiceMembers(
this.voiceChannelID
).map((x) => x.id);

this.scoreboard
for (const player of this.scoreboard
.getPlayerIDs()
.filter((x) => !currentVoiceMembers.includes(x))
.map((x) => this.setPlayerInVC(x, false));
.filter((x) => !currentVoiceMembers.includes(x))) {
await this.setPlayerInVC(player, false);
}

if (this.gameType === GameType.TEAMS) {
// Players join teams manually with ,join
return;
}

currentVoiceMembers
.filter((x) => x !== process.env.BOT_CLIENT_ID)
.map((x) =>
this.scoreboard.addPlayer(
this.gameType === GameType.ELIMINATION
? EliminationPlayer.fromUserID(
x,
(this.scoreboard as EliminationScoreboard)
.startingLives
)
: Player.fromUserID(x)
)
for (const player of currentVoiceMembers.filter(
(x) => x !== process.env.BOT_CLIENT_ID
)) {
const firstGameOfDay = await isFirstGameOfDay(player);
this.scoreboard.addPlayer(
this.gameType === GameType.ELIMINATION
? EliminationPlayer.fromUserID(
player,
(this.scoreboard as EliminationScoreboard)
.startingLives,
firstGameOfDay
)
: Player.fromUserID(player, 0, firstGameOfDay)
);
}
}

/**
Expand Down

0 comments on commit 806e03f

Please sign in to comment.