diff options
Diffstat (limited to 'internal/casino/blackjack.go')
| -rw-r--r-- | internal/casino/blackjack.go | 75 |
1 files changed, 28 insertions, 47 deletions
diff --git a/internal/casino/blackjack.go b/internal/casino/blackjack.go index 0a5c0d1..5fb8b0b 100644 --- a/internal/casino/blackjack.go +++ b/internal/casino/blackjack.go @@ -668,28 +668,22 @@ func (t *blackjackTable) settle() []Event { if !p.HasBet { continue } - roundNet, roundFailed := int64(0), false + needsBalance := p.LeaveAfter || p.SitOutAfter || !p.Connected + lines := make([]settlementLine, 0, len(p.hands)+1) for i, hand := range p.hands { result, payout, settleErr := settleHand(hand, dealerTotal, dealerBlackjack, t.Rules) // One shared settlement path for every game: pay before // announcing, and leave the stakes pending on any failure so a // refund can never be paid on top of a payout that was not durable. if settleStakeOutcome(p.Wallet, payout, hand.stakes, settleErr) { - roundFailed = true - settlement := t.playerAction(p.Name, p.Name+"’s settlement is pending recovery.", payoutFailedMessage()) - colorizeBlackjackSettlement(&settlement, result) - events = append(events, settlement) + events = append(events, t.playerAction(p.Name, p.Name+"’s settlement is pending recovery.", payoutFailedMessage())) continue } - publicResult, _ := blackjackResultMessages(p.Name, result, payout) - roundNet += int64(payout) - int64(hand.bet) - privateResult := resultText(result, hand.bet, payout) + label := "" if len(p.hands) > 1 { - privateResult = fmt.Sprintf("Hand %d/%d | %s", i+1, len(p.hands), privateResult) + label = fmt.Sprintf("Hand %d/%d", i+1, len(p.hands)) } - settlement := t.playerAction(p.Name, publicResult, privateResult) - colorizeBlackjackSettlement(&settlement, result) - events = append(events, settlement) + lines = append(lines, settlementLine{Label: label, Result: result, Stake: hand.bet, Returned: payout}) } if p.insurance > 0 { insurancePayout := 0 @@ -698,27 +692,19 @@ func (t *blackjackTable) settle() []Event { insurancePayout, insuranceErr = MulPayout(p.insurance, 1+t.Rules.InsurancePayout) } if settleStakeOutcome(p.Wallet, insurancePayout, []string{p.insuranceStakeID}, insuranceErr) { - roundFailed = true events = append(events, t.private(p.Name, payoutFailedMessage())) } else { - roundNet += int64(insurancePayout) - int64(p.insurance) - events = append(events, t.private(p.Name, resultText("insurance", p.insurance, insurancePayout))) + lines = append(lines, settlementLine{Label: "Insurance", Result: "insurance", Stake: p.insurance, Returned: insurancePayout}) } } - if !roundFailed { - // A single settled hand with no insurance already reported its net - // in the per-hand result line, so a summary is only noise. Keep it - // for split hands and insurance, and whenever the player will not - // receive the next-round menu that carries their balance. - needsBalance := p.LeaveAfter || p.SitOutAfter || !p.Connected - if len(p.hands) > 1 || p.insurance > 0 || needsBalance { - e := t.private(p.Name, fmt.Sprintf("Round complete | Net %+d credits (insurance included)", roundNet)) - e.ShowBalance = needsBalance - if roundNet > 0 { - e.Color = "casino_big_win" - } - events = append(events, e) - } + // One settlement per player reports the round's net once and then + // names every hand (and insurance) that produced it. A single hand + // keeps the headline only; splits and insurance get the itemized list. + if len(lines) > 0 { + settlement := t.playerAction(p.Name, blackjackPublicResult(p.Name, lines), settlementText(lines)) + settlement.ShowBalance = needsBalance + settlement.Color = settlementTag(lines) + events = append(events, settlement) } // Each hand's stakes were already consumed per-handle by // settleStakeOutcome (a payout removes them in PayCredits; a loss @@ -780,13 +766,19 @@ func (t *blackjackTable) resetRound() { } } -// colorizeBlackjackSettlement paints a winning settlement with the big-win -// (or jackpot, for a natural) color. -func colorizeBlackjackSettlement(e *Event, result string) { - if result == "blackjack" { - e.Color = "casino_jackpot_win" - } else if result == "win" { - e.Color = "casino_big_win" +// blackjackPublicResult summarizes a player's round for the room: the net is +// not named, only the outcome. +func blackjackPublicResult(name string, lines []settlementLine) string { + if len(lines) == 1 && lines[0].Result == "blackjack" { + return name + " gets blackjack!" + } + switch { + case settlementNet(lines) > 0: + return name + " wins!" + case settlementNet(lines) < 0: + return name + " loses." + default: + return name + " pushes." } } @@ -861,17 +853,6 @@ func handScore(hand *blackjackHand) string { return fmt.Sprintf("Soft %d", total) } -func blackjackResultMessages(name, result string, payout int) (string, string) { - switch result { - case "win", "blackjack": - return name + " wins!", fmt.Sprintf("You win! +%d credits", payout) - case "push": - return name + " pushes.", fmt.Sprintf("You push. +%d credits", payout) - default: - return name + " loses.", "You lose!" - } -} - // markDisconnected removes the player from the table. A wager is forfeited // only when a hand is actually in flight (cards are face up, so a free // refund would hand back information the round carries); a stake placed in |
