aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_mods.go
blob: 26b0e9552b79b40b5891ce73de94dcc1ff5ae00f (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package game

import (
	"fmt"
	"sort"

	"thehouseoficarus/internal/color"
	"thehouseoficarus/internal/net"
	"thehouseoficarus/internal/player"
	"thehouseoficarus/internal/ui"
)

func (g *Game) executeMods(sess *net.Session, args []string, rawInput string) {
	showAll := len(args) > 0 && args[0] == "all"
	g.doMods(sess, showAll)
}

func (g *Game) doMods(sess *net.Session, showAll bool) {
	p := sess.Player
	sciLevel := p.Level(player.Science)
	mode := g.colorMode(sess)

	categories := []struct {
		Name string
		Cat  ModCategory
	}{
		{"Combat", ModCombat},
		{"Utility", ModUtility},
		{"Transport", ModTransport},
		{"Enchantment", ModEnchant},
	}

	sess.WriteLine("")
	anyMods := false
	for _, cat := range categories {
		var catMods []*ModDef
		for _, m := range AllMods {
			if m.Category != cat.Cat {
				continue
			}
			if !showAll && m.Level > sciLevel {
				continue
			}
			catMods = append(catMods, m)
		}
		if len(catMods) == 0 {
			continue
		}
		anyMods = true

		sort.Slice(catMods, func(i, j int) bool {
			return catMods[i].Level < catMods[j].Level
		})

		t := &ui.Table{
			Title: cat.Name,
			Columns: []string{
				color.Render(mode, color.Parse("49"), "Module"),
				color.Render(mode, color.Parse("F5"), "Level"),
				color.Render(mode, color.Parse("B3"), "Cost"),
				color.Render(mode, color.Parse("B3"), "XP"),
			},
		}

		for _, m := range catMods {
			unlocked := m.Level <= sciLevel
			levelStr := fmt.Sprintf("Lv %d", m.Level)
			costStr := g.junkCostString(p, m)
			xpStr := fmt.Sprintf("%d XP", m.BaseXP)
			if m.ID == "transport_home" && p.HomeTransportCooldown > 0 {
				nameStr := fmt.Sprintf("%s (%d ticks)", m.Name, p.HomeTransportCooldown)
				t.Rows = append(t.Rows, []string{
					g.colorize(sess, "dim", nameStr),
					g.colorize(sess, "dim", levelStr),
					g.colorize(sess, "dim", costStr),
					g.colorize(sess, "dim", xpStr),
				})
			} else if unlocked {
				t.Rows = append(t.Rows, []string{
					color.Render(mode, color.Parse("49"), m.Name),
					color.Render(mode, color.Parse("F5"), levelStr),
					color.Render(mode, color.Parse("B3"), costStr),
					color.Render(mode, color.Parse("B3"), xpStr),
				})
			} else {
				t.Rows = append(t.Rows, []string{
					g.colorize(sess, "dim", m.Name),
					g.colorize(sess, "dim", levelStr),
					g.colorize(sess, "dim", costStr),
					g.colorize(sess, "dim", xpStr),
				})
			}
		}

		for _, line := range t.Render(p.OptionBool("unicode"), p.OptionInt("wrap_width")) {
			sess.WriteLine(line)
		}
		sess.WriteLine("")
	}

	if !anyMods {
		sess.WriteLine("No modules found.")
	}

	if p.AutotriggerMod != "" {
		mod := GetMod(p.AutotriggerMod)
		if mod != nil {
			sess.WriteLine(fmt.Sprintf("Autotrigger: %s", g.colorize(sess, "science_mod", mod.Name)))
		}
	}
}