diff options
| author | historia <[not public]> | 2026-06-18 02:34:56 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-18 02:34:56 -0400 |
| commit | fae979b75e37b6ad57e57062a1b637a37ec87174 (patch) | |
| tree | 53daaa52b5f844b5b1a50a1bad909cafdb63eabc /internal/game/cmd_smith.go | |
| parent | 1a9a486ca57f4de4fd1d8f00ee1a2a421f9d2273 (diff) | |
| download | thehouseoficarus-fae979b75e37b6ad57e57062a1b637a37ec87174.tar.gz | |
cleaned up various crafting menus
Diffstat (limited to 'internal/game/cmd_smith.go')
| -rw-r--r-- | internal/game/cmd_smith.go | 66 |
1 files changed, 45 insertions, 21 deletions
diff --git a/internal/game/cmd_smith.go b/internal/game/cmd_smith.go index 30dcddc..7fc14d2 100644 --- a/internal/game/cmd_smith.go +++ b/internal/game/cmd_smith.go @@ -3,6 +3,7 @@ package game import ( "fmt" "sort" + "strconv" "strings" "thehouseoficarus/internal/action" @@ -10,6 +11,7 @@ import ( "thehouseoficarus/internal/net" "thehouseoficarus/internal/object" "thehouseoficarus/internal/player" + "thehouseoficarus/internal/world" ) func (g *Game) doSmith(sess *net.Session, input string) { @@ -41,10 +43,7 @@ func (g *Game) doSmith(sess *net.Session, input string) { } unique := uniqueItemNames(matches) if len(unique) > 1 { - sess.WriteLine("Which one?") - for _, name := range unique { - sess.WriteLine(fmt.Sprintf(" - %s", name)) - } + g.showWhichOne(sess, matches) return } barID := matches[0].ID @@ -69,16 +68,16 @@ func (g *Game) doSmith(sess *net.Session, input string) { sess.PendingMenu = barMenuData(barTypes) sess.State = net.StateRecipeChoice - sess.WriteLine("\nWhich bars would you like to smith?") - for i, barID := range barTypes { + var names []string + for _, barID := range barTypes { def, _ := g.ItemStore.Load(barID) name := barID if def != nil { name = g.itemColorize(sess, def, def.Name) } - sess.WriteLine(fmt.Sprintf(" %d) %s", i+1, name)) + names = append(names, name) } - sess.WriteLine(fmt.Sprintf(" %d) Nothing", len(barTypes)+1)) + g.showMenuTable(sess, "Which bars would you like to smith?", names) } func (g *Game) showSmithTable(sess *net.Session, p *player.Player, barID string, allRecipes []action.RecipeDef) { @@ -111,22 +110,31 @@ func (g *Game) showSmithTable(sess *net.Session, p *player.Player, barID string, tbl := &Table{ Title: titleCase(barName) + " Smithing", - Columns: []string{"Product", "Inputs", "Level Req."}, + Columns: []string{"#", "Product", "Inputs", "Level Req."}, } - for _, r := range recipes { + for i, r := range recipes { outDef, _ := g.ItemStore.Load(r.Output) productName := r.Output if outDef != nil { productName = outDef.Name } + outputQty := r.OutputQty + if outputQty <= 0 { + outputQty = 1 + } + if outDef != nil && outDef.Stackable && outputQty > 1 { + productName = fmt.Sprintf("%s x%d", productName, outputQty) + } + bars := barsRequired(r, barID) inputStr := "1 bar" if bars > 1 { inputStr = fmt.Sprintf("%d bars", bars) } levelStr := fmt.Sprint(r.Level) + numStr := fmt.Sprintf("%d", i+1) canMake := barCount >= bars && skillLevel >= r.Level if canMake { @@ -135,9 +143,10 @@ func (g *Game) showSmithTable(sess *net.Session, p *player.Player, barID string, productName = color.Render(mode, dimSpec, productName) inputStr = color.Render(mode, dimSpec, inputStr) levelStr = color.Render(mode, dimSpec, levelStr) + numStr = color.Render(mode, dimSpec, numStr) } - tbl.Rows = append(tbl.Rows, []string{productName, inputStr, levelStr}) + tbl.Rows = append(tbl.Rows, []string{numStr, productName, inputStr, levelStr}) } unicode := p.OptionBool("unicode") @@ -190,6 +199,10 @@ func (g *Game) handleSmithProduct(sess *net.Session, input string) { } } + sort.Slice(recipes, func(i, j int) bool { + return recipes[i].Level < recipes[j].Level + }) + var targetRecipe *action.RecipeDef var count int @@ -216,18 +229,29 @@ func (g *Game) handleSmithProduct(sess *net.Session, input string) { } else { qty, productName := parseQty(input) count = qty - productName = strings.ToLower(strings.TrimSpace(productName)) + productName = strings.TrimSpace(productName) - for i := range recipes { - outDef, _ := g.ItemStore.Load(recipes[i].Output) - name := recipes[i].Output - if outDef != nil { - name = outDef.Name + if idx, err := strconv.Atoi(productName); err == nil && idx > 0 && idx <= len(recipes) { + targetRecipe = &recipes[idx-1] + } else { + matchCount := 0 + for i := range recipes { + outDef, _ := g.ItemStore.Load(recipes[i].Output) + name := recipes[i].Output + if outDef != nil { + name = outDef.Name + } + if world.WordPrefixMatch(productName, name) { + if matchCount == 0 { + targetRecipe = &recipes[i] + } + matchCount++ + } } - lower := strings.ToLower(name) - if lower == productName || strings.HasPrefix(lower, productName) { - targetRecipe = &recipes[i] - break + if matchCount > 1 { + sess.WriteLine("That's ambiguous.") + g.reprompt(sess) + return } } |
