combat testing and polishing in the dev console, many bug fixes

This commit is contained in:
2025-11-27 20:37:53 -06:00
parent 94c4ca9e95
commit dd92cf5991
45 changed files with 8157 additions and 1106 deletions

View File

@@ -349,14 +349,32 @@ class CombatEncounter:
return None
def advance_turn(self) -> None:
"""Advance to the next combatant's turn."""
self.current_turn_index += 1
"""Advance to the next alive combatant's turn, skipping dead combatants."""
# Track starting position to detect full cycle
start_index = self.current_turn_index
rounds_advanced = 0
# If we've cycled through all combatants, start a new round
if self.current_turn_index >= len(self.turn_order):
self.current_turn_index = 0
self.round_number += 1
self.log_action("round_start", None, f"Round {self.round_number} begins")
while True:
self.current_turn_index += 1
# If we've cycled through all combatants, start a new round
if self.current_turn_index >= len(self.turn_order):
self.current_turn_index = 0
self.round_number += 1
rounds_advanced += 1
self.log_action("round_start", None, f"Round {self.round_number} begins")
# Get the current combatant
current = self.get_current_combatant()
# If combatant is alive, their turn starts
if current and current.is_alive():
break
# Safety check: if we've gone through all combatants twice without finding
# someone alive, break to avoid infinite loop (combat should end)
if rounds_advanced >= 2:
break
def start_turn(self) -> List[Dict[str, Any]]:
"""

View File

@@ -167,7 +167,8 @@ class GameSession:
user_id: Owner of the session
party_member_ids: Character IDs in this party (multiplayer only)
config: Session configuration settings
combat_encounter: Current combat (None if not in combat)
combat_encounter: Legacy inline combat data (None if not in combat)
active_combat_encounter_id: Reference to combat_encounters table (new system)
conversation_history: Turn-by-turn log of actions and DM responses
game_state: Current world/quest state
turn_order: Character turn order
@@ -184,7 +185,8 @@ class GameSession:
user_id: str = ""
party_member_ids: List[str] = field(default_factory=list)
config: SessionConfig = field(default_factory=SessionConfig)
combat_encounter: Optional[CombatEncounter] = None
combat_encounter: Optional[CombatEncounter] = None # Legacy: inline combat data
active_combat_encounter_id: Optional[str] = None # New: reference to combat_encounters table
conversation_history: List[ConversationEntry] = field(default_factory=list)
game_state: GameState = field(default_factory=GameState)
turn_order: List[str] = field(default_factory=list)
@@ -202,8 +204,13 @@ class GameSession:
self.last_activity = datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
def is_in_combat(self) -> bool:
"""Check if session is currently in combat."""
return self.combat_encounter is not None
"""
Check if session is currently in combat.
Checks both the new database reference and legacy inline storage
for backward compatibility.
"""
return self.active_combat_encounter_id is not None or self.combat_encounter is not None
def start_combat(self, encounter: CombatEncounter) -> None:
"""
@@ -341,6 +348,7 @@ class GameSession:
"party_member_ids": self.party_member_ids,
"config": self.config.to_dict(),
"combat_encounter": self.combat_encounter.to_dict() if self.combat_encounter else None,
"active_combat_encounter_id": self.active_combat_encounter_id,
"conversation_history": [entry.to_dict() for entry in self.conversation_history],
"game_state": self.game_state.to_dict(),
"turn_order": self.turn_order,
@@ -382,6 +390,7 @@ class GameSession:
party_member_ids=data.get("party_member_ids", []),
config=config,
combat_encounter=combat_encounter,
active_combat_encounter_id=data.get("active_combat_encounter_id"),
conversation_history=conversation_history,
game_state=game_state,
turn_order=data.get("turn_order", []),