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_smelt.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_smelt.go')
| -rw-r--r-- | internal/game/cmd_smelt.go | 36 |
1 files changed, 17 insertions, 19 deletions
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") |
