From e4400c5f1e84c18d2126f2cb502ae10685977cbb Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Sat, 20 Jun 2026 03:20:01 -0400 Subject: refactor: combined all station crafting --- internal/game/cmd_smelt.go | 52 ++++++---------------------------------------- 1 file changed, 6 insertions(+), 46 deletions(-) (limited to 'internal/game/cmd_smelt.go') diff --git a/internal/game/cmd_smelt.go b/internal/game/cmd_smelt.go index a72cf53..f1ff4e2 100644 --- a/internal/game/cmd_smelt.go +++ b/internal/game/cmd_smelt.go @@ -53,69 +53,29 @@ func (g *Game) doSmelt(sess *net.Session, input string) { if r.Type != "smelting" || !stationMatch(stationDefID, r.Station) || !r.MatchesEntry(itemID) { continue } - if !r.HasAllItemsQty(p.CountItem) || p.Level(player.SkillName(r.EffectiveSkill())) < r.Level { + if !r.HasAllItemsQty(p.CountItem) || p.Level(player.SkillName(r.EffectiveSkill())) < r.Level { continue } recipes = append(recipes, r) } - if len(recipes) == 0 { - sess.WriteLine("You can't smelt that.") - return - } - - if len(recipes) == 1 { - g.promptHowMany(sess, recipes[0].ID) - return - } - - sess.PendingMenu = recipeMenuData(recipeDefIDs(recipes)) - sess.State = net.StateRecipeChoice - var names []string - for _, r := range recipes { - names = append(names, g.recipeName(sess, &r)) - } - g.showMenuTable(sess, "What would you like to smelt?", names) + g.showRecipeChoice(sess, p, recipes, "You can't smelt that.", "What would you like to smelt?", "") } func (g *Game) showSmeltMenu(sess *net.Session, p *player.Player, allRecipes []action.RecipeDef, stationDefID, stationName string) { seen := make(map[string]bool) - var entries []recipeEntry + var recipes []action.RecipeDef for _, r := range allRecipes { if r.Type != "smelting" || !stationMatch(stationDefID, r.Station) { continue } - if seen[r.ID] || !r.HasAllItemsQty(p.CountItem) || p.Level(player.SkillName(r.EffectiveSkill())) < r.Level { + if seen[r.ID] || !r.HasAllItemsQty(p.CountItem) || p.Level(player.SkillName(r.EffectiveSkill())) < r.Level { continue } seen[r.ID] = true - entries = append(entries, recipeEntry{g.recipeName(sess, &r), r}) - } - - if len(entries) == 0 { - sess.WriteLine("You don't have anything you can smelt.") - return - } - - if len(entries) == 1 { - if p.OptionBool("smelt_all") { - g.startProductionFromRecipe(sess, p, &entries[0].Recipe, 0) - return - } - g.promptHowMany(sess, entries[0].Recipe.ID) - return + recipes = append(recipes, r) } - sess.State = net.StateRecipeChoice - var names []string - for _, e := range entries { - names = append(names, e.ItemName) - } - g.showMenuTable(sess, "What would you like to smelt?", names) - ids := make([]string, len(entries)) - for i, e := range entries { - ids[i] = e.Recipe.ID - } - sess.PendingMenu = recipeMenuData(ids) + g.showRecipeChoice(sess, p, recipes, "You don't have anything you can smelt.", "What would you like to smelt?", "smelt_all") } -- cgit v1.2.3