package game import ( "fmt" "sort" "thirdcollapse/internal/net" "thirdcollapse/internal/player" ) func (g *Game) doQueued(sess *net.Session) { p := sess.Player.(*player.Player) freeCmds := g.freeQueue[p.Name] activeCmd := g.activeQueue[p.Name] if len(freeCmds) == 0 && activeCmd == nil { sess.WriteLine("\nNo actions queued.") return } sess.WriteLine("") if len(freeCmds) > 0 { sess.WriteLine(" Queued free actions (will execute in order):") for i, qc := range freeCmds { cmd := qc.Command if qc.Args != "" { cmd += " " + qc.Args } sess.WriteLine(fmt.Sprintf(" %d) %s", i+1, cmd)) } } if activeCmd != nil { if len(freeCmds) > 0 { sess.WriteLine("") } cmd := activeCmd.Command if activeCmd.Args != "" { cmd += " " + activeCmd.Args } sess.WriteLine(fmt.Sprintf(" Queued active action (executes after free actions):")) sess.WriteLine(fmt.Sprintf(" %s", cmd)) } sess.WriteLine("") sess.WriteLine(fmt.Sprintf(" All queued actions take effect on the next game tick (600ms).")) sess.WriteLine(fmt.Sprintf(" Free actions stack. Only the most recent active action survives.")) var names []string for name := range g.activeQueue { names = append(names, name) } sort.Strings(names) pos := 0 for i, name := range names { if name == p.Name { pos = i + 1 break } } if pos > 0 && len(names) > 1 { sess.WriteLine(fmt.Sprintf("\n Your active action will resolve as queue position #%d of %d.", pos, len(names))) } }