diff options
Diffstat (limited to 'internal/casino/baccarat.go')
| -rw-r--r-- | internal/casino/baccarat.go | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/internal/casino/baccarat.go b/internal/casino/baccarat.go index 800b5e6..d415901 100644 --- a/internal/casino/baccarat.go +++ b/internal/casino/baccarat.go @@ -2,7 +2,6 @@ package casino import ( "fmt" - "math" "math/rand" "sync" ) @@ -125,9 +124,9 @@ func (t *baccaratTable) bet(name, spot string, amount int, wallet Wallet) []Even if amount < t.Config.MinBet || amount > t.Config.MaxBet { return []Event{t.private(name, fmt.Sprintf("Baccarat bets must be %s.", betRangeText(t.Config.MinBet, t.Config.MaxBet)))} } - wager, ok := wallet.Wager(amount) - if !ok { - return []Event{t.private(name, "You don't have enough chips and credits for that bet.")} + wager, err := wallet.Wager(amount) + if err != nil { + return []Event{t.private(name, walletErrorMessage(err))} } p.HasBet, p.Wager, p.Wallet, p.lastBet, p.lastSpot = true, wager, wallet, amount, spot events := []Event{t.playerAction(name, @@ -329,11 +328,13 @@ func settleBaccaratBet(spot string, bet int, playerTotal, bankerTotal int, rules } case bankerTotal > playerTotal: if spot == baccaratSpotBanker { - return "win", bet + int(math.Floor(float64(bet)*rules.BankerPayout)) + bankerWin, _ := MulPayout(bet, rules.BankerPayout) + return "win", bet + bankerWin } default: if spot == baccaratSpotTie { - return "win", bet + int(math.Floor(float64(bet)*rules.TiePayout)) + tieWin, _ := MulPayout(bet, rules.TiePayout) + return "win", bet + tieWin } return "push", bet } @@ -361,3 +362,35 @@ func baccaratResultMessages(name, result string, payout int) (string, string) { return name + " loses.", "You lose!" } } + +// refundAll resolves every committed wager at this table (graceful +// shutdown): stakes return to their players through the wallet. +func (t *baccaratTable) refundAll() []Event { + t.mu.Lock() + defer t.mu.Unlock() + var events []Event + for _, p := range t.players.ordered() { + if !p.HasBet || p.Wallet == nil { + continue + } + name, refund := p.Name, p.Wager.Total + if refund <= 0 { + continue + } + if err := p.Wallet.PayCredits(refund); err != nil { + events = append(events, t.private(name, "Shutdown refund could not be persisted; the stake is recorded for recovery.")) + continue + } + events = append(events, t.playerAction(name, + fmt.Sprintf("%s is refunded %d credits as the casino closes.", name, refund), + fmt.Sprintf("The house refunds your %d credit stake for the shutdown.", refund))) + } + return events +} + +// setRoom updates the event-routing room after a room-ID rekey. Locked. +func (t *baccaratTable) setRoom(roomID int) { + t.mu.Lock() + defer t.mu.Unlock() + t.tableBase.setRoom(roomID) +} |
