aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_tech.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/cmd_tech.go')
-rw-r--r--internal/game/cmd_tech.go196
1 files changed, 196 insertions, 0 deletions
diff --git a/internal/game/cmd_tech.go b/internal/game/cmd_tech.go
new file mode 100644
index 0000000..f51ccd9
--- /dev/null
+++ b/internal/game/cmd_tech.go
@@ -0,0 +1,196 @@
+package game
+
+import (
+ "fmt"
+ "strings"
+
+ "thehouseoficarus/internal/color"
+ "thehouseoficarus/internal/net"
+ "thehouseoficarus/internal/player"
+)
+
+func (g *Game) doTech(sess *net.Session, input string) {
+ p := sess.Player.(*player.Player)
+ techLevel := p.Level(player.Technology)
+
+ if techLevel < 1 {
+ sess.WriteLine("\nYou 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("\nUnknown tech: %s", input))
+ return
+ }
+ if len(matches) > 1 {
+ var names []string
+ for _, m := range matches {
+ names = append(names, m.Name)
+ }
+ sess.WriteLine(fmt.Sprintf("\nAmbiguous 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("\nUnknown tech.")
+ return
+ }
+
+ techLevel := p.Level(player.Technology)
+
+ if p.HasActiveTech(techID) {
+ p.DeactivateTech(techID)
+ sess.WriteLine(fmt.Sprintf("\n%s deactivated.", def.Name))
+ return
+ }
+
+ if techLevel < def.Level {
+ sess.WriteLine(fmt.Sprintf("\nYou need level %d Technology to use %s.", def.Level, def.Name))
+ return
+ }
+
+ if p.Battery <= 0 {
+ sess.WriteLine("\nYour battery is depleted!")
+ return
+ }
+
+ deactivated := g.deactivateGroup(p, def.Group)
+ for _, name := range deactivated {
+ sess.WriteLine(fmt.Sprintf("\n%s deactivated.", name))
+ }
+
+ p.ActivateTech(techID)
+ sess.WriteLine(fmt.Sprintf("\n%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.(*player.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 := &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("\nNo 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("\nQuick tech: %s", name))
+ }
+ return
+ }
+
+ matches := TechByPrefixMatch(strings.ToLower(input))
+ if len(matches) == 0 {
+ sess.WriteLine(fmt.Sprintf("\nUnknown tech: %s", input))
+ return
+ }
+ if len(matches) > 1 {
+ var names []string
+ for _, m := range matches {
+ names = append(names, m.Name)
+ }
+ sess.WriteLine(fmt.Sprintf("\nAmbiguous tech: %s. Matches: %s", input, strings.Join(names, ", ")))
+ return
+ }
+
+ p.QuickTech = matches[0].ID
+ g.AccountStore.SaveCharacter(p)
+ sess.WriteLine(fmt.Sprintf("\nQuick tech set to %s.", matches[0].Name))
+}