Implement finding items for fabricator
This commit is contained in:
@@ -338,12 +338,6 @@ local function quickStackItems(character)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- for i, slot in ipairs(inventory.slots) do
|
|
||||||
-- if slot.items and #slot.items > 0 then
|
|
||||||
-- print(string.format("Item at slot %d is %s", i, slot.items[1].Prefab.Identifier.Value))
|
|
||||||
-- end
|
|
||||||
-- end
|
|
||||||
|
|
||||||
local itemTree, err = tryBuildItemTree(inventory)
|
local itemTree, err = tryBuildItemTree(inventory)
|
||||||
if err then
|
if err then
|
||||||
debugPrint(string.format("Error building item tree: %s", err))
|
debugPrint(string.format("Error building item tree: %s", err))
|
||||||
@@ -352,13 +346,13 @@ local function quickStackItems(character)
|
|||||||
itemTree = sortItemtreeBySlots(itemTree)
|
itemTree = sortItemtreeBySlots(itemTree)
|
||||||
local toMove = {}
|
local toMove = {}
|
||||||
|
|
||||||
for i, slot in ipairs(inventory.slots) do
|
-- for i, slot in ipairs(inventory.slots) do
|
||||||
if #slot.items > 0 then
|
-- if #slot.items > 0 then
|
||||||
local item = slot.items[1]
|
-- local item = slot.items[1]
|
||||||
local identifier = item.Prefab.Identifier.Value
|
-- local identifier = item.Prefab.Identifier.Value
|
||||||
print(string.format("Item at slot %d is %s", i, identifier))
|
-- print(string.format("Item at slot %d is %s", i, identifier))
|
||||||
end
|
-- end
|
||||||
end
|
-- end
|
||||||
|
|
||||||
for _, slotid in ipairs(inventorySlotsToStack) do
|
for _, slotid in ipairs(inventorySlotsToStack) do
|
||||||
debugPrint(string.format("Processing inventory slot: %d", slotid))
|
debugPrint(string.format("Processing inventory slot: %d", slotid))
|
||||||
@@ -496,8 +490,36 @@ end
|
|||||||
Hook.Patch("Barotrauma.Character", "ControlLocalPlayer", function(instance, ptable)
|
Hook.Patch("Barotrauma.Character", "ControlLocalPlayer", function(instance, ptable)
|
||||||
if not PlayerInput.KeyHit(CONFIG.FABRICATOR_KEY) then return end
|
if not PlayerInput.KeyHit(CONFIG.FABRICATOR_KEY) then return end
|
||||||
|
|
||||||
|
-- TODO: Maybe get items from entire sub...?
|
||||||
|
-- There's no point getting recipes if we don't have all of this bullshit
|
||||||
|
---@type Barotrauma.Character
|
||||||
local character = instance
|
local character = instance
|
||||||
if not character then return end
|
if not character then
|
||||||
|
debugPrint("Character instance is nil.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
---@type Barotrauma.CharacterInventory
|
||||||
|
local inventory = character.Inventory
|
||||||
|
if not inventory then
|
||||||
|
debugPrint("Character inventory is nil.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
---@type Barotrauma.ItemInventory.Slot
|
||||||
|
local bagSlot = inventory.slots[BAG_SLOT]
|
||||||
|
if not bagSlot then
|
||||||
|
debugPrint("Bag slot not found.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if #bagSlot.items == 0 then
|
||||||
|
debugPrint("Bag slot is empty.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
---@type Barotrauma.Item
|
||||||
|
local bagItem = bagSlot.items[1]
|
||||||
|
if not bagItem then
|
||||||
|
debugPrint("Bag item not found.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local fabricator, err = getOpenFabricator()
|
local fabricator, err = getOpenFabricator()
|
||||||
if err then
|
if err then
|
||||||
@@ -514,9 +536,14 @@ Hook.Patch("Barotrauma.Character", "ControlLocalPlayer", function(instance, ptab
|
|||||||
local toGet = recipe.requiredItems
|
local toGet = recipe.requiredItems
|
||||||
---@type fun(item: Barotrauma.Item): boolean
|
---@type fun(item: Barotrauma.Item): boolean
|
||||||
local filter = function(item)
|
local filter = function(item)
|
||||||
|
if item.Prefab.Identifier == recipe.targetItem.identifier then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
local items = enqueueInventory(character.inventory.slots[BAG_SLOT], {}, filter)
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local items = enqueueInventory(bagItem.OwnInventory, {}, filter)
|
||||||
DumpTable(items)
|
DumpTable(items)
|
||||||
end, Hook.HookMethodType.After)
|
end, Hook.HookMethodType.After)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user