Fix up some more minor issues with stacker
This commit is contained in:
@@ -112,19 +112,19 @@ local function tryMoveItem(item, itemTree, force)
|
||||
-- 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
|
||||
if location then
|
||||
-- First try to move to existing stacks
|
||||
for _, itemLocation in ipairs(location) do
|
||||
if itemLocation.maxFits > 0 then
|
||||
-- We cannot stack items with decreased condition
|
||||
local canBePut = itemLocation.inventory.CanBePutInSlot(item.Prefab, itemLocation.slotIndex, item.Condition)
|
||||
-- MyModGlobal.debugPrint(string.format("Can be put in slot %d: %s", itemLocation.slotIndex, tostring(canBePut)))
|
||||
|
||||
if itemLocation.maxFits > 0 and canBePut 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
|
||||
itemLocation.maxFits = itemLocation.inventory.HowManyCanBePut(item.Prefab, itemLocation.slotIndex)
|
||||
end
|
||||
-- if moved then
|
||||
-- MyModGlobal.debugPrint(string.format("Moved item to existing stack at slot index: %d", itemLocation .slotIndex))
|
||||
-- else
|
||||
@@ -139,13 +139,26 @@ local function tryMoveItem(item, itemTree, force)
|
||||
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, true, true, nil)
|
||||
local maxFits = itemLocation.maxFits
|
||||
-- These empty slots are not guranteed to be empty, ironically
|
||||
-- After we insert an item into one it's no longer empty
|
||||
-- But it still is in the empty table
|
||||
-- So we want to make sure we can insert our item
|
||||
-- Into the maybe empty slots
|
||||
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
|
||||
|
||||
if maxFits > 0 then
|
||||
-- MyModGlobal.debugPrint(string.format("Trying to move item to empty slot at index: %d", itemLocation.slotIndex))
|
||||
moved = moved or itemLocation.inventory.TryPutItem(item, itemLocation.slotIndex, true, false, nil)
|
||||
if moved then
|
||||
itemLocation.maxFits = itemLocation.inventory.HowManyCanBePut(item.Prefab, itemLocation.slotIndex)
|
||||
end
|
||||
-- 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
|
||||
end
|
||||
|
||||
@@ -250,7 +263,12 @@ local function quickStackItems(character)
|
||||
return
|
||||
end
|
||||
|
||||
-- local inventory = character.Inventory
|
||||
local inventory = character.Inventory
|
||||
if not inventory or not inventory.slots then
|
||||
MyModGlobal.debugPrint("Character has no inventory")
|
||||
return
|
||||
end
|
||||
|
||||
-- for i, slot in ipairs(inventory.slots) do
|
||||
-- if #slot.items > 0 then
|
||||
-- local item = slot.items[1]
|
||||
|
||||
Reference in New Issue
Block a user