]> Skullheadx's Git Forge - monopoly-web.git/commitdiff
fix validatorsp
authorSkullheadx <admonty1@protonmail.com>
Mon, 8 Jun 2026 22:47:01 +0000 (18:47 -0400)
committerSkullheadx <admonty1@protonmail.com>
Mon, 8 Jun 2026 22:47:01 +0000 (18:47 -0400)
game/game.go

index 0025066a6c54e1b56c5a25157206d8ebeb403085..3fbf01b0f24b1446c0f0eb744160959e82cfaaca 100644 (file)
@@ -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