From 9a716a7d2ce514f452b425caedc1a9a15cde09f0 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Fri, 7 Aug 2026 05:02:39 -0400 Subject: feat: disconnect forfeits bet and frees up seat --- internal/game/casino.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'internal/game/casino.go') diff --git a/internal/game/casino.go b/internal/game/casino.go index 785666e..9f3b524 100644 --- a/internal/game/casino.go +++ b/internal/game/casino.go @@ -43,6 +43,10 @@ func (w casinoWallet) PayCredits(amount int) { w.g.AccountStore.SaveCharacter(w.p) } +// casinoAffordable is the most a player can wager: chips are spent first, +// then credits. +func casinoAffordable(p *player.Player) int { return p.Credits + countChips(p) } + func (g *Game) casinoTable(roomID int, gameName string) (*casino.Table, bool) { room, err := g.World.LoadRoom(roomID) if err != nil { @@ -50,7 +54,11 @@ func (g *Game) casinoTable(roomID int, gameName string) (*casino.Table, bool) { } for _, cfg := range room.CasinoTables { if strings.EqualFold(string(cfg.Game), gameName) { - return g.Casino.EnsureTable(roomID, cfg), true + table := g.Casino.EnsureTable(roomID, cfg) + if table == nil { + return nil, false + } + return table, true } } return nil, false @@ -126,7 +134,12 @@ func (g *Game) executeBet(sess *net.Session, args []string, rawInput string) { } if len(args) == 1 { if args[0] == "max" { - g.emitCasinoEvents(g.Casino.SetMachineBet(machine.RoomID, machine.Config.ID, p.Name, machine.Config.MaxBet, casinoWallet{g: g, p: p})) + amount := min(machine.Config.MaxBet, casinoAffordable(p)) + if amount < 1 { + sess.WriteLine("You don't have any chips or credits to bet.") + return + } + g.emitCasinoEvents(g.Casino.SetMachineBet(machine.RoomID, machine.Config.ID, p.Name, amount, casinoWallet{g: g, p: p})) return } if amount, err := strconv.Atoi(args[0]); err == nil && amount > 0 { @@ -163,7 +176,12 @@ func (g *Game) executeBet(sess *net.Session, args []string, rawInput string) { sess.WriteLine("Use bet, bet [on ], bet min, or bet max.") return } - amount, hasAmount = table.Config.MaxBet, true + amount = min(table.Config.MaxBet, casinoAffordable(p)) + if amount < 1 { + sess.WriteLine("You don't have any chips or credits to bet.") + return + } + hasAmount = true continue } if value, err := strconv.Atoi(arg); err == nil && value > 0 { -- cgit v1.2.3