Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/server/BotController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,14 @@ export class BotController {
const delay = BOT_EMOTE_DELAY_MIN + Math.random() * (BOT_EMOTE_DELAY_MAX - BOT_EMOTE_DELAY_MIN);
const botId = bot.id;
const botName = bot.name;
bot.lastEmoteTime = now;

this.pendingEmoteTimeout = setTimeout(() => {
if (this.destroyed) return;
this.pendingEmoteTimeout = null;
// Cooldown is defined between audible/visible emotes, not between the
// times they were scheduled. Random delivery delays can differ, so
// recording `now` above could let two emitted reactions land closer
// together than BOT_EMOTE_COOLDOWN_MS.
bot.lastEmoteTime = Date.now();
this.onBotEmote?.(botId, botName, reactionId);
}, delay);

Expand Down
2 changes: 2 additions & 0 deletions tests/engine/BotBrain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ describe('BotBrain', () => {
let aggChallenges = 0;
let conChallenges = 0;
const trials = 500;
const randomSpy = vi.spyOn(Math, 'random').mockImplementation(seededRandom(0xC0A9));

for (let i = 0; i < trials; i++) {
const aggResult = decide(game, 'p2', BOT_PERSONALITIES.aggressive, {
Expand All @@ -999,6 +1000,7 @@ describe('BotBrain', () => {
});
if (conResult?.type === 'challenge') conChallenges++;
}
randomSpy.mockRestore();

// Aggressive should challenge more than conservative
expect(aggChallenges).toBeGreaterThan(conChallenges);
Expand Down