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/action_clean.go | 60 +++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 34 deletions(-) (limited to 'internal/game/action_clean.go') diff --git a/internal/game/action_clean.go b/internal/game/action_clean.go index 7330883..b85a3e0 100644 --- a/internal/game/action_clean.go +++ b/internal/game/action_clean.go @@ -19,37 +19,31 @@ func (g *Game) advanceClean(sess *net.Session, p *player.Player) { return } - allRecipes, err := g.RecipeStore.LoadAll() - if err != nil { - g.cancelBgAction(p) - return - } + items := g.CraftIndex.ByType("clean") - var recipe *cleanMatch - for _, r := range allRecipes { - if r.Type != "clean" { - continue - } + var match *cleanMatch + for _, item := range items { + c := item.FirstCraft() if filter != "" { - if len(r.Consume) == 0 || len(r.Consume[0].Items) == 0 { + if len(c.Consume) == 0 || len(c.Consume[0].Items) == 0 { continue } - if !strings.Contains(r.Consume[0].Items[0], filter) && - !strings.Contains(r.Output, filter) { + if !strings.Contains(c.Consume[0].Items[0], filter) && + !strings.Contains(item.ID, filter) { continue } } - if p.Level(player.Pharmacy) < r.Level { + if p.Level(player.Pharmacy) < c.Level { continue } - if !r.HasAllItems(p.HasItem) { + if !craftHasAllItems(c, p.HasItem) { continue } - recipe = &cleanMatch{r.Consume[0].Items[0], r.Output, r.XP, r.Message} + match = &cleanMatch{c.Consume[0].Items[0], item.ID, c.XP, c.Message} break } - if recipe == nil { + if match == nil { sess.WriteLine("\nYou've finished cleaning herbs.") g.cancelBgAction(p) return @@ -57,47 +51,45 @@ func (g *Game) advanceClean(sess *net.Session, p *player.Player) { for i := 0; i < 28; i++ { slot := p.InvSlot(i) - if slot != nil && slot.ItemID == recipe.consumeID { - slot.ItemID = recipe.outputID + if slot != nil && slot.ItemID == match.consumeID { + slot.ItemID = match.outputID break } } - if recipe.xp > 0 { - g.awardSkillXP(sess, p, player.Pharmacy, recipe.xp) + if match.xp > 0 { + g.awardSkillXP(sess, p, player.Pharmacy, match.xp) } g.AccountStore.SaveCharacter(p) - msg := recipe.message + msg := match.message if msg == "" { - outDef, _ := g.ItemStore.Load(recipe.outputID) - outputName := recipe.outputID + outDef, _ := g.ItemStore.Load(match.outputID) + outputName := match.outputID if outDef != nil { outputName = outDef.Name } msg = fmt.Sprintf("You clean a %s.", outputName) } - if p.OptionBool("xp_drops") && recipe.xp > 0 { + if p.OptionBool("xp_drops") && match.xp > 0 { abbr := player.SkillAbbr[player.Pharmacy] - msg += g.colorize(sess, "xp", fmt.Sprintf(" (+%dxp %s)", recipe.xp, abbr)) + msg += g.colorize(sess, "xp", fmt.Sprintf(" (+%dxp %s)", match.xp, abbr)) } sess.WriteLine(msg) hasMore := false - for _, r := range allRecipes { - if r.Type != "clean" { - continue - } + for _, item := range items { + c := item.FirstCraft() if filter != "" { - if len(r.Consume) == 0 || len(r.Consume[0].Items) == 0 { + if len(c.Consume) == 0 || len(c.Consume[0].Items) == 0 { continue } - if !strings.Contains(r.Consume[0].Items[0], filter) && - !strings.Contains(r.Output, filter) { + if !strings.Contains(c.Consume[0].Items[0], filter) && + !strings.Contains(item.ID, filter) { continue } } - if p.Level(player.Pharmacy) >= r.Level && r.HasAllItems(p.HasItem) { + if p.Level(player.Pharmacy) >= c.Level && craftHasAllItems(c, p.HasItem) { hasMore = true break } -- cgit v1.2.3