aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_toggle.go
blob: 19c111c7cee079fe61e9f1ac8c9db2304960fa54 (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
package game

import (
	"fmt"
	"strings"

	"thirdcollapse/internal/net"
	"thirdcollapse/internal/player"
)

var toggles = []struct {
	Name        string
	Description string
}{
	{"description", "Long room descriptions"},
	{"tinymap", "Mini-map display"},
	{"xpdrops", "XP drop messages in combat"},
	{"exits", "Long exit display in look"},
	{"mobenter", "Messages when mobs enter the room"},
	{"mobleave", "Messages when mobs leave the room"},
	{"mobspawn", "Messages when mobs spawn in the area"},
	{"reserve", "Show full reserved item details"},
}

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

	if input == "" {
		sess.WriteLine("")
		for _, t := range toggles {
			status := "Off"
			if p.Toggles[t.Name] {
				status = "On"
			}
			sess.WriteLine(fmt.Sprintf("  %-12s  %-3s  %s", t.Name, status, t.Description))
		}
		g.AccountStore.SaveCharacter(p)
		return
	}

	for _, t := range toggles {
		if strings.ToLower(input) == t.Name {
			p.Toggles[t.Name] = !p.Toggles[t.Name]
			status := "Off"
			if p.Toggles[t.Name] {
				status = "On"
			}
			sess.WriteLine(fmt.Sprintf("\n%s %s.", t.Description, status))
			g.AccountStore.SaveCharacter(p)
			return
		}
	}
	sess.WriteLine(fmt.Sprintf("\nUnknown toggle: %s", input))
}