package game import ( "fmt" "strings" "thehouseoficarus/internal/item" "thehouseoficarus/internal/net" "thehouseoficarus/internal/player" ) func (g *Game) executeSmelt(sess *net.Session, args []string, rawInput string) { g.doSmelt(sess, strings.Join(args, " ")) } func (g *Game) doSmelt(sess *net.Session, input string) { p := sess.Player g.cancelAction(p) stationDefID, stationName := g.findStation(p.RoomID, []string{"furnace"}) if stationDefID == "" { sess.WriteLine("You need a furnace to smelt.") return } items := g.CraftIndex.BySubtype("smelting") if input == "" { g.showSmeltMenu(sess, p, items, 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 []*item.ItemDef for _, item := range items { c := item.FirstCraft() if !stationMatch(stationDefID, c.Station) || !craftMatchesEntry(c, itemID) { continue } if !craftHasAllItemsQty(c, p.CountItem) || p.Level(player.SkillName(c.EffectiveSkill())) < c.Level { continue } recipes = append(recipes, item) } 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, items []*item.ItemDef, stationDefID, stationName string) { seen := make(map[string]bool) var recipes []*item.ItemDef for _, item := range items { c := item.FirstCraft() if !stationMatch(stationDefID, c.Station) { continue } if seen[item.ID] || !craftHasAllItemsQty(c, p.CountItem) || p.Level(player.SkillName(c.EffectiveSkill())) < c.Level { continue } seen[item.ID] = true recipes = append(recipes, item) } g.showRecipeChoice(sess, p, recipes, "You don't have anything you can smelt.", "What would you like to smelt?", "smelt_all") }