Skip to content

Commit

Permalink
Auctions: Fix nom timer not getting reset after an undo (smogon#10610)
Browse files Browse the repository at this point in the history
* Auctions: Fix nom timer not getting reset after an undo

* Use functions to actually prevent crashes from ever happening
  • Loading branch information
Karthik99999 authored Oct 13, 2024
1 parent 451b17b commit 9d473d1
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions server/chat-plugins/auction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export class Auction extends Rooms.SimpleRoomGame {
}

sendBidInfo() {
if (this.type === 'blind') return;
let buf = `<div class="infobox">`;
buf += Utils.html`Player: <username>${this.nominatedPlayer.name}</username> `;
buf += `Top bid: <b>${this.highestBid}</b> `;
Expand Down Expand Up @@ -515,10 +516,7 @@ export class Auction extends Rooms.SimpleRoomGame {
} while (this.nominatingTeam.isSuspended());
this.sendHTMLBox(this.generateAuctionTable());
this.sendMessage(`/html It is now <b>${Utils.escapeHTML(this.nominatingTeam.name)}</b>'s turn to nominate a player. Managers: ${this.nominatingTeam.getManagers().map(m => `<username class="username">${Utils.escapeHTML(m)}</username>`).join(' ')}`);
if (this.nomTimeLimit) {
this.sendTimer(false, true);
this.nomTimer = setInterval(() => this.pokeNomTimer(), 1000);
}
this.startNomTimer();
}

nominate(user: User, target: string) {
Expand Down Expand Up @@ -551,9 +549,8 @@ export class Auction extends Rooms.SimpleRoomGame {
}

this.sendMessage(Utils.html`/html <username class="username">${user.name}</username> from team <b>${this.nominatingTeam.name}</b> has nominated <username>${player.name}</username> 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();
}
}

Expand Down Expand Up @@ -588,10 +585,8 @@ export class Auction extends Rooms.SimpleRoomGame {
this.highestBid = bid;
this.highestBidder = team;
this.sendMessage(Utils.html`/html <username class="username">${user.name}</username>[${team.name}]: <b>${bid}</b>`);
this.clearBidTimer();
this.bidTimer = setInterval(() => this.pokeBidTimer(), 1000);
this.sendBidInfo();
this.sendTimer();
this.startBidTimer();
}
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9d473d1

Please sign in to comment.