package game import ( "sort" "thehouseoficarus/internal/player" ) func (g *Game) dropItemsOnDeath(p *player.Player) { roomID := p.RoomID if p.Credits > 0 { g.World.AddGroundItem(roomID, "credits", p.Credits) p.Credits = 0 } var items []deathDrop for slot, inv := range p.Inventory { if inv == nil || inv.Quantity <= 0 { continue } val := 0 if def, err := g.ItemStore.Load(inv.ItemID); err == nil { val = def.Value * inv.Quantity } items = append(items, deathDrop{ itemID: inv.ItemID, quantity: inv.Quantity, totalVal: val, invSlot: slot, }) } for eqSlot, itemID := range p.Equipment { val := 0 if def, err := g.ItemStore.Load(itemID); err == nil { val = def.Value } items = append(items, deathDrop{ itemID: itemID, quantity: 1, totalVal: val, isEquip: true, equipSlot: eqSlot, }) } if len(items) <= 3 { return } sort.Slice(items, func(i, j int) bool { return items[i].totalVal > items[j].totalVal }) for i := 3; i < len(items); i++ { it := items[i] if it.isEquip { delete(p.Equipment, it.equipSlot) } else { p.SetInvSlot(it.invSlot, nil) } g.World.AddGroundItem(roomID, it.itemID, it.quantity) } }