From b218163c29fe1a7fc6a84f5616346f8cee43de30 Mon Sep 17 00:00:00 2001 From: PartMan Date: Tue, 4 Jun 2024 10:21:04 +0530 Subject: [PATCH] Scavengers: Fix lint issues --- server/chat-plugins/scavenger-games.ts | 43 ++++++++++++++------------ 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/server/chat-plugins/scavenger-games.ts b/server/chat-plugins/scavenger-games.ts index 3e6c20dfd40db..8e92e700ca52c 100644 --- a/server/chat-plugins/scavenger-games.ts +++ b/server/chat-plugins/scavenger-games.ts @@ -7,7 +7,7 @@ * @license MIT license */ -import {ScavengerHunt, ScavengerHuntPlayer, ScavengerHuntFinish} from './scavengers'; +import {ScavengerHunt, ScavengerHuntPlayer as Scavenger, ScavengerHuntFinish} from './scavengers'; import {Utils} from '../../lib'; namespace Twists { @@ -47,13 +47,13 @@ namespace Twists { guesses: {[playerId: string]: Set}[]; } - export interface PerfectScorePlayer extends ScavengerHuntPlayer { + export interface PerfectScorePlayer extends Scavenger { answers: Record; } - export interface BonusRoundPlayer extends ScavengerHuntPlayer { + export interface BonusRoundPlayer extends Scavenger { skippedQuestion: boolean; } - export interface BlindIncognitoPlayer extends ScavengerHuntPlayer { + export interface BlindIncognitoPlayer extends Scavenger { preCompleted?: boolean; } } @@ -248,7 +248,7 @@ const TWISTS: TwistCollection = { id: 'incognito', desc: "Upon answering the last question correctly, the player's finishing time will not be announced in the room! Results will only be known at the end of the hunt.", - onCorrectAnswer(player: ScavengerHuntPlayer, value: string) { + onCorrectAnswer(player: Scavenger, value: string) { if (player.currentQuestion + 1 >= this.questions.length) { this.runEvent('PreComplete', player); @@ -258,7 +258,7 @@ const TWISTS: TwistCollection = { } }, - onPreComplete(player: ScavengerHuntPlayer) { + onPreComplete(player: Scavenger) { const now = Date.now(); const time = Chat.toDurationString(now - this.startTime, {hhmmss: true}); const canBlitz = this.completed.length < 3; @@ -266,7 +266,8 @@ const TWISTS: TwistCollection = { const blitz = now - this.startTime <= 60000 && canBlitz && (this.room.settings.scavSettings?.blitzPoints?.[this.gameType] || this.gameType === 'official'); - const result: ScavengerHuntFinish = this.runEvent('Complete', player, time, blitz) || {name: player.name, id: player.id, time, blitz}; + const fallbackResult = {name: player.name, id: player.id, time, blitz}; + const result: ScavengerHuntFinish = this.runEvent('Complete', player, time, blitz) || fallbackResult; this.preCompleted = this.preCompleted ? [...this.preCompleted, result] : [result]; player.completed = true; @@ -284,7 +285,7 @@ const TWISTS: TwistCollection = { desc: 'Every wrong answer adds 30 seconds to your final time!', - onIncorrectAnswer(player: ScavengerHuntPlayer, value: string) { + onIncorrectAnswer(player: Scavenger, value: string) { if (!player.incorrect) player.incorrect = []; const id = `${player.currentQuestion}-${value}`; if (player.incorrect.includes(id)) return; @@ -292,7 +293,7 @@ const TWISTS: TwistCollection = { player.incorrect.push(id); }, - onComplete(player: ScavengerHuntPlayer, time: string, blitz: boolean) { + onComplete(player: Scavenger, time: string, blitz: boolean) { const seconds = toSeconds(time); if (!player.incorrect) return {name: player.name, id: player.id, total: seconds, blitz, time}; @@ -303,7 +304,8 @@ const TWISTS: TwistCollection = { return {name: player.name, id: player.id, total, blitz, time: finalTime}; }, - onConfirmCompletion(player: ScavengerHuntPlayer, _time: string, _blitz: boolean, place: string, {blitz, time}: ScavengerHuntFinish) { + onConfirmCompletion(player: Scavenger, _time: string, _blitz: boolean, place: string, result: ScavengerHuntFinish) { + const {blitz, time} = result; const deductionMessage = player.incorrect?.length ? Chat.count(player.incorrect, 'incorrect guesses', 'incorrect guess') : "Perfect!"; @@ -351,7 +353,8 @@ const TWISTS: TwistCollection = { const blitz = now - this.startTime <= 60000 && canBlitz && (this.room.settings.scavSettings?.blitzPoints?.[this.gameType] || this.gameType === 'official'); - const result: ScavengerHuntFinish = this.runEvent('Complete', player, time, blitz) || {name: player.name, id: player.id, time, blitz}; + const fallbackResult = {name: player.name, id: player.id, time, blitz}; + const result: ScavengerHuntFinish = this.runEvent('Complete', player, time, blitz) || fallbackResult; this.preCompleted = this.preCompleted ? [...this.preCompleted, result] : [result]; player.preCompleted = true; @@ -378,7 +381,7 @@ const TWISTS: TwistCollection = { this.startTimes = {}; }, - onJoin(user: ScavengerHuntPlayer & User) { + onJoin(user: Scavenger & User) { if (!Config.noipchecks) { const altIp = user.ips.find(ip => this.altIps[ip] && this.joinedIps.includes(user.id)); if (altIp) { @@ -398,13 +401,13 @@ const TWISTS: TwistCollection = { return true; }, - onLeave(player: ScavengerHuntPlayer) { + onLeave(player: Scavenger) { for (const ip of player.joinIps) { this.altIps[ip] = {id: player.id, name: player.name}; } }, - onComplete(player: ScavengerHuntPlayer, time: string, blitz: boolean) { + onComplete(player: Scavenger, time: string, blitz: boolean) { const now = Date.now(); const takenTime = Chat.toDurationString(now - this.startTimes[player.id], {hhmmss: true}); const result = {name: player.name, id: player.id, time: takenTime, blitz}; @@ -436,7 +439,7 @@ const TWISTS: TwistCollection = { }); }, - onIncorrectAnswer(player: ScavengerHuntPlayer, value: string) { + onIncorrectAnswer(player: Scavenger, value: string) { const curr = player.currentQuestion; if (!this.incorrect[curr][value]) this.incorrect[curr][value] = new Set(); @@ -444,7 +447,7 @@ const TWISTS: TwistCollection = { }, onSubmitPriority: 1, - onSubmit(player: ScavengerHuntPlayer, valueToId: string, value: string) { + onSubmit(player: Scavenger, valueToId: string, value: string) { const currentQuestion = player.currentQuestion; if (currentQuestion + 1 === this.questions.length) { @@ -551,7 +554,7 @@ const TWISTS: TwistCollection = { return true; }, - onIncorrectAnswer(player: ScavengerHuntPlayer, value: string) { + onIncorrectAnswer(player: Scavenger, value: string) { const curr = player.currentQuestion; if (!this.guesses[curr][player.id]) this.guesses[curr][player.id] = new Set(); @@ -912,7 +915,7 @@ const MODES: {[k: string]: GameMode | string} = { } */ teams: {}, - teamAnnounce(player: ScavengerHuntPlayer | User, message: string) { + teamAnnounce(player: Scavenger | User, message: string) { const team = this.getPlayerTeam(player); for (const userid of team.players) { @@ -923,7 +926,7 @@ const MODES: {[k: string]: GameMode | string} = { } }, - getPlayerTeam(player: ScavengerHuntPlayer | User) { + getPlayerTeam(player: Scavenger | User) { const game = this.room.scavgame!; for (const teamID in game.teams) { const team = game.teams[teamID]; @@ -934,7 +937,7 @@ const MODES: {[k: string]: GameMode | string} = { return null; }, - advanceTeam(answerer: ScavengerHuntPlayer, isFinished?: boolean) { + advanceTeam(answerer: Scavenger, isFinished?: boolean) { const hunt = this.room.getGame(ScavengerHunt)!; const team = this.getPlayerTeam(answerer);