diff options
Diffstat (limited to 'internal/game/sys_combat.go')
| -rw-r--r-- | internal/game/sys_combat.go | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/internal/game/sys_combat.go b/internal/game/sys_combat.go index b2a2463..af8cc75 100644 --- a/internal/game/sys_combat.go +++ b/internal/game/sys_combat.go @@ -5,6 +5,7 @@ import ( "math/rand" "sort" + "thehouseoficarus/internal/item" "thehouseoficarus/internal/net" "thehouseoficarus/internal/player" ) @@ -36,13 +37,23 @@ func (g *Game) dropItemsOnDeath(p *player.Player) { } for eqSlot, itemID := range p.Equipment { + quantity := 1 + // Ammo keeps its stack count in AmmoQty, not in an inventory slot; + // dropping the equipment entry without moving that count would destroy + // the rest of the stack and leave a stale ammo_qty on disk. + if eqSlot == item.SlotAmmo { + quantity = p.AmmoQty + if quantity <= 0 { + quantity = 1 + } + } val := 0 if def, err := g.ItemStore.Load(itemID); err == nil { - val = def.Value + val = def.Value * quantity } items = append(items, deathDrop{ itemID: itemID, - quantity: 1, + quantity: quantity, totalValue: val, isEquip: true, equipSlot: eqSlot, @@ -61,6 +72,12 @@ func (g *Game) dropItemsOnDeath(p *player.Player) { it := items[i] if it.isEquip { delete(p.Equipment, it.equipSlot) + // Equipped quality is keyed by item id and must not outlive the + // equipment entry, or a later drop/wear reads a stale quality. + delete(p.EquipQuality, it.itemID) + if it.equipSlot == item.SlotAmmo { + p.AmmoQty = 0 + } } else { p.SetInvSlot(it.invSlot, nil) } |
