diff options
| author | historia <[not public]> | 2026-09-15 17:04:48 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-09-15 17:04:48 -0400 |
| commit | 69fb90f6876d7f7dbe7be0d515c94849e5431caf (patch) | |
| tree | 15fb0f5897c537315d4283bb8265d28a13aae313 /internal/game/casino.go | |
| parent | d89504c3df74706b387b8fa829dd291e31ca01c7 (diff) | |
| download | thehouseoficarus-69fb90f6876d7f7dbe7be0d515c94849e5431caf.tar.gz | |
cmd_quit gracefully departs casino games; cmd_stop cancels a pending quit
Diffstat (limited to 'internal/game/casino.go')
| -rw-r--r-- | internal/game/casino.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/internal/game/casino.go b/internal/game/casino.go index 7442178..3edb26b 100644 --- a/internal/game/casino.go +++ b/internal/game/casino.go @@ -94,6 +94,34 @@ func (w casinoWallet) PayCredits(amount int) error { // then credits. func casinoAffordable(p *player.Player) int { return p.Credits + countChips(p) } +// leaveCasinoGames departs every casino game the player participates in +// using the graceful leave policy each game defines for player-initiated +// exits (the same path the "stop" command takes): a table with a wager +// committed to the round in flight refuses and emits its own refusal +// message, machines stop auto-bet or are left outright. It reports whether +// the player is now clear of all casino games; false means a departure is +// blocked mid-round and the caller (quit) must abort. Nil-safe for test +// scaffolding without a Casino manager. +func (g *Game) leaveCasinoGames(sess *net.Session, p *player.Player) bool { + if g.Casino == nil { + return true + } + if table, playing := g.Casino.Participation(p.Name); playing { + if table != nil { + g.emitCasinoEvents(g.Casino.Leave(table.RoomID, table.Config.ID, p.Name)) + } else if machine, ok := g.Casino.MachineFor(p.Name); ok { + if events, stopped := g.Casino.StopMachineAutoBet(machine.RoomID, machine.Config.ID, p.Name); stopped { + g.emitCasinoEvents(events) + } else { + g.emitCasinoEvents(g.Casino.LeaveMachine(machine.RoomID, machine.Config.ID, p.Name)) + } + } + _, stillPlaying := g.Casino.Participation(p.Name) + return !stillPlaying + } + return true +} + // inCasinoGame reports whether the player is currently seated at any casino // table or machine. Nil-safe for test scaffolding without a Casino manager. func (g *Game) inCasinoGame(name string) bool { |
