From 9d473d136c687c7e70e2e80fed93b1dfebde5d2c Mon Sep 17 00:00:00 2001 From: Karthik Bandagonda <32044378+Karthik99999@users.noreply.github.com> Date: Sat, 12 Oct 2024 17:40:08 -0700 Subject: [PATCH] Auctions: Fix nom timer not getting reset after an undo (#10610) * Auctions: Fix nom timer not getting reset after an undo * Use functions to actually prevent crashes from ever happening --- server/chat-plugins/auction.ts | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/server/chat-plugins/auction.ts b/server/chat-plugins/auction.ts index a5398e9979de..7fca3803eac4 100644 --- a/server/chat-plugins/auction.ts +++ b/server/chat-plugins/auction.ts @@ -241,6 +241,7 @@ export class Auction extends Rooms.SimpleRoomGame { } sendBidInfo() { + if (this.type === 'blind') return; let buf = `
`; buf += Utils.html`Player: ${this.nominatedPlayer.name} `; buf += `Top bid: ${this.highestBid} `; @@ -515,10 +516,7 @@ export class Auction extends Rooms.SimpleRoomGame { } while (this.nominatingTeam.isSuspended()); this.sendHTMLBox(this.generateAuctionTable()); this.sendMessage(`/html It is now ${Utils.escapeHTML(this.nominatingTeam.name)}'s turn to nominate a player. Managers: ${this.nominatingTeam.getManagers().map(m => `${Utils.escapeHTML(m)}`).join(' ')}`); - if (this.nomTimeLimit) { - this.sendTimer(false, true); - this.nomTimer = setInterval(() => this.pokeNomTimer(), 1000); - } + this.startNomTimer(); } nominate(user: User, target: string) { @@ -551,9 +549,8 @@ export class Auction extends Rooms.SimpleRoomGame { } this.sendMessage(Utils.html`/html ${user.name} from team ${this.nominatingTeam.name} has nominated ${player.name} for auction. Use /bid or type a number to place a bid!`); - if (this.type === 'auction') this.sendBidInfo(); - this.sendTimer(); - this.bidTimer = setInterval(() => this.pokeBidTimer(), 1000); + this.sendBidInfo(); + this.startBidTimer(); } } @@ -588,10 +585,8 @@ export class Auction extends Rooms.SimpleRoomGame { this.highestBid = bid; this.highestBidder = team; this.sendMessage(Utils.html`/html ${user.name}[${team.name}]: ${bid}`); - this.clearBidTimer(); - this.bidTimer = setInterval(() => this.pokeBidTimer(), 1000); this.sendBidInfo(); - this.sendTimer(); + this.startBidTimer(); } } @@ -647,12 +642,26 @@ export class Auction extends Rooms.SimpleRoomGame { this.room.add('|uhtmlchange|timer|'); } + startNomTimer() { + if (!this.nomTimeLimit) return; + this.clearNomTimer(); + this.sendTimer(false, true); + this.nomTimer = setInterval(() => this.pokeNomTimer(), 1000); + } + clearBidTimer() { clearInterval(this.bidTimer); this.bidTimeRemaining = this.bidTimeLimit; this.room.add('|uhtmlchange|timer|'); } + startBidTimer() { + if (!this.bidTimeLimit) return; + this.clearBidTimer(); + this.sendTimer(); + this.bidTimer = setInterval(() => this.pokeBidTimer(), 1000); + } + pokeNomTimer() { this.nomTimeRemaining--; if (!this.nomTimeRemaining) {