Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trivia: Fix crash and Number mode game cap #10753

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions server/chat-plugins/trivia/trivia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ export class Trivia extends Rooms.RoomGame<TriviaPlayer> {
const prizes = this.getPrizes();
const [p1, p2, p3] = winners;

if (!p1) return `No winners this game!`;
let initialPart = this.room.tr`${Utils.escapeHTML(p1.name)} won the game with a final score of <strong>${p1.player.points}</strong>`;
if (!this.game.givesPoints) {
return `${initialPart}.`;
Expand All @@ -847,18 +848,25 @@ export class Trivia extends Rooms.RoomGame<TriviaPlayer> {

getStaffEndMessage(winners: TopPlayer[], mapper: (k: TopPlayer) => string) {
let message = "";
const winnerParts: ((k: TopPlayer) => string)[] = [
winner => this.room.tr`User ${mapper(winner)} won the game of ` +
if (winners.length) {
const winnerParts: ((k: TopPlayer) => string)[] = [
winner => this.room.tr`User ${mapper(winner)} won the game of ` +
(this.game.givesPoints ? this.room.tr`ranked ` : this.room.tr`unranked `) +
this.room.tr`${this.game.mode} mode trivia under the ${this.game.category} category with ` +
this.room.tr`a cap of ${this.getDisplayableCap()} ` +
this.room.tr`with ${winner.player.points} points and ` +
this.room.tr`${winner.player.correctAnswers} correct answers`,
winner => this.room.tr` Second place: ${mapper(winner)} (${winner.player.points} points)`,
winner => this.room.tr`, third place: ${mapper(winner)} (${winner.player.points} points)`,
];
for (let i = 0; i < winners.length; i++) {
message += winnerParts[i](winners[i]);
}
dot-Comfey marked this conversation as resolved.
Show resolved Hide resolved
} else {
message = `No participants in the game of ` +
(this.game.givesPoints ? this.room.tr`ranked ` : this.room.tr`unranked `) +
this.room.tr`${this.game.mode} mode trivia under the ${this.game.category} category with ` +
this.room.tr`a cap of ${this.getDisplayableCap()} ` +
this.room.tr`with ${winner.player.points} points and ` +
this.room.tr`${winner.player.correctAnswers} correct answers`,
winner => this.room.tr` Second place: ${mapper(winner)} (${winner.player.points} points)`,
winner => this.room.tr`, third place: ${mapper(winner)} (${winner.player.points} points)`,
];
for (let i = 0; i < winners.length; i++) {
message += winnerParts[i](winners[i]);
this.room.tr`a cap of ${this.getDisplayableCap()}`;
}
return `${message}`;
}
Expand Down Expand Up @@ -1088,11 +1096,9 @@ export class NumberModeTrivia extends Trivia {
);

const points = this.calculatePoints(innerBuffer.length);
let winner = false;
const cap = this.getCap();
let winner = cap.questions && this.questionNumber >= cap.questions;
if (points) {
const cap = this.getCap();
// We add 1 questionNumber because it starts at 0
winner = !!cap.questions && this.questionNumber >= cap.questions;
for (const userid in this.playerTable) {
const player = this.playerTable[userid];
if (player.isCorrect) player.incrementPoints(points, this.questionNumber);
Expand Down
Loading