dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit ef92fac1861b9203d403ef36d4204caaefeece3b
parent 2b33e20e80d44d1a0fec74c3da36e2d288305c4f
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sun, 17 Dec 2023 01:45:44 -0500

accessor for cash

Diffstat:
Mpkg/web/handlers/poker/poker.go | 28+++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -107,9 +107,11 @@ type SeatedPlayer struct { LastActionTS time.Time } +func (p *SeatedPlayer) GetCash() database.PokerChip { return p.Cash } + // Return either or not a player is eligible to play a game func (p *SeatedPlayer) isEligible(pokerTableMinBet database.PokerChip) bool { - return p != nil && p.Cash >= pokerTableMinBet + return p != nil && p.GetCash() >= pokerTableMinBet } type PokerPlayer struct { @@ -128,7 +130,7 @@ type PokerPlayer struct { func (p *PokerPlayer) GetBet() database.PokerChip { return p.Bet } func (p *PokerPlayer) isAllIn() bool { - return p.Cash == 0 + return p.GetCash() == 0 } func (p *PokerPlayer) doBet(db *database.DkfDB, bet database.PokerChip, pokerTableID int64, roomTopic string) { @@ -136,7 +138,7 @@ func (p *PokerPlayer) doBet(db *database.DkfDB, bet database.PokerChip, pokerTab p.RoundTotalBet += bet p.Bet += bet p.Cash -= bet - PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerSeatIdx: p.SeatIdx, Player: p.Username, Bet: bet, TotalBet: p.GetBet(), Cash: p.Cash}) + PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerSeatIdx: p.SeatIdx, Player: p.Username, Bet: bet, TotalBet: p.GetBet(), Cash: p.GetCash()}) } type PlayerCard struct { @@ -243,10 +245,10 @@ func (g *Ongoing) computeWinners() (winner []GameResult) { func sortGameResults(arr []GameResult) { for idx := range arr { sort.Slice(arr[idx].Players, func(i, j int) bool { - if arr[idx].Players[i].Cash == arr[idx].Players[j].Cash { + if arr[idx].Players[i].GetCash() == arr[idx].Players[j].GetCash() { return arr[idx].Players[i].RoundTotalBet < arr[idx].Players[j].RoundTotalBet } - return arr[idx].Players[i].Cash < arr[idx].Players[j].Cash + return arr[idx].Players[i].GetCash() < arr[idx].Players[j].GetCash() }) } sort.Slice(arr, func(i, j int) bool { return arr[i].HandScore < arr[j].HandScore }) @@ -609,7 +611,7 @@ RoundIsSettledLoop: } doCall := func() int { - bet := utils.MinInt(minBet-p.GetBet(), p.Cash) + bet := utils.MinInt(minBet-p.GetBet(), p.GetCash()) if bet == 0 { newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s check", pUsername)) } else { @@ -625,7 +627,7 @@ RoundIsSettledLoop: } doAllIn := func() int { - bet := p.Cash + bet := p.GetCash() if (p.GetBet() + bet) > minBet { lastRaisePlayerIdx = playerToPlayIdx } @@ -653,8 +655,8 @@ RoundIsSettledLoop: PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: msg}) return continueGetPlayerEventLoop } - if bet > p.Cash { - msg := fmt.Sprintf("Bet (%d) is too high. Must bet at most %d", bet, p.Cash) + if bet > p.GetCash() { + msg := fmt.Sprintf("Bet (%d) is too high. Must bet at most %d", bet, p.GetCash()) PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: msg}) return continueGetPlayerEventLoop } @@ -1166,7 +1168,7 @@ func processPot(winners []GameResult, mainPot, pokerTableMinBet database.PokerCh } handStr := poker.RankString(group.HandScore) isDone = true - if len(group.Players) == 1 && group.Players[0].Cash > 0 { + if len(group.Players) == 1 && group.Players[0].GetCash() > 0 { // Only 1 player win and is not all-in player := group.Players[0] piece := mainPot @@ -1206,7 +1208,7 @@ func processPot(winners []GameResult, mainPot, pokerTableMinBet database.PokerCh } piece := mainPot / database.PokerChip(nbPlayersInGroup-allInCount) for _, p := range group.Players { - if p.Cash > 0 { + if p.GetCash() > 0 { piece = utils.MinInt(piece, mainPot) res = append(res, newPlayerGain(p, piece, groupIdx, handStr)) mainPot -= piece @@ -1818,7 +1820,7 @@ func drawSeatsStyle(authUser *database.User, g *PokerGame) string { html += `#seat` + itoa(i+1) + ` { border: 2px solid #0d1b8f; }` } html += `#seat` + itoa(i+1) + ` .inner:before { content: "` + pUsername.String() + `"; }` - html += `#seat` + itoa(i+1) + `_cash:before { content: "` + itoa2(p.Cash) + `"; }` + html += `#seat` + itoa(i+1) + `_cash:before { content: "` + itoa2(p.GetCash()) + `"; }` if g.Ongoing != nil { if op := g.Ongoing.GetPlayer(pUsername); op != nil && op.GetBet() > 0 { html += `#seat` + itoa(i+1) + `Pot:before { content: "` + itoa2(op.GetBet()) + `"; }` @@ -1875,7 +1877,7 @@ func drawGameIsDoneHtml(g *PokerGame, evt GameIsDoneEvent) (html string) { html += `<style>` for i, p := range g.Players { if p != nil { - html += `#seat` + itoa(i+1) + `_cash:before { content: "` + itoa2(p.Cash) + `"; }` + html += `#seat` + itoa(i+1) + `_cash:before { content: "` + itoa2(p.GetCash()) + `"; }` } } html += `#winner:before { content: "Winner: ` + evt.Winner + ` (` + evt.WinnerHand + `)"; }`