aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_trigger_utility.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/cmd_trigger_utility.go')
-rw-r--r--internal/game/cmd_trigger_utility.go39
1 files changed, 24 insertions, 15 deletions
diff --git a/internal/game/cmd_trigger_utility.go b/internal/game/cmd_trigger_utility.go
index ca65445..09eabb1 100644
--- a/internal/game/cmd_trigger_utility.go
+++ b/internal/game/cmd_trigger_utility.go
@@ -187,29 +187,34 @@ func (g *Game) triggerSuperheat(sess *net.Session, p *player.Player, mod *ModDef
return
}
- for _, e := range c.Ingredients {
- for _, itemID := range e.Items {
- qty := e.Quantity
- if qty <= 0 {
- qty = 1
- }
- if p.CountItem(itemID) < qty {
- def, _ := g.ItemStore.Load(itemID)
- name := itemID
- if def != nil {
- name = def.Name
- }
- sess.WriteLine(fmt.Sprintf("You need %d %s.", qty, name))
- return
+ // Availability resolves each entry the way consumeIngredients will: ONE
+ // listed alternative must cover the entry's full quantity. The previous
+ // hand-rolled loop required EVERY listed alternative, e.g. both a
+ // bucket AND a jug of water to superheat clay, and could not name the
+ // missing choice.
+ for i := range c.Ingredients {
+ id, qty := craftIngredientSource(&c.Ingredients[i], p.CountItem)
+ if id != "" {
+ continue
+ }
+ names := make([]string, 0, len(c.Ingredients[i].Items))
+ for _, itemID := range c.Ingredients[i].Items {
+ def, _ := g.ItemStore.Load(itemID)
+ name := itemID
+ if def != nil {
+ name = def.Name
}
+ names = append(names, fmt.Sprintf("%d %s", qty, name))
}
+ sess.WriteLine(fmt.Sprintf("You need one of: %s.", strings.Join(names, " or ")))
+ return
}
if p.Action != nil {
g.cancelAction(p)
}
- consumeIngredients(c, p.HasItem, p.RemoveItem)
+ consumeIngredients(c, p.CountItem, p.RemoveItem)
outputQty := c.OutputQty
if outputQty <= 0 {
@@ -226,6 +231,10 @@ func (g *Game) triggerSuperheat(sess *net.Session, p *player.Player, mod *ModDef
}
if !placed {
freeSlot := p.FirstFreeSlot()
+ if freeSlot < 0 {
+ sess.WriteLine("Your inventory is too full!")
+ return
+ }
p.SetInvSlot(freeSlot, &player.InventorySlot{ItemID: match.ID, Quantity: outputQty})
}