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.go70
1 files changed, 24 insertions, 46 deletions
diff --git a/internal/game/casino.go b/internal/game/casino.go
index c2c4c4f..517cde0 100644
--- a/internal/game/casino.go
+++ b/internal/game/casino.go
@@ -121,24 +121,6 @@ func (w casinoWallet) payCredits(amount int, stakeIDs []string) error {
return nil
}
-// ResolveStakes consumes every stake still pending for the player: the round
-// resolved as a loss, a forfeit, or a slots outcome whose payout carried no
-// stake linkage. The pending ledger and the save are the commit point.
-func (w casinoWallet) ResolveStakes() {
- if len(w.p.PendingWagers) == 0 {
- return
- }
- before := append([]player.PendingWager(nil), w.p.PendingWagers...)
- w.p.PendingWagers = nil
- if err := w.save("resolve stakes"); err != nil {
- // Keep the in-memory ledger consistent with the durable file: the
- // stakes are still pending on disk, so restore them for a later
- // retry or startup recovery instead of silently diverging.
- w.p.PendingWagers = before
- fmt.Fprintf(os.Stderr, "casino resolve stakes: save for %s: %v (ledger restored in memory)\n", w.p.Name, err)
- }
-}
-
// ResolveStake consumes ONE pending stake by wallet handle: its hand lost or
// was paid by a cover, so it must never be refunded. A settlement that
// already removed it (PayCredits) makes this a no-op, so no redundant
@@ -614,6 +596,28 @@ func (g *Game) emitCasinoEvents(events []casino.Event) {
}
}
+// casinoMenuParts resolves a structured menu into the shared header/balance
+// heading/commands used by both menu render paths: the balance line, the
+// heading (falling back to the event message), and a copy of the commands
+// annotated with an unavailability note for anything the player can't afford.
+func (g *Game) casinoMenuParts(sess *net.Session, menu *casino.MenuView, message string) (balance, heading string, commands []casino.MenuCommand) {
+ balance = ""
+ if menu.ShowBalance {
+ balance = g.casinoBalance(sess)
+ }
+ heading = g.casinoTimeText(menu.Heading)
+ if heading == "" {
+ heading = message
+ }
+ commands = append([]casino.MenuCommand(nil), menu.Commands...)
+ for i := range commands {
+ if commands[i].Cost > casinoAffordable(sess.Player) {
+ commands[i].Desc += " [unavailable: insufficient funds]"
+ }
+ }
+ return balance, heading, commands
+}
+
// casinoBoardReminder splits roulette and craps menus so instructions can be
// printed under the betting board, which is the table the reminder refers to.
// Every other game, and compact displays, keep their menu in one block.
@@ -630,20 +634,7 @@ func (g *Game) casinoBoardReminder(sess *net.Session, category string, menu *cas
// The compact reminder is already a short block; leave it intact.
return "", "", false
}
- balance := ""
- if menu.ShowBalance {
- balance = g.casinoBalance(sess)
- }
- heading := g.casinoTimeText(menu.Heading)
- if heading == "" {
- heading = message
- }
- commands := append([]casino.MenuCommand(nil), menu.Commands...)
- for i := range commands {
- if commands[i].Cost > casinoAffordable(sess.Player) {
- commands[i].Desc += " [unavailable: insufficient funds]"
- }
- }
+ balance, heading, commands := g.casinoMenuParts(sess, menu, message)
return g.casinoMenuHeader(sess, balance, heading), g.casinoMenuCommands(sess, commands), true
}
@@ -681,20 +672,7 @@ func (g *Game) casinoPrivateMessage(sess *net.Session, category string, menu *ca
if category != "casino_menu" || menu == nil {
return message
}
- balance := ""
- if menu.ShowBalance {
- balance = g.casinoBalance(sess)
- }
- heading := g.casinoTimeText(menu.Heading)
- if heading == "" {
- heading = message
- }
- commands := append([]casino.MenuCommand(nil), menu.Commands...)
- for i := range commands {
- if commands[i].Cost > casinoAffordable(sess.Player) {
- commands[i].Desc += " [unavailable: insufficient funds]"
- }
- }
+ balance, heading, commands := g.casinoMenuParts(sess, menu, message)
if sess.Player.OptionString("casino_display") == "compact" && !menu.ShowBalance {
var hints []casino.MenuCommand
for _, c := range commands {