aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_queued.go
blob: 549c5fbea9158eb6e2c3402830ded4a1fc142fa8 (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"

	"thehouseoficarus/internal/net"
)

func (g *Game) executeQueued(sess *net.Session, args []string, rawInput string) {
	g.doQueued(sess)
}

func (g *Game) doQueued(sess *net.Session) {
	p := sess.Player

	freeCmds := g.queue.PeekFree(p.Name)
	activeCmd, hasActive := g.queue.PeekActive(p.Name)

	if len(freeCmds) == 0 && !hasActive {
		sess.WriteLine("No 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."))

	names, _ := g.queue.ActivePositions(p.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("  Your active action will resolve as queue position #%d of %d.", pos, len(names)))
	}
}