Add some debug logs and shit

This commit is contained in:
2025-03-30 15:41:23 +02:00
parent f37ef64739
commit e1b658721e

View File

@@ -102,30 +102,59 @@ end
---@param force boolean
---@return string
local function tryMoveItem(item, itemTree, force)
-- MyModGlobal.debugPrint(string.format("Attempting to move item: %s", item.Prefab.Identifier.Value))
force = force or false
local location = itemTree[item.Prefab.Identifier.Value]
if not location and not force then return nil, "No locations for item, not stacking (not forced)" end
if not location and not force then
-- MyModGlobal.debugPrint("No locations for item, not stacking (not forced)")
return nil, "No locations for item, not stacking (not forced)"
end
-- MyModGlobal.debugPrint(string.format("Attempting to move item: %s", item.Prefab.Identifier.Value))
-- MyModGlobal.DumpTable(location)
if item.Condition <= item.MaxCondition then
-- MyModGlobal.debugPrint(string.format("Item %s has condition %.2f(<=%.2f), not stacking", item.Prefab.Identifier.Value, item.Condition, item.MaxCondition))
-- Don't even TRY to stack them
location = nil
end
local moved = false
-- First try to move to existing stacks
for _, itemLocation in ipairs(location) do
if itemLocation.maxFits > 0 then
moved = moved or itemLocation.inventory.TryPutItem(item, itemLocation.slotIndex, false, true, nil)
itemLocation.maxFits = itemLocation.inventory.HowManyCanBePut(item.Prefab, itemLocation.slotIndex)
if location then
-- First try to move to existing stacks
for _, itemLocation in ipairs(location) do
if itemLocation.maxFits > 0 then
moved = moved or itemLocation.inventory.TryPutItem(item, itemLocation.slotIndex, false, true, nil)
itemLocation.maxFits = itemLocation.inventory.HowManyCanBePut(item.Prefab, itemLocation.slotIndex)
-- if moved then
-- MyModGlobal.debugPrint(string.format("Moved item to existing stack at slot index: %d", itemLocation .slotIndex))
-- else
-- MyModGlobal.debugPrint(string.format("Failed to move item to existing stack at slot index: %d", itemLocation .slotIndex))
-- end
end
end
end
-- If we can not find an existing stack
-- Then move to any of the empty slots
if not moved then
-- MyModGlobal.debugPrint("No existing stacks found, trying empty slots...")
for _, itemLocation in ipairs(itemTree['empty']) do
moved = moved or itemLocation.inventory.TryPutItem(item, itemLocation.slotIndex, false, true, nil)
moved = moved or itemLocation.inventory.TryPutItem(item, itemLocation.slotIndex, true, true, nil)
itemLocation.maxFits = itemLocation.inventory.HowManyCanBePut(item.Prefab, itemLocation.slotIndex)
-- if moved then
-- MyModGlobal.debugPrint(string.format("Moved item to empty slot at index: %d", itemLocation.slotIndex))
-- else
-- MyModGlobal.debugPrint(string.format("Failed to move item to empty slot at index: %d", itemLocation.slotIndex))
-- end
end
end
-- If we still can not move the item give up
if not moved then return "Failed to find valid location for item" end
if not moved then
-- MyModGlobal.debugPrint("Failed to find valid location for item")
return "Failed to find valid location for item"
end
-- MyModGlobal.debugPrint("Item moved successfully")
return nil
end