package game import ( "fmt" "sort" "strings" "thehouseoficarus/internal/color" "thehouseoficarus/internal/net" "thehouseoficarus/internal/player" ) func (g *Game) doMods(sess *net.Session) { p := sess.Player.(*player.Player) mode := g.colorMode(sess) sciLevel := p.Level(player.Science) categories := []struct { Name string Cat ModCategory }{ {"Combat", ModCombat}, {"Processing", ModProcessing}, {"Utility", ModUtility}, {"Transport", ModTransport}, {"Enchantment", ModEnchant}, } sess.WriteLine("") anyMods := false for _, cat := range categories { var mods []*ModDef for _, m := range AllMods { if m.Category == cat.Cat && m.Level <= sciLevel { mods = append(mods, m) } } if len(mods) == 0 { continue } sort.Slice(mods, func(i, j int) bool { return mods[i].Level < mods[j].Level }) t := &Table{Title: cat.Name + " Mods", Columns: []string{ color.Render(mode, color.Parse("75"), "Mod"), color.Render(mode, color.Parse("230"), "Lv"), color.Render(mode, color.Parse("245"), "Cost"), color.Render(mode, color.Parse("222"), "XP"), }} for _, m := range mods { costStr := g.modCostDisplay(p, m) xpStr := fmt.Sprintf("%.1f", m.BaseXP) if m.MaxHit > 0 { xpStr += fmt.Sprintf(" (max %d)", m.MaxHit) } t.Rows = append(t.Rows, []string{ color.Render(mode, color.Parse("75"), m.Name), color.Render(mode, color.Parse("230"), fmt.Sprint(m.Level)), color.Render(mode, color.Parse("245"), costStr), color.Render(mode, color.Parse("222"), xpStr), }) } for _, line := range t.Render(p.OptionBool("unicode")) { sess.WriteLine(line) } anyMods = true } if !anyMods { sess.WriteLine("You don't know any mods yet. Train Science to unlock mods.") } if p.AutocastMod != "" { mod := GetMod(p.AutocastMod) if mod != nil { sess.WriteLine(fmt.Sprintf("\nAutocast: %s", g.colorize(sess, "science_mod", mod.Name))) } } } func (g *Game) modCostDisplay(p *player.Player, mod *ModDef) string { cost := g.effectiveJunkCost(p, mod) if len(cost) == 0 { return "free" } var parts []string keys := make([]string, 0, len(cost)) for k := range cost { keys = append(keys, k) } sort.Strings(keys) for _, itemID := range keys { qty := cost[itemID] def, _ := g.ItemStore.Load(itemID) name := itemID if def != nil { name = def.Name } if qty > 1 { parts = append(parts, fmt.Sprintf("%d %s", qty, name)) } else { parts = append(parts, name) } } return strings.Join(parts, ", ") }