aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_queued.go
blob: 325d1978a5eb68d112a719e0fec2f825a59a75d9 (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
67
68
69
70
71
72
package game

import (
	"fmt"

	"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)
	consumeCmd, hasConsume := g.queue.PeekConsume(p.Name)

	if len(freeCmds) == 0 && !hasActive && !hasConsume {
		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("  Queued active action (executes after free actions):")
		sess.WriteLine("    " + cmd)
	}

	if consumeCmd != nil {
		if len(freeCmds) > 0 || activeCmd != nil {
			sess.WriteLine("")
		}
		cmd := consumeCmd.Command
		if consumeCmd.Args != "" {
			cmd += " " + consumeCmd.Args
		}
		sess.WriteLine("  Queued consume action (executes in combat):")
		sess.WriteLine("    " + cmd)
	}

	sess.WriteLine("")
	sess.WriteLine(fmt.Sprintf("  All queued actions take effect on the next game tick (%dms).", g.Ticks.TickLengthMilliseconds()))
	sess.WriteLine("  Free actions stack. Only the most recent active action survives.")

	// ActivePositions returns the names in resolution order and the caller's
	// 1-based position, so there is nothing to recompute here.
	names, pos := g.queue.ActivePositions(p.Name)
	if pos > 0 && len(names) > 1 {
		sess.WriteLine(fmt.Sprintf("  Your active action will resolve as queue position #%d of %d.", pos, len(names)))
	}
}