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) <noreply@anthropic.com>
This commit is contained in:
roberts 2026-03-30 17:34:38 -05:00
parent 5297ac664a
commit 413d18d997

View file

@ -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,