diff options
Diffstat (limited to 'internal/casino/craps.go')
| -rw-r--r-- | internal/casino/craps.go | 72 |
1 files changed, 35 insertions, 37 deletions
diff --git a/internal/casino/craps.go b/internal/casino/craps.go index 3bbb08f..286fe0a 100644 --- a/internal/casino/craps.go +++ b/internal/casino/craps.go @@ -5,7 +5,6 @@ import ( "math/rand" "strconv" "strings" - "time" ) type crapsBet struct { @@ -16,29 +15,29 @@ type crapsBet struct { } type crapsPlayer struct { Participant - bets []*crapsBet - lastSpot string - lastBet int - autoRoll bool - autoElapsed time.Duration + bets []*crapsBet + lastSpot string + lastBet int + autoRoll bool + autoTicks int } func (p *crapsPlayer) participantPtr() *Participant { return &p.Participant } type crapsTable struct { tableCore[*crapsPlayer] - rng *rand.Rand - queue []string - point int - dice [2]int - rolled bool - made map[int]bool - seen map[int]bool - roundElapsed time.Duration - multiplayer bool - lastCall bool - pendingRoll time.Duration // manual roll: time left before the dice resolve - countdown int // simplified craps: automatic-roll countdown lines emitted + rng *rand.Rand + queue []string + point int + dice [2]int + rolled bool + made map[int]bool + seen map[int]bool + roundTicks int + multiplayer bool + lastCall bool + pendingRollTicks int // manual roll: ticks left before the dice resolve + countdown int // simplified craps: automatic-roll countdown lines emitted } type CrapsBetView struct { Name, Target string @@ -52,7 +51,7 @@ type CrapsSnapshot struct { Queue []string Made, Seen []int Bets []CrapsBetView - Remaining int // legacy snapshot field; presentation uses seconds below + Remaining int // legacy snapshot field; presentation uses ticks below ShootIn int DealerIn int AutoRoll bool @@ -78,15 +77,15 @@ func (t *crapsTable) view() *CrapsSnapshot { if t.hasLiveBets() { if t.Config.Craps.variant() == "simplified" { // One automatic roll: the snapshot counts down the shared window. - s.ShootIn = crapsSeconds(crapsSimplifiedDelay - t.roundElapsed) + s.ShootIn = max(0, crapsSimplifiedTicks-t.roundTicks) } else if t.multiplayer { - s.ShootIn = crapsSeconds(crapsBetDelay - t.roundElapsed) - s.DealerIn = crapsSeconds(crapsBetDelay + crapsDealerDelay - t.roundElapsed) + s.ShootIn = max(0, crapsBetTicks-t.roundTicks) + s.DealerIn = max(0, crapsBetTicks+crapsDealerTicks-t.roundTicks) } } if p := t.shooter(); p != nil && p.autoRoll { s.AutoRoll = true - s.AutoIn = max(s.ShootIn, crapsSeconds(crapsAutoDelay-p.autoElapsed)) + s.AutoIn = max(s.ShootIn, max(0, crapsAutoTicks-p.autoTicks)) } for n := 2; n <= 12; n++ { if t.made[n] { @@ -133,10 +132,9 @@ func (t *crapsTable) join(name string) []Event { return append([]Event{e, t.menu(name)}, timing...) } func (t *crapsTable) remove(name string) { - t.countdown = 0 if len(t.queue) > 0 && t.queue[0] == name { // The queued roll belongs to the shooter; a departing shooter cancels it. - t.pendingRoll = 0 + t.pendingRollTicks = 0 } t.removeSeatLocked(name) for i, n := range t.queue { @@ -356,7 +354,7 @@ func (t *crapsTable) resolveRoll(a, b int) []Event { } var results []Event for _, p := range t.players.ordered() { - p.autoElapsed = 0 + p.autoTicks = 0 var lines []settlementLine failed := false var live []*crapsBet @@ -437,7 +435,7 @@ func (t *crapsTable) finishCrapsControls() []Event { } if p.autoRoll { p.autoRoll = false - p.autoElapsed = 0 + p.autoTicks = 0 events = append(events, t.private(p.Name, "{casino_emphasis}Autoroll complete{/} — all your bets have settled. Manual play resumed.")) } if p.LeaveAfter { @@ -457,7 +455,7 @@ func (t *crapsTable) finishCrapsControls() []Event { } return events } -func (t *crapsTable) tick() []Event { return t.tickElapsed(600 * time.Millisecond) } +func (t *crapsTable) tick() []Event { return t.advance(1) } func (t *crapsTable) action(name, action string) []Event { t.mu.Lock() defer t.mu.Unlock() @@ -476,7 +474,7 @@ func (t *crapsTable) action(name, action string) []Event { return append(events, t.syncRoundClock()...) } if t.Config.Craps.variant() == "simplified" && (action == "roll" || action == "autoroll") { - return []Event{t.private(name, "Simplified craps rolls by itself 3 seconds after a bet; there is no manual roll.")} + return []Event{t.private(name, "Simplified craps rolls by itself 3 ticks after a bet; there is no manual roll.")} } if action == "autoroll" { if !p.HasBet { @@ -484,9 +482,9 @@ func (t *crapsTable) action(name, action string) []Event { } if !p.autoRoll { p.autoRoll = true - p.autoElapsed = 0 + p.autoTicks = 0 } - return []Event{t.private(name, "{casino_emphasis}Autoroll ON{/} — every 3 seconds on your turn, respecting the multiplayer betting window. {command}stop{/} returns to manual play."), t.reminder(name)} + return []Event{t.private(name, "{casino_emphasis}Autoroll ON{/} — every 3 ticks on your turn, respecting the multiplayer betting window. {command}stop{/} returns to manual play."), t.reminder(name)} } if action == "roll" { events := t.syncRoundClock() @@ -496,13 +494,13 @@ func (t *crapsTable) action(name, action string) []Event { if !t.hasLiveBets() { return append(events, t.private(name, "Place a bet, then roll whenever you're ready.")) } - if t.multiplayer && t.roundElapsed < crapsBetDelay { - return append(events, t.private(name, fmt.Sprintf("Others have time to bet: you can shoot in {casino_emphasis}%d seconds{/}. Bets remain open until you roll.", crapsSeconds(crapsBetDelay-t.roundElapsed)))) + if t.multiplayer && t.roundTicks < crapsBetTicks { + return append(events, t.private(name, fmt.Sprintf("Others have time to bet: you can shoot in {casino_emphasis}%d ticks{/}. Bets remain open until you roll.", crapsBetTicks-t.roundTicks))) } - if t.pendingRoll > 0 { + if t.pendingRollTicks > 0 { return append(events, t.private(name, "The dice are already in the air.")) } - t.pendingRoll = crapsManualRollDelay + t.pendingRollTicks = crapsManualRollTicks shake := t.playerAction(name, fmt.Sprintf("{casino_emphasis}%s shakes the dice...{/}", name), "{casino_emphasis}You shake the dice...{/}") return append(events, shake) } @@ -607,12 +605,12 @@ func (t *crapsTable) refundAll() []Event { p.bets = nil p.HasBet = false p.autoRoll = false - p.autoElapsed = 0 + p.autoTicks = 0 } t.point = 0 t.rolled = false t.countdown = 0 - t.pendingRoll = 0 + t.pendingRollTicks = 0 t.made = map[int]bool{} t.seen = map[int]bool{} t.phase = phaseWaiting |
