Skip to content

Commit

Permalink
Auctions: Fix edge case for removing players after an undo (smogon#10437
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Karthik99999 authored Jul 24, 2024
1 parent 59672bc commit e8361df
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions server/chat-plugins/auction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,23 @@ class Team {
}

getManagers() {
const managers = [];
for (const manager of this.auction.managers.values()) {
if (manager.team !== this) continue;
const user = Users.getExact(manager.id);
if (user) {
managers.push(user.name);
} else {
managers.push(manager.id);
}
}
return managers;
return [...this.auction.managers.values()]
.filter(m => m.team === this)
.map(m => Users.getExact(m.id)?.name || m.id);
}

addPlayer(player: Player, price = 0) {
if (player.team) player.team.removePlayer(player);
player.team?.removePlayer(player);
this.players.push(player);
this.credits -= price;
player.team = this;
player.price = price;
}

removePlayer(player: Player) {
this.players.splice(this.players.indexOf(player), 1);
const pIndex = this.players.indexOf(player);
if (pIndex === -1) return;
this.players.splice(pIndex, 1);
delete player.team;
player.price = 0;
}
Expand Down

0 comments on commit e8361df

Please sign in to comment.