diff options
| author | historia <[not public]> | 2026-06-18 18:50:54 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-18 18:50:54 -0400 |
| commit | 17e7725f252c7f5d3be2e9c37d62751c631f196f (patch) | |
| tree | 40698c5c95cb21302adbb8cd021bd8d049b6fce1 /internal/game/cmd_smith.go | |
| parent | fae979b75e37b6ad57e57062a1b637a37ec87174 (diff) | |
| download | thehouseoficarus-17e7725f252c7f5d3be2e9c37d62751c631f196f.tar.gz | |
feat: fletching added including zero-time bolt feathering, which probably will break lots of things
Diffstat (limited to 'internal/game/cmd_smith.go')
| -rw-r--r-- | internal/game/cmd_smith.go | 103 |
1 files changed, 40 insertions, 63 deletions
diff --git a/internal/game/cmd_smith.go b/internal/game/cmd_smith.go index 7fc14d2..f2787a5 100644 --- a/internal/game/cmd_smith.go +++ b/internal/game/cmd_smith.go @@ -3,7 +3,6 @@ package game import ( "fmt" "sort" - "strconv" "strings" "thehouseoficarus/internal/action" @@ -11,7 +10,6 @@ import ( "thehouseoficarus/internal/net" "thehouseoficarus/internal/object" "thehouseoficarus/internal/player" - "thehouseoficarus/internal/world" ) func (g *Game) doSmith(sess *net.Session, input string) { @@ -62,6 +60,12 @@ func (g *Game) doSmith(sess *net.Session, input string) { } if len(barTypes) == 1 { + if p.OptionBool("smith_all") { + if recipe := g.findSingleSmithRecipe(p, barTypes[0], allRecipes); recipe != nil { + g.startProductionFromRecipe(sess, p, recipe, 0) + return + } + } g.showSmithTable(sess, p, barTypes[0], allRecipes) return } @@ -203,72 +207,28 @@ func (g *Game) handleSmithProduct(sess *net.Session, input string) { return recipes[i].Level < recipes[j].Level }) - var targetRecipe *action.RecipeDef - var count int - - if input == "" { - lastFlag := fmt.Sprintf("last_smith_%s", barID) - lastRecipeID, _ := p.Flags[lastFlag].(string) - if lastRecipeID == "" { - sess.WriteLine("Never mind.") - g.reprompt(sess) - return - } - for i := range recipes { - if recipes[i].ID == lastRecipeID { - targetRecipe = &recipes[i] - break - } - } - if targetRecipe == nil { - sess.WriteLine("Never mind.") - g.reprompt(sess) - return - } - count = 0 - } else { - qty, productName := parseQty(input) - count = qty - productName = strings.TrimSpace(productName) - - 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++ - } - } - if matchCount > 1 { - sess.WriteLine("That's ambiguous.") - g.reprompt(sess) - return - } - } + lastFlag := fmt.Sprintf("last_smith_%s", barID) + lastRecipeID, _ := p.Flags[lastFlag].(string) - if targetRecipe == nil { - sess.WriteLine("Never mind.") - g.reprompt(sess) - return - } + sel, errMsg := g.resolveRecipeByInput(input, recipes, lastRecipeID) + switch errMsg { + case "ambiguous": + sess.WriteLine("That's ambiguous.") + g.reprompt(sess) + return + case "never_mind": + sess.WriteLine("Never mind.") + g.reprompt(sess) + return } skillLevel := p.Level(player.Smithing) - if skillLevel < targetRecipe.Level { - sess.WriteLine(fmt.Sprintf("You need level %d smithing to make that.", targetRecipe.Level)) + if skillLevel < sel.Recipe.Level { + sess.WriteLine(fmt.Sprintf("You need level %d smithing to make that.", sel.Recipe.Level)) g.reprompt(sess) return } - if !targetRecipe.HasAllItemsQty(p.CountItem) { + if !sel.Recipe.HasAllItemsQty(p.CountItem) { sess.WriteLine("You don't have enough bars.") g.reprompt(sess) return @@ -277,10 +237,10 @@ func (g *Game) handleSmithProduct(sess *net.Session, input string) { if p.Flags == nil { p.Flags = make(map[string]any) } - p.Flags[fmt.Sprintf("last_smith_%s", barID)] = targetRecipe.ID + p.Flags[lastFlag] = sel.Recipe.ID g.AccountStore.SaveCharacter(p) - g.startProductionFromRecipe(sess, p, targetRecipe, count) + g.startProductionFromRecipe(sess, p, sel.Recipe, sel.Count) } func (g *Game) hasToolType(p *player.Player, toolType string) bool { @@ -355,6 +315,23 @@ func barMenuData(barIDs []string) []map[string]string { return out } +func (g *Game) findSingleSmithRecipe(p *player.Player, barID string, allRecipes []action.RecipeDef) *action.RecipeDef { + var makeable []*action.RecipeDef + skillLevel := p.Level(player.Smithing) + for i, r := range allRecipes { + if r.Type != "smithing" || !r.MatchesEntry(barID) { + continue + } + if skillLevel >= r.Level && r.HasAllItemsQty(p.CountItem) { + makeable = append(makeable, &allRecipes[i]) + } + } + if len(makeable) == 1 { + return makeable[0] + } + return nil +} + func titleCase(s string) string { words := strings.Fields(s) for i, w := range words { |
