Files
gogobee/internal/plugin/combat_reaper.go
prosolis 41adfce9f1 Expedition autopilot Phase 4 + rogue sneak attack + TwinBee voice sweep
Tedium-removal pass driven by live play feedback. Three big threads:

Expedition autopilot Phase 4 — background auto-run + harvest-until-dry:
- New expeditionAutoRunTicker walks active expeditions every 15min
  (5min tick, per-expedition CAS on new last_autorun_at column). Skips
  combat sessions, briefing/recap quiet windows, expeditions <30min old.
- Walks up to 3 rooms/tick with compact narration; suppresses DMs when
  0 rooms walked or just hitting the per-tick cap (no "stretch complete"
  filler). Player only hears from the bot when a real decision is needed.
- Compact mode: one-line combat narration for trash/elite, auto-resolves
  elite doorways via the forward-sim engine (boss still pauses). Threaded
  via new advanceOnceWithOpts → resolveRoom → resolveCombatRoom.
- Auto-harvest now grinds each Common/Uncommon node until dry (cap at 8
  attempts/visit), mirroring manual !scavenge retries. Rare+ still pauses.
- Ambient ticker: anti-repeat by Kind via new last_ambient_kind column
  (avoids two pack_rat DMs in a row when the pool only has 6 lines).
- !expedition go <n> now routes to the fork-choice handler when active +
  numeric; fork footer rewritten to suggest !expedition go instead of
  !zone go. Boss/Elite doorway: formatNextRoomMessage routes the action
  hint by next room type and autopilot loop breaks via new nextRoomType
  field so "Room X/Y — Boss" doesn't double-print with contradictory
  hints (!zone advance vs !fight).
- runAutopilotWalk extracted from expeditionCmdRun so foreground and
  background share the loop body.

Rogue Sneak Attack actually exists now:
- Audit found the rogue's "Sneak Attack" passive was AutoCritFirst +
  5% damage rider. No Nd6, ever. Phase 2 Monte Carlo masked this
  with a small flat buff; the class's defining mechanic never matched
  its tooltip or 5e identity.
- Added SneakAttackDie int to CombatModifiers, per-hit Nd6 in
  combat_primitives.go (same lane as DivineStrikePerHit). Scales with
  level: 1d6 at L1-2 ... 4d6 at L7-8 ... capped at 10d6 at L19-20.
- AutoCritFirst + 5% rider retained as bonuses on top of working sneak
  attack — preserves the opener-burst feel.
- L7 rogue expected per-hit ~8 → ~22 damage. Valdris fight math goes
  from "16 rounds to kill, die in 8" to winnable.

TwinBee voice sweep (Phase B3):
- ~530 line changes across 24 files replacing third-person "TwinBee
  notes/files/tracks/respects/..." constructions with first-person
  inside flavor string literals. Code identifiers (TwinBeeLine,
  twinBeeLine, etc.), chat-prefix labels (🎭 **TwinBee:**), item names
  (TwinBee's Bell), achievements, and game-title references in
  fun.go (Konami TwinBee ship) left intact.
- Catches a real bug: Valdris fight rendered "TwinBee marks the
  Legendary Resistance" mid-combat in third person, contradicting
  the Phase B2 convention.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 12:40:17 -07:00

99 lines
3.7 KiB
Go

package plugin
import (
"fmt"
"log/slog"
"maunium.net/go/mautrix/id"
)
// Phase 13 — turn-based combat timeout reaper.
//
// A CombatSession expires 1h after its last action (combatSessionTTL). Per the
// 2026-05-13 timeout decision, an abandoned fight is not flatly marked as a
// retreat — the reaper resumes it from persisted mid-state and auto-plays the
// rest of the fight through the same shared resolver a live !attack uses,
// landing on a real win or loss. The player is DM'd the outcome.
//
// Sessions that cannot be reconstructed (zone run deleted, enemy no longer in
// the bestiary) or that fail to converge within reaperRoundCap fall back to the
// terminal 'expired' status with no fatal-blow side effects — see
// markCombatSessionExpired.
// reaperRoundCap bounds the auto-play loop. A turn-based round always lands at
// least one damage roll eventually, so a real fight converges well within this;
// the cap only guards against a pathological non-terminating session.
const reaperRoundCap = 300
// reapExpiredCombatSessions is the timeout reaper, driven off eventTicker (one
// pass per minute). It auto-plays every stale session to a terminal status.
func (p *AdventurePlugin) reapExpiredCombatSessions() {
expired, err := listExpiredCombatSessions()
if err != nil {
slog.Error("combat: reaper failed to list expired sessions", "err", err)
return
}
for _, sess := range expired {
p.reapCombatSession(sess.UserID, sess.SessionID)
}
}
// reapCombatSession auto-plays a single stale session under the player's lock.
// It re-fetches the session after locking: the player may have finished the
// fight in the window between listing and locking, in which case there is
// nothing to do.
func (p *AdventurePlugin) reapCombatSession(userIDStr, sessionID string) {
userID := id.UserID(userIDStr)
userMu := p.advUserLock(userID)
userMu.Lock()
defer userMu.Unlock()
sess, err := getActiveCombatSession(userID)
if err != nil {
slog.Error("combat: reaper failed to reload session", "user", userID, "err", err)
return
}
// Gone, replaced, or no longer the stale one — the player acted first.
if sess == nil || sess.SessionID != sessionID {
return
}
player, enemy, err := p.combatantsForSession(sess)
if err != nil {
// Can't reconstruct the fight — park it terminal so it isn't retried
// every minute forever.
slog.Warn("combat: reaper cannot rebuild session, marking expired",
"user", userID, "session", sess.SessionID, "err", err)
if merr := markCombatSessionExpired(sess.SessionID); merr != nil {
slog.Error("combat: reaper failed to mark session expired", "session", sess.SessionID, "err", merr)
}
return
}
rounds := 0
for sess.IsActive() {
if rounds >= reaperRoundCap {
slog.Warn("combat: reaper hit round cap, marking expired",
"user", userID, "session", sess.SessionID)
if merr := markCombatSessionExpired(sess.SessionID); merr != nil {
slog.Error("combat: reaper failed to mark session expired", "session", sess.SessionID, "err", merr)
}
return
}
if _, rerr := runCombatRound(sess, &player, &enemy, PlayerAction{Kind: ActionAttack}); rerr != nil {
slog.Error("combat: reaper round failed", "user", userID, "session", sess.SessionID, "err", rerr)
if merr := markCombatSessionExpired(sess.SessionID); merr != nil {
slog.Error("combat: reaper failed to mark session expired", "session", sess.SessionID, "err", merr)
}
return
}
rounds++
}
outcome := p.finishCombatSession(userID, sess, enemy)
preamble := fmt.Sprintf("⏳ Your fight with **%s** timed out — I finished it for you.\n\n", enemy.Name)
if err := p.SendDM(userID, preamble+outcome); err != nil {
slog.Error("combat: reaper failed to DM outcome", "user", userID, "err", err)
}
}