diff options
Diffstat (limited to 'internal/casino/craps.go')
| -rw-r--r-- | internal/casino/craps.go | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/internal/casino/craps.go b/internal/casino/craps.go index 90c95c9..6fa6c79 100644 --- a/internal/casino/craps.go +++ b/internal/casino/craps.go @@ -249,6 +249,9 @@ func (t *crapsTable) bet(name, spot string, amount int, w Wallet) []Event { } requested := amount amount = roundUpTo(amount, payoutDen) + if amount > t.Config.MaxBet { + return reject(fmt.Sprintf("That wager rounds up to %d, above the table maximum.", amount)) + } // Compare without multiplying a potentially very large stake by Nx. if (amount-1)/limit >= b.stake.Total { return reject("Odds already placed or above the free-odds limit.") @@ -557,7 +560,6 @@ func (t *crapsTable) unbetAllLocked(p *crapsPlayer) []Event { if b.odds.Total > 0 { total += b.odds.Total ids = append(ids, b.odds.ID) - b.odds = Wager{} } live = append(live, b) default: @@ -571,12 +573,17 @@ func (t *crapsTable) unbetAllLocked(p *crapsPlayer) []Event { if total == 0 { return []Event{t.private(p.Name, "Nothing removable on the table.")} } + // Keep the live wagers intact until the atomic refund succeeds. On a + // failed save they still belong to the next roll, or a later unbet retry. + if err := p.Wallet.PayCredits(total, ids...); err != nil { + return []Event{t.private(p.Name, "The house could not take down your bets. All wagers remain live; try unbet again.")} + } + for _, b := range live { + b.odds = Wager{} + } p.bets = live p.HasBet = len(live) > 0 e := t.private(p.Name, fmt.Sprintf("You take down {casino_chips}%d{/} credits of optional bets; contracts stay up.", total)) - if err := p.Wallet.PayCredits(total, ids...); err != nil { - e.Message = payoutFailedMessage() - } events := []Event{e, t.betSummary(p)} events = append(events, t.syncRoundClock()...) if t.players.has(p.Name) { |
