From: Skullheadx Date: Mon, 8 Jun 2026 22:47:01 +0000 (-0400) Subject: fix validatorsp X-Git-Url: http://git.skullheadx.com/nixos/static/about.html?a=commitdiff_plain;h=1d7b0c2e787c19f972adff62a50c2cf01111a359;p=monopoly-web.git fix validatorsp --- diff --git a/game/game.go b/game/game.go index 0025066..3fbf01b 100644 --- a/game/game.go +++ b/game/game.go @@ -223,10 +223,7 @@ func (ms *MonopolyServer) rollHandler(w http.ResponseWriter, r *http.Request) { } func (ms *MonopolyServer) roll() { - ms.gameCtx.logGameCtx() ms.gameCtx.RollDice() - - ms.gameCtx.logGameCtx() ms.gameCtx.ProcessMovement() ms.gameCtx.logGameCtx() @@ -306,6 +303,7 @@ func (ms *MonopolyServer) start() { ms.gameCtxMu.Lock() ms.gameCtx = InitCtx(ms.randSeed, players) + ms.gameCtx.logGameCtx() ms.gameCtxMu.Unlock() msg := []byte{MSG_START} @@ -457,25 +455,29 @@ func (ctx *Context) ValidateIsTurn(userUUID string) bool { } func (ctx *Context) ValidateCanRoll(userUUID string) bool { - if ctx.ValidateIsTurn(userUUID) && ctx.EventPeek() == EventRollDice { + if ctx.ValidateIsTurn(userUUID) && (ctx.EventPeek() == EventRollDice || ctx.EventPeek() == EventJail) { return true } return false } func (ctx *Context) ValidateCanEndTurn(userUUID string) bool { - if ctx.ValidateIsTurn(userUUID) || ctx.EventPeek() == EventEndTurn || ctx.GetCurrentTurnPlayer().Money >= 0 { + if ctx.ValidateIsTurn(userUUID) && ctx.EventPeek() == EventEndTurn && ctx.GetCurrentTurnPlayer().Money >= 0 { return true } return false } -func (ctx *Context) ValidateCanExitJail(userUUD string) bool { +func (ctx *Context) ValidateCanExitJail(userUUID string) bool { + inJail := false for _, iJV := range ctx.Visitors.InJail { - if ctx.Players.Alive[iJV.VisitorID.Index()].UserUUID == userUUD { - return true + if ctx.Players.Alive[iJV.VisitorID.Index()].UserUUID == userUUID { + inJail = true } } + if ctx.ValidateIsTurn(userUUID) && inJail && ctx.EventPeek() == EventJail { + return true + } return false } @@ -522,6 +524,7 @@ func (ctx *Context) RollDice() { } func (ctx *Context) EndTurn() { + ctx.EventPop() nextTurnPlayerID := PlayerID{ID: (ctx.Turn.Current.ID + 1) % int32(len(ctx.Players.Alive))} ctx.Turn = initTurn(nextTurnPlayerID, !ctx.PlayerCanMove(nextTurnPlayerID)) // TODO: send options list to the next player