aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_cook.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/cmd_cook.go')
-rw-r--r--internal/game/cmd_cook.go42
1 files changed, 17 insertions, 25 deletions
diff --git a/internal/game/cmd_cook.go b/internal/game/cmd_cook.go
index 04c98bb..6dfbcce 100644
--- a/internal/game/cmd_cook.go
+++ b/internal/game/cmd_cook.go
@@ -4,8 +4,8 @@ import (
"fmt"
"strings"
- "thehouseoficarus/internal/action"
"thehouseoficarus/internal/net"
+ "thehouseoficarus/internal/object"
"thehouseoficarus/internal/player"
)
@@ -23,14 +23,10 @@ func (g *Game) doCook(sess *net.Session, input string) {
return
}
- allRecipes, err := g.RecipeStore.LoadAll()
- if err != nil {
- sess.WriteLine("Error loading recipes.")
- return
- }
+ items := g.CraftIndex.ByType("cooking")
if input == "" {
- g.showCookMenu(sess, p, allRecipes, stationDefID, stationName)
+ g.showCookMenu(sess, p, items, stationDefID, stationName)
return
}
@@ -51,13 +47,11 @@ func (g *Game) doCook(sess *net.Session, input string) {
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)
+ var recipes []*object.ItemDef
+ for _, item := range items {
+ c := item.FirstCraft()
+ if stationMatch(stationDefID, c.Station) && craftMatchesEntry(c, itemID) && craftHasAllItems(c, p.HasItem) {
+ recipes = append(recipes, item)
}
}
@@ -65,25 +59,23 @@ func (g *Game) doCook(sess *net.Session, input string) {
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) {
+func (g *Game) showCookMenu(sess *net.Session, p *player.Player, items []*object.ItemDef, stationDefID, stationName string) {
seen := make(map[string]bool)
- var recipes []action.RecipeDef
+ var recipes []*object.ItemDef
- for _, r := range allRecipes {
- if r.Type != "cooking" {
- continue
- }
- if !stationMatch(stationDefID, r.Station) {
+ for _, item := range items {
+ c := item.FirstCraft()
+ if !stationMatch(stationDefID, c.Station) {
continue
}
- if seen[r.ID] {
+ if seen[item.ID] {
continue
}
- if !r.HasAllItems(p.HasItem) {
+ if !craftHasAllItems(c, p.HasItem) {
continue
}
- seen[r.ID] = true
- recipes = append(recipes, r)
+ seen[item.ID] = true
+ recipes = append(recipes, item)
}
title := fmt.Sprintf("What would you like to cook on the %s?", stationName)