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/action_production.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/action_production.go')
| -rw-r--r-- | internal/game/action_production.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/internal/game/action_production.go b/internal/game/action_production.go index 0b8ca45..d4e2274 100644 --- a/internal/game/action_production.go +++ b/internal/game/action_production.go @@ -41,6 +41,58 @@ func (g *Game) promptHowMany(sess *net.Session, recipeID string) { sess.Write("How many (return for all)?: ") } +type recipeSelection struct { + Recipe *action.RecipeDef + Count int +} + +func (g *Game) resolveRecipeByInput(input string, recipes []action.RecipeDef, lastRecipeID string) (sel recipeSelection, errMsg string) { + if input == "" { + if lastRecipeID == "" { + return sel, "never_mind" + } + for i := range recipes { + if recipes[i].ID == lastRecipeID { + sel.Recipe = &recipes[i] + return sel, "" + } + } + return sel, "never_mind" + } + + qty, productName := parseQty(input) + productName = strings.TrimSpace(productName) + + if idx, err := strconv.Atoi(productName); err == nil && idx > 0 && idx <= len(recipes) { + sel.Recipe = &recipes[idx-1] + sel.Count = qty + return sel, "" + } + + 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 { + sel.Recipe = &recipes[i] + sel.Count = qty + } + matchCount++ + } + } + if matchCount > 1 { + return sel, "ambiguous" + } + if sel.Recipe == nil { + return sel, "never_mind" + } + return sel, "" +} + func (g *Game) showMenuTable(sess *net.Session, title string, names []string) { p := sess.Player.(*player.Player) tbl := &Table{Title: title} @@ -129,6 +181,7 @@ func (g *Game) buildCombineRecipe(def *object.ItemDef) *action.RecipeDef { func (g *Game) startProduction(sess *net.Session, p *player.Player, recipe *action.RecipeDef, actionType, displayVerb, startMsg, endMsg string, count int) { g.CancelAction(p) + g.CancelBackgroundAction(p) if recipe.Skill != "" { skillLevel := p.Level(player.SkillName(recipe.Skill)) |
