package game import ( "fmt" "strings" "thehouseoficarus/internal/item" "thehouseoficarus/internal/net" "thehouseoficarus/internal/player" ) func (g *Game) executeCook(sess *net.Session, args []string, rawInput string) { g.doCook(sess, strings.Join(args, " ")) } func (g *Game) doCook(sess *net.Session, input string) { p := sess.Player g.cancelAction(p) stationDefID, stationName := g.findStation(p.RoomID, []string{"fire", "cooking_range"}) if stationDefID == "" { sess.WriteLine("You need a fire or cooking range to cook.") return } items := g.CraftIndex.ByType("cooking") if input == "" { g.showCookMenu(sess, p, items, stationDefID, stationName) return } qty, itemName := parseQty(input) _ = qty matches := g.findInventoryMatches(itemName, p) if len(matches) == 0 { sess.WriteLine(fmt.Sprintf("You don't have any '%s'.", itemName)) 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) && craftHasAllItems(c, p.HasItem) { recipes = append(recipes, item) } } title := fmt.Sprintf("What would you like to cook on the %s?", stationName) g.showRecipeChoice(sess, p, recipes, "You can't cook that.", title, "") } func (g *Game) showCookMenu(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] { continue } if !craftHasAllItems(c, p.HasItem) { continue } seen[item.ID] = true recipes = append(recipes, item) } title := fmt.Sprintf("What would you like to cook on the %s?", stationName) g.showRecipeChoice(sess, p, recipes, "You don't have anything you can cook.", title, "cook_all") }