aboutsummaryrefslogtreecommitdiff
path: root/internal/game/action_clean.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-20 23:43:35 -0400
committerhistoria <[not public]>2026-06-20 23:43:35 -0400
commit470bc5bd99b793e46305310b5fbeb3068eba45f1 (patch)
treeff268fab1a8e7699cd6404e6e86c2d4bd1c6f2f6 /internal/game/action_clean.go
parent010fa439399581391fcd509d2058191ff4fa74b3 (diff)
downloadthehouseoficarus-470bc5bd99b793e46305310b5fbeb3068eba45f1.tar.gz
refactor: removed separate crafting recipes and combined them into item YAML
Diffstat (limited to 'internal/game/action_clean.go')
-rw-r--r--internal/game/action_clean.go60
1 files changed, 26 insertions, 34 deletions
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
}