package game import ( "fmt" "thehouseoficarus/internal/action" "thehouseoficarus/internal/net" "thehouseoficarus/internal/player" ) func (g *Game) doSmelt(sess *net.Session, input string) { p := sess.Player.(*player.Player) g.CancelAction(p) stationDefID, stationName := g.findStation(p.RoomID, []string{"furnace"}) if stationDefID == "" { sess.WriteLine("You need a furnace to smelt.") return } allRecipes, err := g.RecipeStore.LoadAll() if err != nil { sess.WriteLine("Error loading recipes.") return } if input == "" { g.showSmeltMenu(sess, p, allRecipes, stationDefID, stationName) return } matches := g.findInventoryMatches(input, p) if len(matches) == 0 { sess.WriteLine(fmt.Sprintf("You don't have any '%s'.", input)) return } unique := uniqueItemNames(matches) if len(unique) > 1 { g.showWhichOne(sess, matches) return } itemID := matches[0].ID var recipes []action.RecipeDef for _, r := range allRecipes { 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 { 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(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) } func (g *Game) showSmeltMenu(sess *net.Session, p *player.Player, allRecipes []action.RecipeDef, stationDefID, stationName string) { seen := make(map[string]bool) var entries []recipeEntry 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 { 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 } 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) sess.PendingMenu = entryMenuData(entries) }