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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
package game
import (
"fmt"
"strings"
"thehouseoficarus/internal/color"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/player"
"thehouseoficarus/internal/ui"
)
func (g *Game) doTech(sess *net.Session, input string) {
p := sess.Player
techLevel := p.Level(player.Technology)
if techLevel < 1 {
sess.WriteLine("You need at least level 1 Technology to use tech.")
return
}
input = strings.TrimSpace(input)
if input == "" {
if p.QuickTech == "" {
g.doTechList(sess)
return
}
g.toggleTech(sess, p, p.QuickTech)
return
}
lower := strings.ToLower(input)
if lower == "list" {
g.doTechList(sess)
return
}
if strings.HasPrefix(lower, "quick ") {
name := strings.TrimSpace(input[6:])
g.doTechQuick(sess, p, name)
return
}
matches := TechByPrefixMatch(lower)
if len(matches) == 0 {
sess.WriteLine(fmt.Sprintf("Unknown tech: %s", input))
return
}
if len(matches) > 1 {
var names []string
for _, m := range matches {
names = append(names, m.Name)
}
sess.WriteLine(fmt.Sprintf("Ambiguous tech: %s. Matches: %s", input, strings.Join(names, ", ")))
return
}
g.toggleTech(sess, p, matches[0].ID)
}
func (g *Game) toggleTech(sess *net.Session, p *player.Player, techID string) {
def := GetTechDef(techID)
if def == nil {
sess.WriteLine("Unknown tech.")
return
}
techLevel := p.Level(player.Technology)
if p.HasActiveTech(techID) {
p.DeactivateTech(techID)
sess.WriteLine(fmt.Sprintf("%s deactivated.", def.Name))
return
}
if techLevel < def.Level {
sess.WriteLine(fmt.Sprintf("You need level %d Technology to use %s.", def.Level, def.Name))
return
}
if p.Battery <= 0 {
sess.WriteLine("Your battery is depleted!")
return
}
deactivated := g.deactivateGroup(p, def.Group)
for _, name := range deactivated {
sess.WriteLine(fmt.Sprintf("%s deactivated.", name))
}
p.ActivateTech(techID)
sess.WriteLine(fmt.Sprintf("%s activated.", def.Name))
}
func (g *Game) deactivateGroup(p *player.Player, group string) []string {
if group == "" {
return nil
}
var deactivated []string
for id := range p.ActiveTechs {
def := GetTechDef(id)
if def != nil && def.Group == group {
p.DeactivateTech(id)
deactivated = append(deactivated, def.Name)
}
}
return deactivated
}
func (g *Game) doTechList(sess *net.Session) {
p := sess.Player
mode := g.colorMode(sess)
techLevel := p.Level(player.Technology)
sess.WriteLines(
"",
fmt.Sprintf("Battery: %s/%s",
g.colorize(sess, "battery", fmt.Sprintf("%.1f", p.Battery)),
color.Render(mode, color.Parse("230"), fmt.Sprintf("%.0f", p.MaxBattery())),
),
)
t := &ui.Table{Title: "Technology", Columns: []string{"Tech", "Level", "Drain/tick", "Effect", "Status"}}
for _, tech := range AllTechs {
status := ""
nameStr := tech.Name
if tech.Level <= techLevel {
if p.HasActiveTech(tech.ID) {
status = color.Render(mode, color.Parse("82"), "ON")
} else {
status = color.Render(mode, color.Parse("240"), "off")
}
nameStr = color.Render(mode, color.Parse("75"), tech.Name)
} else {
status = color.Render(mode, color.Parse("160"), "locked")
nameStr = color.Render(mode, color.Parse("240"), tech.Name)
}
effect := techEffectString(tech)
t.Rows = append(t.Rows, []string{
nameStr,
fmt.Sprint(tech.Level),
fmt.Sprintf("%.2f", tech.DrainRate),
effect,
status,
})
}
for _, line := range t.Render(p.OptionBool("unicode")) {
sess.WriteLine(line)
}
if p.QuickTech != "" {
qDef := GetTechDef(p.QuickTech)
if qDef != nil {
sess.WriteLine(fmt.Sprintf("\nQuick tech: %s", qDef.Name))
}
}
}
func (g *Game) doTechQuick(sess *net.Session, p *player.Player, input string) {
if input == "" {
if p.QuickTech == "" {
sess.WriteLine("No quick tech set. Usage: tech quick <name>")
} else {
def := GetTechDef(p.QuickTech)
name := p.QuickTech
if def != nil {
name = def.Name
}
sess.WriteLine(fmt.Sprintf("Quick tech: %s", name))
}
return
}
matches := TechByPrefixMatch(strings.ToLower(input))
if len(matches) == 0 {
sess.WriteLine(fmt.Sprintf("Unknown tech: %s", input))
return
}
if len(matches) > 1 {
var names []string
for _, m := range matches {
names = append(names, m.Name)
}
sess.WriteLine(fmt.Sprintf("Ambiguous tech: %s. Matches: %s", input, strings.Join(names, ", ")))
return
}
p.QuickTech = matches[0].ID
g.AccountStore.SaveCharacter(p)
sess.WriteLine(fmt.Sprintf("Quick tech set to %s.", matches[0].Name))
}
func (g *Game) executeTech(sess *net.Session, args []string, rawInput string) {
g.doTech(sess, strings.Join(args, " "))
}
|