fix(complement-race): add missing AI commentary cooldown updates
Fixed critical bug where AI racers would spam speech bubbles every 200ms instead of respecting the 2-6 second cooldown between comments. Issue: The TRIGGER_AI_COMMENTARY action was only updating activeSpeechBubbles but not updating the AI racer's lastComment timestamp and cooldown value. This caused getAICommentary() cooldown check to always pass since lastComment stayed at 0. Fix: Added setClientAIRacers() call to update racer.lastComment and racer.commentCooldown (random 2-6 seconds) when commentary is triggered, matching the pattern from the original single-player version. Impact: - AI commentary now properly throttled (one comment per 2-6 seconds) - Speech bubbles readable instead of rapidly changing - Matches original solo game behavior Provider.tsx:803-814 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -800,6 +800,18 @@ export function ComplementRaceProvider({ children }: { children: ReactNode }) {
|
||||
newBubbles.set(action.racerId, action.message)
|
||||
return { ...prev, activeSpeechBubbles: newBubbles }
|
||||
})
|
||||
// Update racer's lastComment time and cooldown to prevent spam
|
||||
setClientAIRacers((prevRacers) =>
|
||||
prevRacers.map((racer) =>
|
||||
racer.id === action.racerId
|
||||
? {
|
||||
...racer,
|
||||
lastComment: Date.now(),
|
||||
commentCooldown: Math.random() * 4000 + 2000, // 2-6 seconds
|
||||
}
|
||||
: racer
|
||||
)
|
||||
)
|
||||
break
|
||||
}
|
||||
case 'CLEAR_AI_COMMENT': {
|
||||
|
||||
Reference in New Issue
Block a user