diff options
| author | historia <[not public]> | 2026-08-07 05:02:39 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-08-07 05:02:39 -0400 |
| commit | 9a716a7d2ce514f452b425caedc1a9a15cde09f0 (patch) | |
| tree | de980f16c4af93512a1616e6521275fd62aca542 /internal/game/casino.go | |
| parent | 0f008790f192a491ac3901d54b506b756f57fef8 (diff) | |
| download | thehouseoficarus-9a716a7d2ce514f452b425caedc1a9a15cde09f0.tar.gz | |
feat: disconnect forfeits bet and frees up seat
Diffstat (limited to 'internal/game/casino.go')
| -rw-r--r-- | internal/game/casino.go | 24 |
1 files changed, 21 insertions, 3 deletions
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 <amount> [on <target>], 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 { |
