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_trigger_utility.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_trigger_utility.go')
| -rw-r--r-- | internal/game/cmd_trigger_utility.go | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/internal/game/cmd_trigger_utility.go b/internal/game/cmd_trigger_utility.go index ce59975..69abc34 100644 --- a/internal/game/cmd_trigger_utility.go +++ b/internal/game/cmd_trigger_utility.go @@ -6,6 +6,7 @@ import ( "thehouseoficarus/internal/combat" "thehouseoficarus/internal/net" + "thehouseoficarus/internal/object" "thehouseoficarus/internal/player" ) @@ -169,18 +170,25 @@ func (g *Game) triggerSuperheat(sess *net.Session, p *player.Player, mod *ModDef return } - recipe := g.RecipeStore.FindByInput("smelt", inv.ItemID) - if recipe == nil { + var match *object.ItemDef + for _, item := range g.CraftIndex.ByType("smelting") { + if craftMatchesEntry(item.FirstCraft(), inv.ItemID) { + match = item + break + } + } + if match == nil { sess.WriteLine("You can't superheat that.") return } + c := match.FirstCraft() - if recipe.Level > 0 && p.Level(player.SkillName(recipe.Skill)) < recipe.Level { - sess.WriteLine(fmt.Sprintf("You need level %d %s to smelt that.", recipe.Level, recipe.Skill)) + if c.Level > 0 && p.Level(player.SkillName(c.Skill)) < c.Level { + sess.WriteLine(fmt.Sprintf("You need level %d %s to smelt that.", c.Level, c.Skill)) return } - for _, e := range recipe.Consume { + for _, e := range c.Consume { for _, itemID := range e.Items { qty := e.Quantity if qty <= 0 { @@ -202,24 +210,16 @@ func (g *Game) triggerSuperheat(sess *net.Session, p *player.Player, mod *ModDef g.cancelAction(p) } - for _, e := range recipe.Consume { - for _, itemID := range e.Items { - qty := e.Quantity - if qty <= 0 { - qty = 1 - } - p.RemoveItem(itemID, qty) - } - } + craftConsumeAll(c, p.HasItem, p.RemoveItem) - outputQty := recipe.OutputQty + outputQty := c.OutputQty if outputQty <= 0 { outputQty = 1 } placed := false for i := 0; i < 28; i++ { slot := p.InvSlot(i) - if slot != nil && slot.ItemID == recipe.Output { + if slot != nil && slot.ItemID == match.ID { slot.Quantity += outputQty placed = true break @@ -227,20 +227,16 @@ func (g *Game) triggerSuperheat(sess *net.Session, p *player.Player, mod *ModDef } if !placed { freeSlot := p.FirstFreeSlot() - p.SetInvSlot(freeSlot, &player.InventorySlot{ItemID: recipe.Output, Quantity: outputQty}) + p.SetInvSlot(freeSlot, &player.InventorySlot{ItemID: match.ID, Quantity: outputQty}) } var extraGains []xpGain - if recipe.XP > 0 { - extraGains = []xpGain{{recipe.Skill, recipe.XP}} + if c.XP > 0 { + extraGains = []xpGain{{c.EffectiveSkill(), c.XP}} } g.triggerModReward(sess, p, mod, 1.0, extraGains...) - outputDef, _ := g.ItemStore.Load(recipe.Output) - outputName := recipe.Output - if outputDef != nil { - outputName = outputDef.Name - } + outputName := match.Name inputDef, _ := g.ItemStore.Load(inv.ItemID) inputName := inv.ItemID if inputDef != nil { |
