aboutsummaryrefslogtreecommitdiff
path: root/internal/game/lifecycle.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/lifecycle.go')
-rw-r--r--internal/game/lifecycle.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/internal/game/lifecycle.go b/internal/game/lifecycle.go
new file mode 100644
index 0000000..b39c805
--- /dev/null
+++ b/internal/game/lifecycle.go
@@ -0,0 +1,31 @@
+package game
+
+import (
+ "thehouseoficarus/internal/net"
+ "thehouseoficarus/internal/player"
+)
+
+// releaseCharacterRuntime tears down a character's live world presence when it
+// leaves the world, whether through the quit countdown final tick or a hard
+// disconnect. Keeping it in one place is what stops a per-player system from
+// being cleaned up on one exit path and forgotten on another: the quit path
+// used to leave a player occupying a safespot cover and holding a stale action.
+//
+// It deliberately does NOT detach the session registry, touch trigger
+// sequences, persist the character, or resolve casino wagers. Callers own
+// those because their ordering differs: disconnect must snapshot locked
+// sequences (persistLockedOnDisconnect) before sequences are dropped, and
+// resolves casino wagers through its deferral/refund path, while quit forfeits
+// a mid-round stake immediately before saving.
+func (g *Game) releaseCharacterRuntime(sess *net.Session, p *player.Player) {
+ if p == nil {
+ return
+ }
+ g.stopCombat(p.Name)
+ g.cancelRest(p.Name)
+ g.cancelAction(p)
+ if ss, ok := g.safespot.Get(p.Name); ok {
+ g.forceLeaveSafespot(sess, p, &ss, "")
+ }
+ delete(g.hackingStates, p.Name)
+}