aboutsummaryrefslogtreecommitdiff
path: root/internal/game/predictions.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-10-05 17:05:14 -0400
committerhistoria <[not public]>2026-10-05 17:05:14 -0400
commite42952469dadfb3535633c66c881050ac128703c (patch)
treea78f7396b72cdbd6fa4f6c454c830f40cf2ad0cb /internal/game/predictions.go
parent90ad8c0c33b519d5830c69d4128bdc984b5e9de8 (diff)
downloadthehouseoficarus-e42952469dadfb3535633c66c881050ac128703c.tar.gz
fix: gather verbs, walk oom, admin path bypass, roulette refund
Diffstat (limited to 'internal/game/predictions.go')
-rw-r--r--internal/game/predictions.go34
1 files changed, 21 insertions, 13 deletions
diff --git a/internal/game/predictions.go b/internal/game/predictions.go
index c61e64e..2cd5917 100644
--- a/internal/game/predictions.go
+++ b/internal/game/predictions.go
@@ -82,11 +82,11 @@ func (g *Game) executePredictions(s *net.Session, args []string, origin string)
if len(args) > 0 {
r.action = strings.ToLower(args[0])
}
- number := func(i int) int {
- if i >= len(args) {
+ number1 := func() int {
+ if len(args) <= 1 {
return 0
}
- n, _ := strconv.Atoi(args[i])
+ n, _ := strconv.Atoi(args[1])
return n
}
switch r.action {
@@ -108,7 +108,7 @@ func (g *Game) executePredictions(s *net.Session, args []string, origin string)
r.search = s.PredictionSearch
case "list":
if len(args) > 1 {
- r.page = number(1)
+ r.page = number1()
}
case "refresh", "next", "prev":
r.action = s.PredictionScreen
@@ -149,7 +149,7 @@ func (g *Game) executePredictions(s *net.Session, args []string, origin string)
r.id = s.PredictionSelected
break
}
- n := number(1)
+ n := number1()
if n < 1 || n > len(s.PredictionIDs) {
s.WriteLine("Choose a market number from markets.")
g.predictionHints(s)
@@ -163,7 +163,7 @@ func (g *Game) executePredictions(s *net.Session, args []string, origin string)
g.predictionHints(s)
return
}
- r.quantity = number(1)
+ r.quantity = number1()
if len(args) < 3 || r.quantity < 1 || r.quantity > 10000 {
s.WriteLine("buy SHARES OUTCOME - for example: buy 10 yes or buy 10 2")
g.predictionHints(s)
@@ -176,7 +176,7 @@ func (g *Game) executePredictions(s *net.Session, args []string, origin string)
r.outcomeName = outcomeTok
}
case "holding", "sell":
- r.lot = number(1) - 1
+ r.lot = number1() - 1
if r.lot < 0 || r.lot >= len(s.Player.PredictionContracts) {
s.WriteLine("Use a contract number from active.")
return
@@ -254,7 +254,7 @@ func (g *Game) executePredictions(s *net.Session, args []string, origin string)
case "active":
g.predictionActive(s, result.markets)
case "closed":
- g.predictionClosed(s, result.markets, r.page)
+ g.predictionClosed(s, r.page)
case "view":
if _, ok := result.markets[r.id]; ok {
g.predictionView(s, result.markets[r.id], result.history)
@@ -386,14 +386,15 @@ func (g *Game) collectPredictions(s *net.Session) {
p := s.Player
before := append([]prediction.Contract(nil), p.PredictionContracts...)
credits := p.Credits
+ // Compute the payout before mutating contract status: if the credit cap
+ // rejects the deposit we must leave the contracts resolved so the player
+ // can collect later. Marking them collected first destroyed the winnings.
total, count := 0, 0
- for i, c := range p.PredictionContracts {
+ for _, c := range p.PredictionContracts {
if c.Status != "resolved" {
continue
}
total += c.Proceeds
- c.Status = "collected"
- p.PredictionContracts[i] = c
count++
}
if count == 0 {
@@ -406,6 +407,13 @@ func (g *Game) collectPredictions(s *net.Session) {
s.WriteLine("Collecting would exceed your credit limit. Bank or spend some credits and try again.")
return
}
+ for i, c := range p.PredictionContracts {
+ if c.Status != "resolved" {
+ continue
+ }
+ c.Status = "collected"
+ p.PredictionContracts[i] = c
+ }
p.Credits = balance
if !g.savePredictions(s, before, credits) {
return
@@ -415,7 +423,7 @@ func (g *Game) collectPredictions(s *net.Session) {
} else {
s.WriteLine(g.colorize(s, "casino_result_push", fmt.Sprintf("Cleared %d resolved contract(s); no payout this time.", count)))
}
- g.predictionClosed(s, nil, 1)
+ g.predictionClosed(s, 1)
}
func (g *Game) tradePrediction(s *net.Session, r predictionRequest, m prediction.Market) (traded bool) {
p := s.Player
@@ -679,7 +687,7 @@ func (g *Game) predictionActive(s *net.Session, markets map[string]prediction.Ma
g.predictionHints(s)
}
-func (g *Game) predictionClosed(s *net.Session, markets map[string]prediction.Market, page int) {
+func (g *Game) predictionClosed(s *net.Session, page int) {
p := s.Player
s.PredictionScreen = "closed"
s.PredictionSelected = ""