aboutsummaryrefslogtreecommitdiff
path: root/internal/game/casino.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/casino.go')
-rw-r--r--internal/game/casino.go24
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 {