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, g.resolveConstant(sess, "table_header_label"), "Module"), color.Render(mode, g.resolveConstant(sess, "table_header_detail"), "Level"), color.Render(mode, g.resolveConstant(sess, "table_header_xp"), "Cost"), color.Render(mode, g.resolveConstant(sess, "table_header_xp"), "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, g.resolveConstant(sess, "table_header_label"), m.Name), color.Render(mode, g.resolveConstant(sess, "table_header_detail"), levelStr), color.Render(mode, g.resolveConstant(sess, "table_header_xp"), costStr), color.Render(mode, g.resolveConstant(sess, "table_header_xp"), 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))) } } }