diff options
| author | historia <[not public]> | 2026-06-20 23:43:35 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-20 23:43:35 -0400 |
| commit | 470bc5bd99b793e46305310b5fbeb3068eba45f1 (patch) | |
| tree | ff268fab1a8e7699cd6404e6e86c2d4bd1c6f2f6 /internal/game/cmd_clean.go | |
| parent | 010fa439399581391fcd509d2058191ff4fa74b3 (diff) | |
| download | thehouseoficarus-470bc5bd99b793e46305310b5fbeb3068eba45f1.tar.gz | |
refactor: removed separate crafting recipes and combined them into item YAML
Diffstat (limited to 'internal/game/cmd_clean.go')
| -rw-r--r-- | internal/game/cmd_clean.go | 42 |
1 files changed, 25 insertions, 17 deletions
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 |
