diff --git a/src/structures/game_session.ts b/src/structures/game_session.ts index 4d0d58c96..ccad92fba 100644 --- a/src/structures/game_session.ts +++ b/src/structures/game_session.ts @@ -505,11 +505,13 @@ export default class GameSession extends Session { this.scoreboard.getPlayerIDs().map(async (participant) => { await this.ensurePlayerStat(participant); await GameSession.incrementPlayerGamesPlayed(participant); - const playerScore = this.scoreboard.getPlayerScore(participant); - if (playerScore > 0) { + const playerCorrectGuessCount = + this.scoreboard.getPlayerCorrectGuessCount(participant); + + if (playerCorrectGuessCount > 0) { await GameSession.incrementPlayerSongsGuessed( participant, - 1, + playerCorrectGuessCount, ); } @@ -527,6 +529,8 @@ export default class GameSession extends Session { } } + const playerScore = this.scoreboard.getPlayerScore(participant); + await GameSession.insertPerSessionStats( participant, playerScore, diff --git a/src/structures/player.ts b/src/structures/player.ts index 86de391c5..b46acaef0 100644 --- a/src/structures/player.ts +++ b/src/structures/player.ts @@ -23,6 +23,9 @@ export default class Player { /** The player's current score */ protected score: number; + /** The number of correct guesses the player has made */ + private correctGuessCount: number; + /** The player's avatar URL */ private readonly avatarURL: string | null; @@ -48,6 +51,7 @@ export default class Player { this.guildID = guildID; this.avatarURL = avatarURL; this.score = points; + this.correctGuessCount = 0; this.username = username; this.firstGameOfTheDay = firstGameOfTheDay; this.premium = premium; @@ -120,6 +124,11 @@ export default class Player { return this.score; } + /** @returns how many correct guesses the player has made */ + getCorrectGuessCount(): number { + return this.correctGuessCount; + } + /* * @param boldScore - whether to display the score in bold * @returns what to display as the score in the scoreboard for the player @@ -152,6 +161,13 @@ export default class Player { this.score += pointsEarned; } + /** + * Increments the player's correct guess count by 1 + */ + incrementCorrectGuessCount(): void { + this.correctGuessCount += 1; + } + /** * Increment the player's EXP gain by the specified amount * @param expGain - The amount of EXP that was gained diff --git a/src/structures/scoreboard.ts b/src/structures/scoreboard.ts index 5b2abefdd..6af263692 100644 --- a/src/structures/scoreboard.ts +++ b/src/structures/scoreboard.ts @@ -103,9 +103,10 @@ export default class Scoreboard { guessResult.pointsEarned, ); + this.players[guessResult.userID].incrementCorrectGuessCount(); this.players[guessResult.userID].incrementExp(guessResult.expGain); - const winnerScore = this.players[guessResult.userID].getScore(); + const winnerScore = this.players[guessResult.userID].getScore(); if (winnerScore === this.highestScore) { // If user is tied for first, add them to the first place array this.firstPlace.push(this.players[guessResult.userID]); @@ -158,6 +159,14 @@ export default class Scoreboard { return this.players[userID]?.getExpGain() ?? 0; } + /** + * @param userID - The Discord user ID of the player to check + * @returns the number of correct guesses by the player + */ + getPlayerCorrectGuessCount(userID: string): number { + return this.players[userID]?.getCorrectGuessCount() ?? 0; + } + /** * @param guildPreference - The GuildPreference * @returns whether the game has completed