mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-04-25 15:40:31 -05:00
Trivia: Fix crash and Number mode game cap (#10753)
* Trivia: Fix crash and Number mode game cap Discussed with Trivia auth. Fixes an issue in Number mode where the game fails to end after a specified amount of questions, and fixes a crash caused by ending a game with no participation * Update server/chat-plugins/trivia/trivia.ts Co-authored-by: Kris Johnson <11083252+KrisXV@users.noreply.github.com> --------- Co-authored-by: Kris Johnson <11083252+KrisXV@users.noreply.github.com>
This commit is contained in:
parent
b790eb8309
commit
69eac3893e
|
|
@ -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}.`;
|
||||
|
|
@ -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 (const [i, winner] of winners.entries()) {
|
||||
message += winnerParts[i](winner);
|
||||
}
|
||||
} 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}`;
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user