diff options
Diffstat (limited to 'internal/game/cmd_remove.go')
| -rw-r--r-- | internal/game/cmd_remove.go | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/internal/game/cmd_remove.go b/internal/game/cmd_remove.go index d03daec..8ea21a9 100644 --- a/internal/game/cmd_remove.go +++ b/internal/game/cmd_remove.go @@ -150,7 +150,21 @@ func (g *Game) doRemoveAll(sess *net.Session) { return } - needed := len(p.Equipment) + // Ammo routes through removeAllAmmo, which merges into an existing + // matching-quality stack and therefore needs no fresh slot. Count only the + // entries that will actually consume a slot so a mergeable ammo stack does + // not make the pre-gate report a false "no room". + needed := 0 + for _, slot := range EquipSlots { + itemID, ok := p.Equipment[slot] + if !ok { + continue + } + if slot == item.SlotAmmo && p.AmmoQty > 0 && g.ammoHasMergeableStack(p, itemID) { + continue + } + needed++ + } if needed > p.FreeSlots() { sess.WriteLine("You don't have room to remove everything!") return @@ -232,3 +246,17 @@ func (g *Game) removeAllAmmo(sess *net.Session, p *player.Player, itemID string) } sess.WriteLine(fmt.Sprintf("You remove %s.", g.itemColorize(sess, def, name))) } + +// ammoHasMergeableStack reports whether removeAllAmmo will merge the equipped +// ammo stack into an existing inventory stack with the same freshly-picked +// properties (see pickedStackProps), which consumes no free slot. +func (g *Game) ammoHasMergeableStack(p *player.Player, itemID string) bool { + quality, maxQuality := g.pickedStackProps(itemID) + for i := 0; i < player.MaxInventorySlots; i++ { + s := p.InvSlot(i) + if s != nil && s.ItemID == itemID && s.Quality == quality && s.MaxQuality == maxQuality { + return true + } + } + return false +} |
