mirror of
https://github.com/prosolis/gogobee.git
synced 2026-07-15 16:42:41 +00:00
Combat: guard daily-cron paths against mid-fight combat sessions
A turn-based elite/boss combat session locks the run for up to 1h and can straddle any scheduled tick. Add hasActiveCombatSession() and consult it from the morning DM, midnight idle reaper, expedition briefing/recap, and mid-day random event paths so none of them fire DMs or mutate run state into a live fight. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"gogobee/internal/db"
|
||||
@@ -256,6 +257,23 @@ func getActiveCombatSession(userID id.UserID) (*CombatSession, error) {
|
||||
return s, err
|
||||
}
|
||||
|
||||
// hasActiveCombatSession reports whether the player is currently locked into a
|
||||
// turn-based elite/boss fight. Daily-cron and periodic-ticker paths consult
|
||||
// this to avoid firing DMs or mutating run state into a live fight: an active
|
||||
// session locks the run (no `!zone advance`), so the player can't move it
|
||||
// forward and a cron path shouldn't either. The session carries a 1h TTL, so
|
||||
// the collision window is bounded — but real, since a fight can straddle any
|
||||
// scheduled tick. On a lookup error this returns false (fail-open): a missed
|
||||
// guard is a confusing DM, not corruption.
|
||||
func hasActiveCombatSession(userID id.UserID) bool {
|
||||
s, err := getActiveCombatSession(userID)
|
||||
if err != nil {
|
||||
slog.Warn("combat: cron guard failed to check active session", "user", userID, "err", err)
|
||||
return false
|
||||
}
|
||||
return s != nil
|
||||
}
|
||||
|
||||
// getCombatSession fetches by ID regardless of status. Test/admin/reaper use.
|
||||
func getCombatSession(sessionID string) (*CombatSession, error) {
|
||||
row := db.Get().QueryRow(`SELECT `+combatSessionCols+`
|
||||
|
||||
Reference in New Issue
Block a user