package routes import ( "dk/internal/auth" "dk/internal/components" "dk/internal/middleware" "dk/internal/models/fights" "dk/internal/models/users" "dk/internal/router" "math/rand" ) func RegisterFightRoutes(r *router.Router) { group := r.Group("/fight") group.Use(auth.RequireAuth()) group.Use(middleware.RequireFighting()) group.Get("/", showFight) } func showFight(ctx router.Ctx, _ []string) { user := ctx.UserValue("user").(*users.User) fight, err := fights.Find(user.FightID) if err != nil { ctx.SetContentType("text/plain") ctx.SetBodyString("Fight not found") return } // If turn 0, determine first strike and advance to turn 1 if fight.Turn == 0 { // 50% chance user goes first fight.FirstStrike = rand.Float32() < 0.5 fight.Turn = 1 fight.Save() } components.RenderPage(ctx, "Fighting", "fight/fight.html", map[string]any{ "fight": fight, "user": user, }) }