package game import ( "fmt" "thehouseoficarus/internal/action" "thehouseoficarus/internal/net" "thehouseoficarus/internal/player" ) func (g *Game) doCook(sess *net.Session, input string) { p := sess.Player.(*player.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) } } if len(recipes) == 0 { sess.WriteLine("You can't cook 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, fmt.Sprintf("What would you like to cook on the %s?", stationName), names) } func (g *Game) showCookMenu(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 != "cooking" { continue } if !stationMatch(stationDefID, r.Station) { continue } if seen[r.ID] { continue } if !r.HasAllItems(p.HasItem) { 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 cook.") return } if len(entries) == 1 { if p.OptionBool("cook_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, fmt.Sprintf("What would you like to cook on the %s?", stationName), names) sess.PendingMenu = entryMenuData(entries) } func (g *Game) recipeName(sess *net.Session, r *action.RecipeDef) string { if r.Output != "" { if def, err := g.ItemStore.Load(r.Output); err == nil { return g.itemColorize(sess, def, def.Name) } } return r.DisplayName() }