Implement selective sussing
This commit is contained in:
@@ -349,45 +349,71 @@ end
|
||||
local function buildItemTree(inventory, itemTree, iter)
|
||||
iter = iter or 0
|
||||
itemTree = itemTree or {}
|
||||
if not inventory or not inventory.slots then return itemTree end
|
||||
if not inventory or not inventory.slots then
|
||||
debugPrint("Inventory is nil or has no slots, returning empty itemTree")
|
||||
return itemTree
|
||||
end
|
||||
|
||||
-- One slot can have one item but multiple of it
|
||||
-- The number of an item in a slot is #slot.items
|
||||
for slotIndex, slot in ipairs(inventory.slots) do
|
||||
-- This iteration shit is done only to skip the player inventory as a potential destination
|
||||
-- This iteration is done only to skip the player inventory as a potential destination
|
||||
-- Since it will always be 0th iteration and there's no point stacking
|
||||
-- Items from the player inventory to itself
|
||||
debugPrint("Building item tree for inventory at iteration: " .. iter .. ", slot index: " .. slotIndex)
|
||||
debugPrint("Slot " .. slotIndex .. " has " .. #slot.items .. " items")
|
||||
if iter > 0 then
|
||||
if #slot.items == 0 then
|
||||
debugPrint("Slot " .. slotIndex .. " is empty, adding to itemTree as 'empty'")
|
||||
itemTree['empty'] = itemTree['empty'] or {}
|
||||
itemTree['empty'][#itemTree['empty'] + 1] = {
|
||||
inventory = inventory,
|
||||
slotIndex = slotIndex,
|
||||
maxFits = 60
|
||||
}
|
||||
debugPrint("Added empty slot to itemTree at index: " .. slotIndex)
|
||||
else
|
||||
---@type Barotrauma.Item
|
||||
local item = slot.items[1]
|
||||
local maxStackSize = item.Prefab.MaxStackSize or 60
|
||||
local identifier = item.Prefab.Identifier.Value
|
||||
debugPrint("Found item: " ..
|
||||
item.Name .. " with identifier: " .. identifier .. ", max stack size: " .. maxStackSize)
|
||||
itemTree[identifier] = itemTree[identifier] or {}
|
||||
-- We DO want even slots with maxFits = 0
|
||||
-- Because that indicates that we DO HAVE the item
|
||||
-- At all
|
||||
-- And based on that we decide to move it
|
||||
itemTree[identifier][#itemTree[identifier] + 1] = {
|
||||
inventory = inventory,
|
||||
slotIndex = slotIndex,
|
||||
maxFits = maxStackSize - #slot.items
|
||||
maxFits = slot.HowManyCanBePut(item.Prefab)
|
||||
}
|
||||
debugPrint("Added item to itemTree under identifier: " ..
|
||||
identifier .. ", available fits: " .. (maxStackSize - #slot.items))
|
||||
end
|
||||
end
|
||||
|
||||
if #slot.items > 1 then
|
||||
|
||||
if #slot.items > 0 then
|
||||
---@type Barotrauma.Item
|
||||
local item = slot.items[1]
|
||||
if item.OwnInventory then
|
||||
print("Searching inside " .. item.Name .. " for nested containers")
|
||||
local tags = item.Prefab.Tags
|
||||
local shouldSuss = false
|
||||
for tag in tags do
|
||||
if tag.value:find("container") then
|
||||
shouldSuss = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if shouldSuss then
|
||||
debugPrint("Searching inside " .. item.Name .. " for nested containers")
|
||||
buildItemTree(item.OwnInventory, itemTree, iter + 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
debugPrint("Completed building item tree for current inventory iteration: " .. iter)
|
||||
return itemTree
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user