diff options
Diffstat (limited to 'internal/player/player.go')
| -rw-r--r-- | internal/player/player.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/internal/player/player.go b/internal/player/player.go index aad0b8e..92b017a 100644 --- a/internal/player/player.go +++ b/internal/player/player.go @@ -205,7 +205,7 @@ type Player struct { Options map[string]any `yaml:"-"` Flags map[string]any `yaml:"flags"` PendingSequence *PendingSequence `yaml:"pending_sequence,omitempty"` - RegenerateTick int + RegenerateTick int `yaml:"-"` AmmoQty int `yaml:"ammo_qty,omitempty"` Action *behavior.Action `yaml:"-"` BackgroundAction *behavior.Action `yaml:"-"` @@ -525,6 +525,11 @@ func (p *Player) RemoveItem(itemID string, qty int) bool { if qty <= 0 { return false } + // All-or-nothing: a caller that rolls back on false must not find the + // inventory already drained. Check the total first, then remove. + if p.CountItem(itemID) < qty { + return false + } remaining := qty for i, slot := range p.Inventory { if slot == nil || slot.ItemID != itemID { |
