Skip to content

Commit

Permalink
refactor(server/inventory): add ignoreCount param to SlotWeight
Browse files Browse the repository at this point in the history
Allow calculation of per-item weight in a slot.
  • Loading branch information
thelindat committed Mar 17, 2023
1 parent c49f1ff commit 9ff8ebe
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions modules/inventory/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,9 @@ end)

---@param item table
---@param slot table
function Inventory.SlotWeight(item, slot)
local weight = item.weight * slot.count
function Inventory.SlotWeight(item, slot, ignoreCount)
local weight = ignoreCount and item.weight or item.weight * (slot.count or 1)

if not slot.metadata then slot.metadata = {} end

if item.ammoname and slot.metadata.ammo then
Expand All @@ -364,7 +365,7 @@ function Inventory.SlotWeight(item, slot)
end

if slot.metadata.weight then
weight += (slot.metadata.weight * slot.count)
weight += ignoreCount and slot.metadata.weight or (slot.metadata.weight * (slot.count or 1))
end

return weight
Expand Down

0 comments on commit 9ff8ebe

Please sign in to comment.