aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_style.go
blob: 043c65f500d0ef3dd263bb16c794d03db6b3f004 (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
package game

import (
	"fmt"
	"strings"

	"thehouseoficarus/internal/net"
	"thehouseoficarus/internal/player"
)

func (g *Game) doStyle(sess *net.Session, input string) {
	p := sess.Player

	styles := []string{"accurate", "aggressive", "defensive", "balanced"}
	if input == "" {
		sess.WriteLine("Combat styles:")
		for _, s := range styles {
			marker := " "
			if string(p.AttackStyle) == s {
				marker = "*"
			}
			sess.WriteLine(fmt.Sprintf("  %s %s", marker, s))
		}
		return
	}

	input = strings.ToLower(input)
	var matches []string
	for _, s := range styles {
		if strings.HasPrefix(s, input) {
			matches = append(matches, s)
		}
	}
	if len(matches) == 1 {
		p.AttackStyle = player.AttackStyle(matches[0])
		g.AccountStore.SaveCharacter(p)
		sess.WriteLine(fmt.Sprintf("Combat style set to %s.", matches[0]))
		return
	}
	if len(matches) > 1 {
		sess.WriteLine(fmt.Sprintf("Ambiguous style: %s. Choices: %s", input, strings.Join(matches, ", ")))
		return
	}
	sess.WriteLine(fmt.Sprintf("Unknown style: %s. Choices: accurate, aggressive, defensive, balanced", input))
}

func (g *Game) executeStyle(sess *net.Session, args []string, rawInput string) {
	if len(args) == 0 {
		g.doStyle(sess, "")
	} else {
		g.doStyle(sess, args[0])
	}
}