Skip to content

Commit 69bd7f7

Browse files
authored
Merge branch 'main' into leaderboards
2 parents fe5615f + d4e0964 commit 69bd7f7

File tree

5 files changed

+191
-91
lines changed

5 files changed

+191
-91
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/execution/nation/NationEmojiBehavior.ts

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
Player,
77
PlayerType,
88
Relation,
9-
Team,
109
Tick,
1110
} from "../../game/Game";
1211
import { PseudoRandom } from "../../PseudoRandom";
@@ -55,6 +54,8 @@ export class NationEmojiBehavior {
5554
) {}
5655

5756
maybeSendCasualEmoji() {
57+
if (this.gameOver) return;
58+
5859
this.checkOverwhelmedByAttacks();
5960
this.checkVerySmallAttack();
6061
this.congratulateWinner();
@@ -107,60 +108,23 @@ export class NationEmojiBehavior {
107108

108109
// Check if game is over - send congratulations
109110
private congratulateWinner(): void {
110-
if (this.gameOver) return;
111+
const winner = this.game.getWinner();
112+
if (winner === null) return;
113+
114+
this.gameOver = true;
111115

112-
const percentToWin = this.game.config().percentageTilesOwnedToWin();
113-
const numTilesWithoutFallout =
114-
this.game.numLandTiles() - this.game.numTilesWithFallout();
115116
const isTeamGame =
116117
this.game.config().gameConfig().gameMode === GameMode.Team;
117118

118119
if (isTeamGame) {
119120
// Team game: all nations congratulate if another team won
120-
const teamToTiles = new Map<Team, number>();
121-
for (const player of this.game.players()) {
122-
const team = player.team();
123-
if (team === null) continue;
124-
teamToTiles.set(
125-
team,
126-
(teamToTiles.get(team) ?? 0) + player.numTilesOwned(),
127-
);
128-
}
129-
130-
const sorted = Array.from(teamToTiles.entries()).sort(
131-
(a, b) => b[1] - a[1],
132-
);
133-
if (sorted.length === 0) return;
134-
135-
const [winningTeam, winningTiles] = sorted[0];
136-
const winningPercent = (winningTiles / numTilesWithoutFallout) * 100;
137-
if (winningPercent < percentToWin) return;
138-
139-
this.gameOver = true;
140-
141121
// Don't congratulate if it's our own team
142-
if (winningTeam === this.player.team()) return;
122+
if (winner === this.player.team()) return;
143123

144124
this.sendEmoji(AllPlayers, EMOJI_CONGRATULATE);
145125
} else {
146126
// FFA game: The largest nation congratulates if a human player won
147-
const sorted = this.game
148-
.players()
149-
.sort((a, b) => b.numTilesOwned() - a.numTilesOwned());
150-
151-
if (sorted.length === 0) return;
152-
153-
const firstPlace = sorted[0];
154-
155-
// Check if first place has won (crossed the win threshold)
156-
const firstPlacePercent =
157-
(firstPlace.numTilesOwned() / numTilesWithoutFallout) * 100;
158-
if (firstPlacePercent < percentToWin) return;
159-
160-
this.gameOver = true;
161-
162-
// Only send if first place is a human
163-
if (firstPlace.type() !== PlayerType.Human) return;
127+
if (typeof winner === "string") return; // It's a team, not a player
164128

165129
// Only the largest nation sends the congratulation
166130
const largestNation = this.game
@@ -169,13 +133,12 @@ export class NationEmojiBehavior {
169133
.sort((a, b) => b.numTilesOwned() - a.numTilesOwned())[0];
170134
if (largestNation !== this.player) return;
171135

172-
this.sendEmoji(firstPlace, EMOJI_CONGRATULATE);
136+
this.sendEmoji(winner, EMOJI_CONGRATULATE);
173137
}
174138
}
175139

176140
// Brag with our crown
177141
private brag(): void {
178-
if (this.gameOver) return;
179142
if (!this.random.chance(300)) return;
180143

181144
const sorted = this.game

0 commit comments

Comments
 (0)