diff options
Diffstat (limited to 'internal/game/act_combine.go')
| -rw-r--r-- | internal/game/act_combine.go | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/internal/game/act_combine.go b/internal/game/act_combine.go index bc9b6de..b16cf7a 100644 --- a/internal/game/act_combine.go +++ b/internal/game/act_combine.go @@ -100,6 +100,15 @@ func (g *Game) advanceCombine(sess *net.Session, p *player.Player) { return } + // A full inventory must never destroy materials: verify the output + // can be placed BEFORE collecting byproducts and consuming. + outDef, _ := g.ItemStore.Load(item.ID) + if !craftOutputFits(p, item.ID, outDef) { + sess.WriteLine("Your inventory is too full!") + g.cancelAction(p) + return + } + // Byproducts must be collected BEFORE consumption: the resolver maps // each ingredient entry to the alternative actually being consumed // (bucket vs jug of water), which requires the items still present. @@ -112,26 +121,12 @@ func (g *Game) advanceCombine(sess *net.Session, p *player.Player) { outputQty = 1 } - outDef, _ := g.ItemStore.Load(item.ID) - placed := false - if outDef != nil && outDef.Stackable { - for i := 0; i < 28; i++ { - slot := p.InvSlot(i) - if slot != nil && slot.ItemID == item.ID { - slot.Quantity += outputQty - placed = true - break - } - } - } - if !placed { - freeSlot := p.FirstFreeSlot() - if freeSlot == -1 { - sess.WriteLine("Your inventory is too full!") - g.cancelAction(p) - return - } - p.SetInvSlot(freeSlot, &player.InventorySlot{ItemID: item.ID, Quantity: outputQty}) + if !placeCraftOutput(p, item.ID, outDef, outputQty) { + // Defensive: the fits check above should have guaranteed a + // stack or slot. + sess.WriteLine("Your inventory is too full!") + g.cancelAction(p) + return } // Return the empty containers (and any other byproducts) alongside |
