Fix rubberbanding and refactor a little
This commit is contained in:
@@ -24,6 +24,7 @@ MyModGlobal = {
|
|||||||
AOEPICKUP = Keys.Y,
|
AOEPICKUP = Keys.Y,
|
||||||
QICK_FABRICATOR = Keys.K,
|
QICK_FABRICATOR = Keys.K,
|
||||||
QICK_DECONSTRUCTOR = Keys.J,
|
QICK_DECONSTRUCTOR = Keys.J,
|
||||||
|
QICK_MEDICAL_FABRICATOR = Keys.M,
|
||||||
NESTED_CONTAINERS = true,
|
NESTED_CONTAINERS = true,
|
||||||
DEBUG_MODE = true,
|
DEBUG_MODE = true,
|
||||||
},
|
},
|
||||||
@@ -166,10 +167,15 @@ end, Hook.HookMethodType.After)
|
|||||||
|
|
||||||
Hook.Patch("Barotrauma.Character", "ControlLocalPlayer", function(instance, ptable)
|
Hook.Patch("Barotrauma.Character", "ControlLocalPlayer", function(instance, ptable)
|
||||||
if not PlayerInput.KeyHit(MyModGlobal.CONFIG.QICK_FABRICATOR) then return end
|
if not PlayerInput.KeyHit(MyModGlobal.CONFIG.QICK_FABRICATOR) then return end
|
||||||
quickaccess.tryAccessFabricator()
|
quickaccess.tryAccessFabricator(PlayerInput.IsShiftDown())
|
||||||
end, Hook.HookMethodType.After)
|
end, Hook.HookMethodType.After)
|
||||||
|
|
||||||
Hook.Patch("Barotrauma.Character", "ControlLocalPlayer", function(instance, ptable)
|
Hook.Patch("Barotrauma.Character", "ControlLocalPlayer", function(instance, ptable)
|
||||||
if not PlayerInput.KeyHit(MyModGlobal.CONFIG.QICK_DECONSTRUCTOR) then return end
|
if not PlayerInput.KeyHit(MyModGlobal.CONFIG.QICK_DECONSTRUCTOR) then return end
|
||||||
quickaccess.tryAccessDeconstructor()
|
quickaccess.tryAccessDeconstructor(PlayerInput.IsShiftDown())
|
||||||
|
end, Hook.HookMethodType.After)
|
||||||
|
|
||||||
|
Hook.Patch("Barotrauma.Character", "ControlLocalPlayer", function(instance, ptable)
|
||||||
|
if not PlayerInput.KeyHit(MyModGlobal.CONFIG.QICK_MEDICAL_FABRICATOR) then return end
|
||||||
|
quickaccess.tryAccessMedicalFabricator(PlayerInput.IsShiftDown())
|
||||||
end, Hook.HookMethodType.After)
|
end, Hook.HookMethodType.After)
|
||||||
|
@@ -7,7 +7,7 @@ Hook.Add("Character_CanInteractWith_Item_Postfix", "YourModName.AllowRemoteInter
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
-- Then patch the CanInteractWith method
|
-- Then patch the CanInteractWith method
|
||||||
Hook.Patch("YourModName", "Barotrauma.Character", "CanInteractWith",
|
Hook.Patch("Cyka", "Barotrauma.Character", "CanInteractWith",
|
||||||
{ "Barotrauma.Item", "System.Single&", "System.Boolean" },
|
{ "Barotrauma.Item", "System.Single&", "System.Boolean" },
|
||||||
function(_, ptable)
|
function(_, ptable)
|
||||||
local result = Hook.Call("Character_CanInteractWith_Item_Postfix")
|
local result = Hook.Call("Character_CanInteractWith_Item_Postfix")
|
||||||
@@ -18,66 +18,78 @@ Hook.Patch("YourModName", "Barotrauma.Character", "CanInteractWith",
|
|||||||
Hook.HookMethodType.After
|
Hook.HookMethodType.After
|
||||||
)
|
)
|
||||||
|
|
||||||
local function tryAccessFabricator()
|
local cachedFabricator = nil
|
||||||
|
local cachedDeconstructor = nil
|
||||||
|
local cachedMedicalFabricator = nil
|
||||||
|
|
||||||
|
---@param prefabIdentifier string
|
||||||
|
---@param componentName string
|
||||||
|
---@return Barotrauma.Item, Barotrauma.Items.Components
|
||||||
|
local function findByComponent(prefabIdentifier, componentName)
|
||||||
local items = utils.enqueueAllSubmarineItems({}, function(item)
|
local items = utils.enqueueAllSubmarineItems({}, function(item)
|
||||||
return item.Prefab.Identifier.Value == "fabricator", item.Prefab.Identifier.Value == "fabricator"
|
return item.Prefab.Identifier.Value == prefabIdentifier, item.Prefab.Identifier.Value == prefabIdentifier
|
||||||
end)
|
end)
|
||||||
if #items == 0 then
|
if #items == 0 then
|
||||||
MyModGlobal.debugPrint("No fabricator found")
|
MyModGlobal.debugPrint("No " .. componentName .. " found")
|
||||||
return
|
return nil, nil
|
||||||
end
|
end
|
||||||
if #items > 1 then
|
if #items > 1 then
|
||||||
MyModGlobal.debugPrint("Multiple fabricators found, using first one")
|
MyModGlobal.debugPrint("Multiple " .. componentName .. " found, using first one")
|
||||||
|
return nil, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
---@type Barotrauma.Item
|
---@type Barotrauma.Item
|
||||||
local fabricator = items[1]
|
local item = items[1]
|
||||||
---@type Barotrauma.Items.Components.Fabricator
|
---@type Barotrauma.Items.Components
|
||||||
local fabricatorComponent
|
local component
|
||||||
for component in fabricator.Components do
|
for itcomponent in item.Components do
|
||||||
if component.Name == "Fabricator" then
|
if itcomponent.Name == componentName then
|
||||||
fabricatorComponent = component
|
component = itcomponent
|
||||||
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not fabricatorComponent then
|
if not component then
|
||||||
MyModGlobal.debugPrint("No fabricator component found")
|
MyModGlobal.debugPrint("No " .. componentName .. " component found")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return item, component
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param force boolean
|
||||||
|
local function tryAccessFabricator(force)
|
||||||
|
local fabricator = cachedFabricator
|
||||||
|
if not fabricator or force then
|
||||||
|
fabricator = findByComponent("fabricator", "Fabricator")
|
||||||
|
if not fabricator then
|
||||||
|
MyModGlobal.debugPrint("No fabricator found")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
cachedFabricator = fabricator
|
||||||
|
end
|
||||||
|
|
||||||
local me = Character.Controlled
|
local me = Character.Controlled
|
||||||
if not me then
|
if not me then
|
||||||
MyModGlobal.debugPrint("No controlled character found")
|
MyModGlobal.debugPrint("No controlled character found")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
MyModGlobal.debugPrint("Selecting fabricator")
|
MyModGlobal.debugPrint("Selecting fabricator")
|
||||||
-- fabricatorComponent.Select(me)
|
-- fabricatorComponent.Select(me)
|
||||||
|
fabricator.Prefab.GrabWhenSelected = false
|
||||||
me.SelectedItem = fabricator
|
me.SelectedItem = fabricator
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tryAccessDeconstructor()
|
---@param force boolean
|
||||||
local items = utils.enqueueAllSubmarineItems({}, function(item)
|
local function tryAccessDeconstructor(force)
|
||||||
return item.Prefab.Identifier.Value == "deconstructor", item.Prefab.Identifier.Value == "deconstructor"
|
local deconstructor = cachedDeconstructor
|
||||||
end)
|
if not deconstructor or force then
|
||||||
if #items == 0 then
|
deconstructor = findByComponent("deconstructor", "Deconstructor")
|
||||||
MyModGlobal.debugPrint("No deconstructor found")
|
if not deconstructor then
|
||||||
return
|
MyModGlobal.debugPrint("No deconstructor found")
|
||||||
end
|
return
|
||||||
if #items > 1 then
|
|
||||||
MyModGlobal.debugPrint("Multiple deconstructors found, using first one")
|
|
||||||
end
|
|
||||||
|
|
||||||
---@type Barotrauma.Item
|
|
||||||
local deconstructor = items[1]
|
|
||||||
---@type Barotrauma.Items.Components.Deconstructor
|
|
||||||
local deconstructorComponent
|
|
||||||
for component in deconstructor.Components do
|
|
||||||
if component.Name == "Deconstructor" then
|
|
||||||
deconstructorComponent = component
|
|
||||||
end
|
end
|
||||||
end
|
cachedDeconstructor = deconstructor
|
||||||
if not deconstructorComponent then
|
|
||||||
MyModGlobal.debugPrint("No deconstructor component found")
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local me = Character.Controlled
|
local me = Character.Controlled
|
||||||
@@ -85,12 +97,39 @@ local function tryAccessDeconstructor()
|
|||||||
MyModGlobal.debugPrint("No controlled character found")
|
MyModGlobal.debugPrint("No controlled character found")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
MyModGlobal.debugPrint("Selecting deconstructor")
|
MyModGlobal.debugPrint("Selecting deconstructor")
|
||||||
-- deconstructorComponent.Select(me)
|
-- deconstructorComponent.Select(me)
|
||||||
|
deconstructor.Prefab.GrabWhenSelected = false
|
||||||
me.SelectedItem = deconstructor
|
me.SelectedItem = deconstructor
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param force boolean
|
||||||
|
local function tryAccessMedicalFabricator(force)
|
||||||
|
local medicalFabricator = cachedMedicalFabricator
|
||||||
|
if not medicalFabricator or force then
|
||||||
|
medicalFabricator = findByComponent("medicalfabricator", "MedicalFabricator")
|
||||||
|
if not medicalFabricator then
|
||||||
|
MyModGlobal.debugPrint("No medical fabricator found")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
cachedMedicalFabricator = medicalFabricator
|
||||||
|
end
|
||||||
|
|
||||||
|
local me = Character.Controlled
|
||||||
|
if not me then
|
||||||
|
MyModGlobal.debugPrint("No controlled character found")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
MyModGlobal.debugPrint("Selecting medical fabricator")
|
||||||
|
-- medicalFabricatorComponent.Select(me)
|
||||||
|
medicalFabricator.Prefab.GrabWhenSelected = false
|
||||||
|
me.SelectedItem = medicalFabricator
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tryAccessFabricator = tryAccessFabricator,
|
tryAccessFabricator = tryAccessFabricator,
|
||||||
tryAccessDeconstructor = tryAccessDeconstructor,
|
tryAccessDeconstructor = tryAccessDeconstructor,
|
||||||
|
tryAccessMedicalFabricator = tryAccessMedicalFabricator,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user