aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_queued.go
blob: 040ff316f4ae56375d8af64f901e7b0910f4b92e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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)))
	}
}