package game import ( "fmt" "strings" "thehouseoficarus/internal/action" "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 } allRecipes, err := g.RecipeStore.LoadAll() if err != nil { sess.WriteLine("Error loading recipes.") return } if input == "" { g.showCookMenu(sess, p, allRecipes, 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 []action.RecipeDef for _, r := range allRecipes { if r.Type != "cooking" { continue } if stationMatch(stationDefID, r.Station) && r.MatchesEntry(itemID) && r.HasAllItems(p.HasItem) { recipes = append(recipes, r) } } 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, allRecipes []action.RecipeDef, stationDefID, stationName string) { seen := make(map[string]bool) var recipes []action.RecipeDef for _, r := range allRecipes { if r.Type != "cooking" { continue } if !stationMatch(stationDefID, r.Station) { continue } if seen[r.ID] { continue } if !r.HasAllItems(p.HasItem) { continue } seen[r.ID] = true recipes = append(recipes, r) } 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") }