Add a persistent event log for shop and prep actions.

This commit is contained in:
Greyson Parrelli
2026-07-23 08:00:59 -04:00
parent f7a00f6c48
commit 506c6e5b55
7 changed files with 330 additions and 9 deletions
+19 -1
View File
@@ -93,6 +93,9 @@ type Game struct {
Battle *BattleResult `json:"battle,omitempty"` // most recent battle
NextCardID int `json:"nextCardId"`
WinnerSeat int `json:"winnerSeat"` // set at gameover; -1 = tie
// Log is the running, human-readable event log shown across every phase.
Log []LogEntry `json:"log,omitempty"`
LogSeq int `json:"logSeq"` // last assigned entry sequence number
// RollDie overrides the rock die (faces 0,0,1,1,2,2) for tests. Nil
// (including after loading from storage) means a fair random roll.
@@ -225,6 +228,7 @@ func (g *Game) startShopRound() {
}
// The priority-token holder shops first.
g.Turn = g.PrioritySeat
g.logf(-1, "🛒", "Round %d — shop opens (%s goes first).", g.Round, g.Players[g.PrioritySeat].Name)
}
// drawFromTier pops the top card of the given tier's deck (1-based tier).
@@ -273,6 +277,7 @@ func (g *Game) Buy(playerID string, rowIdx int) error {
p.Coins--
bought := g.ShopRow[rowIdx]
p.Deck = append(p.Deck, bought)
g.logf(p.Seat, "🛒", "%s bought %s %s.", p.Name, article(bought.Name), bought.Name)
g.ShopRow[rowIdx] = g.drawFromTier(g.Round)
g.applyShopTrigger(p, bought, TriggerBuy)
g.advanceShopTurn()
@@ -310,11 +315,15 @@ func (g *Game) applyShopTrigger(p *Player, c Card, trigger EffectTrigger) {
}
switch e.Action {
case ActionGainApple:
for range e.count() {
n := e.count()
for range n {
p.Deck = append(p.Deck, g.newApple())
}
g.addLog(LogEntry{Seat: p.Seat, Icon: "🍎", Source: c.ID, Spawn: "apple",
Text: fmt.Sprintf("%s adds %d apple%s to %s's deck.", c.Name, n, plural(n), p.Name)})
case ActionRefreshGold:
p.Coins = min(p.Coins+e.count(), CoinsPerRound)
g.logf(p.Seat, "🪙", "%s refreshes %s's coins.", c.Name, p.Name)
case ActionDoubleApples:
apples := 0
for _, dc := range p.Deck {
@@ -325,6 +334,10 @@ func (g *Game) applyShopTrigger(p *Player, c Card, trigger EffectTrigger) {
for range apples {
p.Deck = append(p.Deck, g.newApple())
}
if apples > 0 {
g.addLog(LogEntry{Seat: p.Seat, Icon: "🍎", Source: c.ID, Spawn: "apple",
Text: fmt.Sprintf("%s doubles %s's apples (+%d).", c.Name, p.Name, apples)})
}
}
}
}
@@ -349,6 +362,8 @@ func (g *Game) sellCards(p *Player, cardIDs []string) error {
}
for _, c := range sold {
p.Deck = append(p.Deck, g.newApple())
g.addLog(LogEntry{Seat: p.Seat, Icon: "🍎", Source: c.ID, Spawn: "apple",
Text: fmt.Sprintf("%s sold %s — it becomes an apple.", p.Name, c.Name)})
g.applyShopTrigger(p, c, TriggerSell)
}
return nil
@@ -397,6 +412,7 @@ func (g *Game) TradeStart(playerID string, cardIDs []string) error {
}
p.Coins--
p.TripledThisRound = true
g.logf(p.Seat, "🔄", "%s traded in 3 %s pets for a tier %d pick.", p.Name, suit, nextTier)
g.Pending = &PendingTrade{
PlayerID: playerID,
Tier: nextTier,
@@ -424,6 +440,7 @@ func (g *Game) TradeChoose(playerID string, pick int) error {
tierIdx := g.Pending.Tier - 1
g.ShopDecks[tierIdx] = append(g.ShopDecks[tierIdx], other)
g.Pending = nil
g.logf(p.Seat, "🔄", "%s picked %s from the trade.", p.Name, chosen.Name)
// Pets obtained via the Triple action trigger their Buy effects.
g.applyShopTrigger(p, chosen, TriggerBuy)
g.advanceShopTurn()
@@ -456,6 +473,7 @@ func (g *Game) Pass(playerID string) error {
return err
}
p.Coins = 0
g.logf(p.Seat, "✋", "%s passed.", p.Name)
g.advanceShopTurn()
return nil
}