aboutsummaryrefslogtreecommitdiff
path: root/internal/game/lifecycle.go
blob: b39c805b6680cfe0da52058c5a1e1b996d183a91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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)
}