From 470bc5bd99b793e46305310b5fbeb3068eba45f1 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Sat, 20 Jun 2026 23:43:35 -0400 Subject: refactor: removed separate crafting recipes and combined them into item YAML --- internal/game/cmd_clean.go | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'internal/game/cmd_clean.go') diff --git a/internal/game/cmd_clean.go b/internal/game/cmd_clean.go index 951b41d..28758b8 100644 --- a/internal/game/cmd_clean.go +++ b/internal/game/cmd_clean.go @@ -7,6 +7,7 @@ import ( "thehouseoficarus/internal/combat" "thehouseoficarus/internal/engine" "thehouseoficarus/internal/net" + "thehouseoficarus/internal/object" "thehouseoficarus/internal/player" ) @@ -22,26 +23,19 @@ func (g *Game) doClean(sess *net.Session, input string) { return } - allRecipes, err := g.RecipeStore.LoadAll() - if err != nil { - sess.WriteLine("Error loading recipes.") - return - } + items := g.CraftIndex.ByType("clean") filter := strings.TrimSpace(input) found := false - for _, r := range allRecipes { - if r.Type != "clean" { - continue - } - if filter != "" && !matchesCleanFilter(r, filter) { + for _, item := range items { + if filter != "" && !matchesCleanFilter(item, filter) { continue } - if p.Level(player.Pharmacy) < r.Level { + if p.Level(player.Pharmacy) < item.FirstCraft().Level { continue } - if !r.HasAllItems(p.HasItem) { + if !craftHasAllItems(item.FirstCraft(), p.HasItem) { continue } found = true @@ -49,7 +43,21 @@ func (g *Game) doClean(sess *net.Session, input string) { } if !found { - sess.WriteLine("You don't have any herbs to clean.") + hasHerbs := false + for _, item := range items { + if filter != "" && !matchesCleanFilter(item, filter) { + continue + } + if craftHasAllItems(item.FirstCraft(), p.HasItem) { + hasHerbs = true + break + } + } + if hasHerbs { + sess.WriteLine("You don't have the Pharmacy level to clean any of your herbs.") + } else { + sess.WriteLine("You don't have any herbs to clean.") + } return } @@ -71,13 +79,13 @@ func (g *Game) doClean(sess *net.Session, input string) { sess.WriteLine("\nYou begin cleaning herbs.") } -func matchesCleanFilter(r action.RecipeDef, filter string) bool { - if len(r.Consume) > 0 && len(r.Consume[0].Items) > 0 { - if strings.Contains(r.Consume[0].Items[0], filter) { +func matchesCleanFilter(item *object.ItemDef, filter string) bool { + if len(item.Craft) > 0 && len(item.FirstCraft().Consume) > 0 && len(item.FirstCraft().Consume[0].Items) > 0 { + if strings.Contains(item.FirstCraft().Consume[0].Items[0], filter) { return true } } - if strings.Contains(r.Output, filter) { + if strings.Contains(item.ID, filter) { return true } return false -- cgit v1.2.3