]> Skullheadx's Git Forge - monopoly-web.git/commitdiff
some logging master
authorSkullheadx <admonty1@protonmail.com>
Tue, 9 Jun 2026 02:09:55 +0000 (22:09 -0400)
committerSkullheadx <admonty1@protonmail.com>
Tue, 9 Jun 2026 02:15:01 +0000 (22:15 -0400)
16 files changed:
game/actions.go
game/chance.go
game/chest.go
game/color.go
game/config.go
game/game.go
game/go.go
game/helpers.go
game/jail.go
game/movement.go
game/railroad.go
game/tax.go
game/todo
game/types.go
game/utility.go
public/index.js

index bd7c2f1d34cdd4c6e83d1159e6b1b649ab0367af..58e223257e9f76ff03708844823cffce75475c0d 100644 (file)
@@ -1,11 +1,16 @@
 package game
 
+import "fmt"
+
 func (ctx *Context) RollDice() {
        ctx.EventPop()
 
        // Roll Dice
        diceRoll1 := ctx.Random.Int32N(6) + 1
        diceRoll2 := ctx.Random.Int32N(6) + 1
+       total := diceRoll1 + diceRoll2
+
+       ctx.Turn.Log = append(ctx.Turn.Log, fmt.Sprintf(LogRolled, total))
 
        ctx.Turn.NumDiceRolled++
        ctx.Turn.DiceRollsRemaining--
@@ -23,7 +28,7 @@ func (ctx *Context) RollDice() {
                ctx.PutPlayerInJail(ctx.Turn.Current)
        }
 
-       ctx.Turn.MoveQueue = append(ctx.Turn.MoveQueue, diceRoll1+diceRoll2)
+       ctx.Turn.MoveQueue = append(ctx.Turn.MoveQueue, total)
 }
 
 func (ctx *Context) Buy() {
index 3baa945e5e1656fb45257eae47266889acd2f1ab..d1553299742b01df942cc5a819fc1d105cf22fb1 100644 (file)
@@ -18,6 +18,8 @@ func (ctx *Context) ProcessChance() {
 
                card := ctx.Random.IntN(len(ChanceCards))
 
+               ctx.Turn.Log = append(ctx.Turn.Log, LogLandChance)
+
                currentPos := ctx.Players.Alive[visitorID.Index()].CurrentSpaceID
 
                switch card {
index 9dbfb896f23d276f1dfe0dc86decb4c74fd2db50..58f16ffb0efa78e41fcb49bf31c475d721ff1128 100644 (file)
@@ -8,6 +8,8 @@ func (ctx *Context) ProcessChest() {
                }
                card := ctx.Random.IntN(len(ChanceCards))
 
+               ctx.Turn.Log = append(ctx.Turn.Log, LogLandChest)
+
                currentPos := ctx.Players.Alive[visitorID.Index()].CurrentSpaceID
 
                switch card {
index e1826c9a26a7ce0a6f51cd64d1f39b8c1533aedb..7cd7bf7c1a25ab7c0b3025aae2faaa0f31ff1895 100644 (file)
@@ -1,5 +1,7 @@
 package game
 
+import "fmt"
+
 func (ctx *Context) HasColorMonopoly(playerID PlayerID, targetGroup ColorGroup) bool {
        var ownedCount int32
        for _, prop := range ctx.Properties.Owners {
@@ -43,6 +45,8 @@ func (ctx *Context) ProcessOwnedColors() {
                prop := ColorProperties[colorID]
                prices := ColorPropertyRents[colorID]
 
+               ctx.Turn.Log = append(ctx.Turn.Log, fmt.Sprintf(LogLandColor, prop.Name))
+
                var rent int32 = prices[prop.Houses]
 
                if prop.Houses == 0 && ctx.HasColorMonopoly(ownerID, prop.GroupID) {
index 9e309cee78e19628016319cafa99ad8d368801ac..8a43d54794da3f8c42cdd207c1d6da41c4231d52 100644 (file)
@@ -1,8 +1,30 @@
 package game
 
 const (
-       MSG_START uint8 = iota
-       MSG_END
+       MsgStart  = "START"
+       MsgEnd    = "END" // for turns
+       MsgFinish = "FINISH"
+)
+
+const (
+       LogRolled     = " rolled %v."
+       LogRemoveJail = " escaped Jail."
+       LogPutJail    = " was put in Jail."
+
+       LogLandGo       = " landed on GO."
+       LogLandColor    = " landed on %v."
+       LogLandUtility  = " landed on %v."
+       LogLandRailroad = " landed on %v."
+       LogLandChance   = " landed on Chance."
+       LogLandChest    = " landed on Community Chest."
+       LogLandParking  = " landed on Free Parking."
+       LogLandJail     = " is just visiting Jail."
+       LogLandPolice   = " was told by the police to go to Jail."
+       LogLandTax      = " landed on %v."
+
+       LogMoneyGain     = " earned %v."
+       LogMoneyLose     = " lost %v."
+       LogMoneyBankrupt = " is bankrupt."
 )
 
 const (
index d800363325207f72fa6208cc14f987c9f03d19e8..4a20f61402a0f2992b83452354b870acf9f8cfd5 100644 (file)
@@ -18,6 +18,26 @@ func (ms *MServer) deleteSubscriber(s *MSub) {
        ms.subscribersMu.Unlock()
 }
 
+func (ms *MServer) broadcastMsg(msg string) {
+       for s := range ms.Subscribers {
+               select {
+               case s.Msgs <- []byte(msg):
+               default:
+                       go s.CloseSlow()
+               }
+       }
+}
+
+func (ms *MServer) broadcastLog() {
+       for {
+               l, done := QueuePop(&ms.gameCtx.Turn.Log)
+               if done {
+                       break
+               }
+               ms.broadcastMsg(l)
+       }
+}
+
 func (ms *MServer) start() {
        ms.subscribersMu.Lock()
        defer ms.subscribersMu.Unlock()
@@ -34,15 +54,7 @@ func (ms *MServer) start() {
        ms.gameCtx.logGameCtx()
        ms.gameCtxMu.Unlock()
 
-       msg := []byte{MSG_START}
-       for s := range ms.Subscribers {
-               select {
-               case s.Msgs <- msg:
-               default:
-                       go s.CloseSlow()
-               }
-       }
-
+       ms.broadcastMsg(MsgStart)
 }
 
 func (ms *MServer) roll() {
@@ -50,10 +62,12 @@ func (ms *MServer) roll() {
        ms.gameCtx.ProcessMovement()
 
        ms.gameCtx.logGameCtx()
+       ms.broadcastLog()
 }
 
 func (ms *MServer) buy() {
        ms.gameCtx.Buy()
 
        ms.gameCtx.logGameCtx()
+       ms.broadcastLog()
 }
index 21d8339e7ba460b459990fe76f9b80ec42cef894..656dbdb4b044ca720940555abbad732842b018cc 100644 (file)
@@ -2,6 +2,8 @@ package game
 
 func (ctx *Context) ProcessGo() {
        for _, playerID := range ctx.Visitors.Go {
+               ctx.Turn.Log = append(ctx.Turn.Log, LogLandGo)
+
                ctx.AdjustPlayerMoney(playerID, GoSalary)
        }
 }
index 9381bba0912de6d6995be522feef405fa87928e2..f3ea4c97c3a7d82e30519cff41063bd91738148d 100644 (file)
@@ -9,6 +9,12 @@ import (
 func (ctx *Context) AdjustPlayerMoney(playerID PlayerID, amount int32) {
        ctx.Players.Alive[playerID.Index()].Money += amount
 
+       if amount >= 0 {
+               ctx.Turn.Log = append(ctx.Turn.Log, fmt.Sprintf(LogMoneyGain, amount))
+       } else {
+               ctx.Turn.Log = append(ctx.Turn.Log, fmt.Sprintf(LogMoneyLose, -amount))
+       }
+
        if ctx.Players.Alive[playerID.Index()].Money < 0 {
                ctx.Turn.InDebt = true
        } else { // Money >= 0
index a88674fe97c22bbf38bc1384b6935d89e577190b..1163df9d53b3e1f35f917f1189850e0c9c777cba 100644 (file)
@@ -5,6 +5,8 @@ func (ctx *Context) RemovePlayerFromJail(playerID PlayerID) {
                if playerID == iJV.VisitorID {
                        ctx.Visitors.InJail[i] = ctx.Visitors.InJail[len(ctx.Visitors.InJail)-1]
                        ctx.Visitors.InJail = ctx.Visitors.InJail[:len(ctx.Visitors.InJail)-1]
+
+                       ctx.Turn.Log = append(ctx.Turn.Log, LogRemoveJail)
                }
 
        }
@@ -22,6 +24,7 @@ func (ctx *Context) PutPlayerInJail(pID PlayerID) {
                        ctx.Turn.EventStack = ctx.Turn.EventStack[0:1]
                        ctx.Visitors.InJail = append(ctx.Visitors.InJail, InJailVisitor{VisitorID: pID, TurnsLeft: JailDefaultTurns})
                        ctx.Turn.DiceRollsRemaining = 0
+                       ctx.Turn.Log = append(ctx.Turn.Log, LogPutJail)
                }
        }
 }
index 0b165aaeab0fe51b9a79e387427424fd130209a3..8adb4e57eaac222d9a9d0a897f7ed5b8a46a572d 100644 (file)
@@ -73,6 +73,7 @@ func (ctx *Context) AdvancePlayer(playerID PlayerID, currentPosition SpaceID, di
        case TypeTax:
                ctx.Visitors.Tax = append(ctx.Visitors.Tax, TaxVisitor{VisitorID: playerID, TaxID: prop.SubIndexID})
        case TypePolice: // hardcoding to send straight to jail
+               ctx.Turn.Log = append(ctx.Turn.Log, LogLandPolice)
                ctx.PutPlayerInJail(playerID)
        case TypeColor:
                propID := ctx.getOwnablePropID(nextPos)
index fc1c99b0cd48da70efaf845122d4bed345dce253..1da70702e5198572f5817fbbba33bdfda834bc9f 100644 (file)
@@ -1,5 +1,7 @@
 package game
 
+import "fmt"
+
 func (ctx *Context) numRailroadOwned(playerID PlayerID) int32 {
        var ownedCount int32 = 0
        for _, prop := range ctx.Properties.Owners {
@@ -32,7 +34,9 @@ func (ctx *Context) ProcessOwnedRailroad() {
                }
                visitorID := oRV.VisitorID
                ownerID := oRV.OwnerID
-               // railroadID := oRV.railroadID
+               railroadID := oRV.RailroadID
+
+               ctx.Turn.Log = append(ctx.Turn.Log, fmt.Sprintf(LogLandRailroad, RailroadProperties[railroadID].Name))
 
                var rent int32 = RailroadRent[ctx.numRailroadOwned(ownerID)]
 
index a6ad530b3283a6c8c9c58d5ef83ac045d8337149..9e89d11521df0b9b5399b94b003f704cb5bcbe9b 100644 (file)
@@ -1,5 +1,7 @@
 package game
 
+import "fmt"
+
 func (ctx *Context) ProcessTax() {
        for {
                tV, done := QueuePop(&ctx.Visitors.Tax)
@@ -8,6 +10,9 @@ func (ctx *Context) ProcessTax() {
                }
                playerID := tV.VisitorID
                taxID := tV.TaxID
+
+               ctx.Turn.Log = append(ctx.Turn.Log, fmt.Sprintf(LogLandTax, TaxSpaces[taxID].Name))
+
                ctx.AdjustPlayerMoney(playerID, -TaxSpaces[taxID].Amount)
        }
 }
index f679787368216c31d1c20c78c1911a1282ae8ee3..489e5579ecdeae93a4354f0be92713488344ce60 100644 (file)
--- a/game/todo
+++ b/game/todo
@@ -14,7 +14,7 @@
 ** DONE buy prop
 ** TODO auction
 
-* login multiple times makes new websocket
+* DONE login multiple times makes new websocket
 * DONE Better errors for validators
 * TODO Response for frontend game log
 ** TODO start
index 980ce3cc5a6f324bd65bb5677a0a16117be01364..c3da541101389dbb2b5f5b0d0d9db1d3897628e4 100644 (file)
@@ -178,6 +178,7 @@ type Turn struct {
        EventStack         []EventType
        InDebt             bool
        Modifier           Modifiers
+       Log                []string
 }
 
 type Properties struct {
index 301e793817f21c16cae2048f34ef7b683f4fe4c6..1b50553c4742bba70d3c272f48f2547f04ea6a14 100644 (file)
@@ -1,5 +1,7 @@
 package game
 
+import "fmt"
+
 func (ctx *Context) NumUtilities(playerID PlayerID) int32 {
        var ownedCount int32 = 0
        for _, prop := range ctx.Properties.Owners {
@@ -32,9 +34,11 @@ func (ctx *Context) ProcessOwnedUtility() {
                }
                visitorID := oUV.VisitorID
                ownerID := oUV.OwnerID
-               // utilityID := oUV.utilityID
+               utilityID := oUV.UtilityID
                diceRoll := oUV.DiceRoll
 
+               ctx.Turn.Log = append(ctx.Turn.Log, fmt.Sprintf(LogLandUtility, UtilityProperties[utilityID].Name))
+
                var rent int32 = 0
 
                if !ctx.Turn.Modifier.UtilityForceRentMultiplier {
index 22280f458c846a0dd288893943cd43339da171d2..8732a094274ae96c094ca6a17175e72197ca03d2 100644 (file)
                                 console.error('unexpected message type', typeof ev.data)
                                 return
                         }
-                        appendGameLog(ev.data)
+
+                        if (ev.data === "START") {
+                                appendGameLog("The game has started!")
+                        }
                 })
         }
         async function loggedIn() {