Draw items from the submarine for fabricator crafting
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
-- luacheck: globals Character Game MyModGlobal
|
||||
local utils = require("Cyka.utils")
|
||||
local dump = require("Cyka.dump")
|
||||
|
||||
---@return {item: Barotrauma.Item, fabricator: Barotrauma.FabricatorComponent}, string?
|
||||
local function getOpenFabricator()
|
||||
@@ -115,6 +116,7 @@ local function tryStackFabricator(character)
|
||||
local toGet = {}
|
||||
---@type fun(item: Barotrauma.Item): boolean, boolean
|
||||
local filter = function(item)
|
||||
-- TODO: Take into account minCondition and maxCondition
|
||||
local found = false
|
||||
-- MyModGlobal.DumpTable(toFind)
|
||||
-- toFind are all items we need to find
|
||||
@@ -141,6 +143,7 @@ local function tryStackFabricator(character)
|
||||
-- MyModGlobal.debugPrint(string.format("Found %s %s", item.Prefab.Identifier.Value, tostring(remaining)))
|
||||
return found, remaining == 0
|
||||
end
|
||||
-- dump(itemsOnSubmarine)
|
||||
-- MyModGlobal.DumpTable(toGet)
|
||||
|
||||
local items = utils.enqueueInventory(bagItem.OwnInventory, {}, filter)
|
||||
@@ -154,14 +157,59 @@ local function tryStackFabricator(character)
|
||||
end
|
||||
end
|
||||
|
||||
-- If we looked at all items we have on person and still are missing some
|
||||
-- Look at all the items on the submarine
|
||||
local hasAny = false
|
||||
for _, itemInfo in pairs(toFind) do
|
||||
if itemInfo.amount > 0 then
|
||||
hasAny = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if hasAny then
|
||||
local submarine = character.Submarine
|
||||
local found
|
||||
if not submarine then
|
||||
MyModGlobal.debugPrint("Submarine not found.")
|
||||
goto done
|
||||
end
|
||||
for item in submarine.GetItems(false) do
|
||||
if remaining == 0 then goto done end
|
||||
for i, itemInfo in pairs(toFind) do
|
||||
found = false
|
||||
for _, prefab in ipairs(itemInfo.prefabs) do
|
||||
-- MyModGlobal.debugPrint(string.format("Checking %s against %s", item.Prefab.Identifier.Value, prefab))
|
||||
if tostring(item.Prefab.Identifier.Value) == prefab then
|
||||
-- MyModGlobal.debugPrint(string.format("That'll do %s %s", item.Prefab.Identifier.Value, prefab))
|
||||
items[#items + 1] = item
|
||||
itemInfo.amount = itemInfo.amount - 1
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if itemInfo.amount <= 0 then
|
||||
-- MyModGlobal.debugPrint(string.format("Removing %s from toFind", itemInfo.prefabs[1]))
|
||||
toFind[i] = nil
|
||||
remaining = remaining - 1
|
||||
end
|
||||
if found then break end
|
||||
end
|
||||
end
|
||||
|
||||
::done::
|
||||
end
|
||||
|
||||
local slot = -1
|
||||
local previous = nil
|
||||
for _, item in ipairs(items) do
|
||||
if previous ~= item.Prefab.Identifier then slot = slot + 1 end
|
||||
inputInventory.TryPutItem(item, slot, false, true, nil)
|
||||
local moved = inputInventory.TryPutItem(item, slot, false, true, nil)
|
||||
if not moved then
|
||||
MyModGlobal.debugPrint(string.format("Failed to move %s", item.Prefab.Identifier.Value))
|
||||
end
|
||||
previous = item.Prefab.Identifier
|
||||
end
|
||||
MyModGlobal.DumpTable(items)
|
||||
end
|
||||
|
||||
return {
|
||||
|
Reference in New Issue
Block a user