From 413d18d99723684f1d362b43a8e2b069ca4ab156 Mon Sep 17 00:00:00 2001 From: roberts Date: Mon, 30 Mar 2026 17:34:38 -0500 Subject: [PATCH] Fix combat spam: don't stack interrupts, 5s cooldown after combat - Don't create new combat/flee interrupt if one is already active - 5-second cooldown after combat before re-engaging - Prevents Doug from attacking dead mobs repeatedly Co-Authored-By: Claude Opus 4.6 (1M context) --- dougbot/core/brain.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dougbot/core/brain.py b/dougbot/core/brain.py index 0478d22..a567b6a 100644 --- a/dougbot/core/brain.py +++ b/dougbot/core/brain.py @@ -26,7 +26,7 @@ from dougbot.bridge.ws_client import BridgeWSClient from dougbot.bridge.protocol import ResponseMessage from dougbot.core.task_queue import ( TaskStack, PrimaryTask, SubTask, Priority, TaskStatus, - make_task, make_interrupt, + make_task, make_interrupt, TaskStatus, ) from dougbot.core.behaviors import ( NeedsSystem, GoalManager, SpatialMemory, DailyRoutine, BehaviorEngine, @@ -74,6 +74,7 @@ class DougBrain(QObject): # Action tracking self._action_sent_time = 0.0 + self._last_combat_time = 0.0 def start(self): self._running = True @@ -227,6 +228,14 @@ class DougBrain(QObject): def _check_interrupts(self): """Check for immediate threats that need a temporary interrupt.""" + # Don't stack interrupts — if already fighting/fleeing, let it finish + if self._tasks._interruption and self._tasks._interruption.status == TaskStatus.ACTIVE: + return + + # Cooldown after combat — don't re-engage for 5 seconds + if hasattr(self, '_last_combat_time') and time.time() - self._last_combat_time < 5: + return + b = self._behaviors bravery = self._traits.get("bravery", 50) @@ -243,6 +252,7 @@ class DougBrain(QObject): should_flee = (not should_fight) and (dist < 8) and (b.health < 14 or bravery < 30) if should_fight: + self._last_combat_time = time.time() self._tasks.interrupt(make_interrupt( "combat", f"Fighting {mob_type}!", "attack_nearest_hostile", {"range": 6}, timeout=12,