aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_cook.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-17 21:13:07 -0400
committerhistoria <[not public]>2026-06-17 21:13:07 -0400
commitec2e94e3463654a6288464a4c070b48ef9bf7368 (patch)
tree3c5df0f9a6a5968fa4c725a7d331825883ae798c /internal/game/cmd_cook.go
parenteef5ddaa94f8cff6010d092c30fed53d2be01524 (diff)
downloadthehouseoficarus-ec2e94e3463654a6288464a4c070b48ef9bf7368.tar.gz
feat: smithing added, item/object interaction reworked. recipes and menus refactored.
Diffstat (limited to 'internal/game/cmd_cook.go')
-rw-r--r--internal/game/cmd_cook.go158
1 files changed, 20 insertions, 138 deletions
diff --git a/internal/game/cmd_cook.go b/internal/game/cmd_cook.go
index 054a4b0..ce33ccd 100644
--- a/internal/game/cmd_cook.go
+++ b/internal/game/cmd_cook.go
@@ -2,25 +2,18 @@ package game
import (
"fmt"
- "strconv"
- "strings"
"thehouseoficarus/internal/action"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/player"
)
-type cookableEntry struct {
- ItemName string
- Recipe action.RecipeDef
-}
-
func (g *Game) doCook(sess *net.Session, input string) {
p := sess.Player.(*player.Player)
g.CancelAction(p)
- stationName := g.findCookingStation(p.RoomID)
- if stationName == "" {
+ stationDefID, stationName := g.findStation(p.RoomID, []string{"fire", "cooking_range"})
+ if stationDefID == "" {
sess.WriteLine("You need a fire or cooking range to cook.")
return
}
@@ -32,7 +25,7 @@ func (g *Game) doCook(sess *net.Session, input string) {
}
if input == "" {
- g.showCookMenu(sess, p, allRecipes, stationName)
+ g.showCookMenu(sess, p, allRecipes, stationDefID, stationName)
return
}
@@ -61,24 +54,23 @@ func (g *Game) doCook(sess *net.Session, input string) {
if r.Type != "cooking" {
continue
}
- if stationOK(stationName, r.Station) && r.MatchesEntry(itemID) && r.HasAllItems(p.HasItem) {
+ 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 here.")
+ sess.WriteLine("You can't cook that.")
return
}
if len(recipes) == 1 {
- g.startCook(sess, p, &recipes[0], stationName)
+ g.promptHowMany(sess, recipes[0].ID)
return
}
- sess.PendingRecipeItem = itemID
- sess.PendingCookMenu = recipesToMenuData(recipes)
- sess.State = net.StateCookRecipe
+ sess.PendingMenu = recipeMenuData(recipes)
+ sess.State = net.StateRecipeChoice
sess.WriteLine(fmt.Sprintf("\nWhat would you like to cook on the %s?", stationName))
for i, r := range recipes {
sess.WriteLine(fmt.Sprintf(" %d) %s", i+1, g.recipeName(sess, &r)))
@@ -86,15 +78,15 @@ func (g *Game) doCook(sess *net.Session, input string) {
sess.WriteLine(fmt.Sprintf(" %d) Nothing", len(recipes)+1))
}
-func (g *Game) showCookMenu(sess *net.Session, p *player.Player, allRecipes []action.RecipeDef, stationName string) {
+func (g *Game) showCookMenu(sess *net.Session, p *player.Player, allRecipes []action.RecipeDef, stationDefID, stationName string) {
seen := make(map[string]bool)
- var cookables []cookableEntry
+ var entries []recipeEntry
for _, r := range allRecipes {
if r.Type != "cooking" {
continue
}
- if !stationOK(stationName, r.Station) {
+ if !stationMatch(stationDefID, r.Station) {
continue
}
if seen[r.ID] {
@@ -104,28 +96,26 @@ func (g *Game) showCookMenu(sess *net.Session, p *player.Player, allRecipes []ac
continue
}
seen[r.ID] = true
- cookables = append(cookables, cookableEntry{g.recipeName(sess, &r), r})
+ entries = append(entries, recipeEntry{g.recipeName(sess, &r), r})
}
- if len(cookables) == 0 {
+ if len(entries) == 0 {
sess.WriteLine("You don't have anything you can cook.")
return
}
- if len(cookables) == 1 {
- g.startCook(sess, p, &cookables[0].Recipe, stationName)
+ if len(entries) == 1 {
+ g.promptHowMany(sess, entries[0].Recipe.ID)
return
}
- sess.PendingRecipeItem = ""
- sess.State = net.StateCookRecipe
+ sess.State = net.StateRecipeChoice
sess.WriteLine(fmt.Sprintf("\nWhat would you like to cook on the %s?", stationName))
- for i, c := range cookables {
- sess.WriteLine(fmt.Sprintf(" %d) %s", i+1, c.ItemName))
+ for i, e := range entries {
+ sess.WriteLine(fmt.Sprintf(" %d) %s", i+1, e.ItemName))
}
- sess.WriteLine(fmt.Sprintf(" %d) Nothing", len(cookables)+1))
-
- sess.PendingCookMenu = makeCookMenuData(cookables)
+ sess.WriteLine(fmt.Sprintf(" %d) Nothing", len(entries)+1))
+ sess.PendingMenu = entryMenuData(entries)
}
func (g *Game) recipeName(sess *net.Session, r *action.RecipeDef) string {
@@ -136,111 +126,3 @@ func (g *Game) recipeName(sess *net.Session, r *action.RecipeDef) string {
}
return r.DisplayName()
}
-
-func makeCookMenuData(cookables []cookableEntry) []map[string]string {
- out := make([]map[string]string, len(cookables))
- for i, c := range cookables {
- out[i] = map[string]string{"recipe_id": c.Recipe.ID}
- }
- return out
-}
-
-func recipesToMenuData(recipes []action.RecipeDef) []map[string]string {
- out := make([]map[string]string, len(recipes))
- for i, r := range recipes {
- out[i] = map[string]string{"recipe_id": r.ID}
- }
- return out
-}
-
-func stationOK(stationName string, recipeStations []string) bool {
- if len(recipeStations) == 0 {
- return false
- }
- for _, rs := range recipeStations {
- if (rs == "fire" && stationName == "fire") || (rs == "cooking_range" && stationName == "cooking range") {
- return true
- }
- }
- return false
-}
-
-func (g *Game) findCookingStation(roomID int) string {
- for _, obj := range g.World.AllObjInstances(roomID) {
- if obj.Depleted {
- continue
- }
- if obj.DefID == "fire" {
- return "fire"
- }
- if obj.DefID == "cooking_range" {
- return "cooking range"
- }
- }
- return ""
-}
-
-func (g *Game) handleCookRecipe(sess *net.Session, input string) {
- p := sess.Player.(*player.Player)
- input = strings.TrimSpace(input)
- if input == "" {
- return
- }
-
- choice, err := strconv.Atoi(input)
- if err != nil {
- sess.State = net.StateGame
- sess.PendingRecipeItem = ""
- sess.PendingCookMenu = nil
- sess.WriteLine("You decide not to cook anything.")
- g.reprompt(sess)
- return
- }
-
- if len(sess.PendingCookMenu) > 0 {
- menuData := sess.PendingCookMenu
- sess.PendingCookMenu = nil
- if choice <= 0 || choice > len(menuData)+1 {
- sess.WriteLine("Invalid choice.")
- return
- }
- sess.State = net.StateGame
- if choice == len(menuData)+1 {
- sess.WriteLine("You decide not to cook anything.")
- g.reprompt(sess)
- return
- }
- entry := menuData[choice-1]
-
- if cid, ok := entry["combine_item"]; ok {
- def, err := g.ItemStore.Load(cid)
- if err == nil {
- p := sess.Player.(*player.Player)
- g.produceCombined(sess, p, def)
- }
- g.reprompt(sess)
- return
- }
-
- all, err := g.RecipeStore.LoadAll()
- if err != nil {
- g.reprompt(sess)
- return
- }
- for _, r := range all {
- if r.ID == entry["recipe_id"] {
- stationName := "inventory"
- if len(r.Station) > 0 {
- stationName = g.findCookingStation(p.RoomID)
- }
- g.startCook(sess, p, &r, stationName)
- return
- }
- }
- g.reprompt(sess)
- return
- }
-
- sess.State = net.StateGame
- g.reprompt(sess)
-}