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_smelt.go | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'internal/game/cmd_smelt.go') diff --git a/internal/game/cmd_smelt.go b/internal/game/cmd_smelt.go index f1ff4e2..8ad2391 100644 --- a/internal/game/cmd_smelt.go +++ b/internal/game/cmd_smelt.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) doSmelt(sess *net.Session, input string) { return } - allRecipes, err := g.RecipeStore.LoadAll() - if err != nil { - sess.WriteLine("Error loading recipes.") - return - } + items := g.CraftIndex.ByType("smelting") if input == "" { - g.showSmeltMenu(sess, p, allRecipes, stationDefID, stationName) + g.showSmeltMenu(sess, p, items, stationDefID, stationName) return } @@ -48,33 +44,35 @@ func (g *Game) doSmelt(sess *net.Session, input string) { itemID := matches[0].ID - var recipes []action.RecipeDef - for _, r := range allRecipes { - if r.Type != "smelting" || !stationMatch(stationDefID, r.Station) || !r.MatchesEntry(itemID) { + var recipes []*object.ItemDef + for _, item := range items { + c := item.FirstCraft() + if !stationMatch(stationDefID, c.Station) || !craftMatchesEntry(c, itemID) { continue } - if !r.HasAllItemsQty(p.CountItem) || p.Level(player.SkillName(r.EffectiveSkill())) < r.Level { + if !craftHasAllItemsQty(c, p.CountItem) || p.Level(player.SkillName(c.EffectiveSkill())) < c.Level { continue } - recipes = append(recipes, r) + recipes = append(recipes, item) } g.showRecipeChoice(sess, p, recipes, "You can't smelt that.", "What would you like to smelt?", "") } -func (g *Game) showSmeltMenu(sess *net.Session, p *player.Player, allRecipes []action.RecipeDef, stationDefID, stationName string) { +func (g *Game) showSmeltMenu(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 != "smelting" || !stationMatch(stationDefID, r.Station) { + for _, item := range items { + c := item.FirstCraft() + if !stationMatch(stationDefID, c.Station) { continue } - if seen[r.ID] || !r.HasAllItemsQty(p.CountItem) || p.Level(player.SkillName(r.EffectiveSkill())) < r.Level { + if seen[item.ID] || !craftHasAllItemsQty(c, p.CountItem) || p.Level(player.SkillName(c.EffectiveSkill())) < c.Level { continue } - seen[r.ID] = true - recipes = append(recipes, r) + seen[item.ID] = true + recipes = append(recipes, item) } g.showRecipeChoice(sess, p, recipes, "You don't have anything you can smelt.", "What would you like to smelt?", "smelt_all") -- cgit v1.2.3