Added compatibility with Fancy Handwork

This commit is contained in:
Pao
2023-01-27 11:07:23 +01:00
parent f1ff587621
commit af85135fb6
4 changed files with 143 additions and 20 deletions

View File

@@ -44,6 +44,12 @@
"BloodBodyPartType", "BloodBodyPartType",
"ISInventoryPane", "ISInventoryPane",
"ModData", "ModData",
"isDebugEnabled" "isDebugEnabled",
"getActivatedMods",
"ISHotbar",
"isForceDropHeavyItem",
"isFHModKeyDown",
"getPlayerData",
"FHSwapHandsAction"
] ]
} }

View File

@@ -92,7 +92,6 @@ function TocDamagePlayerDuringAmputation(patient, part_name)
body_damage_part:setBleedingTime(ZombRand(10, 20)) body_damage_part:setBleedingTime(ZombRand(10, 20))
end end
---@param body_part BodyPartType
---@param heal_bite boolean ---@param heal_bite boolean
function TocSetParametersForMissingLimb(body_part, heal_bite) function TocSetParametersForMissingLimb(body_part, heal_bite)
body_part:setBleeding(false) body_part:setBleeding(false)
@@ -251,3 +250,23 @@ function CheckIfItemIsInstalledProsthesis(item)
end end
end end
function TocPopulateCanBeHeldTable(can_be_held, limbs_data)
for _, side in ipairs(TOC_sides) do
can_be_held[side] = true
if limbs_data[side .. "_Hand"].is_cut then
if limbs_data[side .. "_LowerArm"].is_cut then
if not limbs_data[side .. "_LowerArm"].is_prosthesis_equipped then
can_be_held[side] = false
end
elseif not limbs_data[side .. "_Hand"].is_prosthesis_equipped then
can_be_held[side] = false
end
end
end
return
end

View File

@@ -0,0 +1,109 @@
---------------------------------
-- Compatibility for various mods
---------------------------------
local function OverrideFancyHandwork()
if getActivatedMods():contains('FancyHandwork') == false then return end
local og_ISHotbar_equipItem = ISHotbar.equipItem
function ISHotbar:equipItem(item)
print("TOC: Overriding FancyHandwork methods")
local mod = isFHModKeyDown()
local primary = self.chr:getPrimaryHandItem()
local secondary = self.chr:getSecondaryHandItem()
local equip = true
local limbs_data = getPlayer():getModData().TOC.Limbs
local can_be_held = {}
TocPopulateCanBeHeldTable(can_be_held, limbs_data)
for _, test in pairs(can_be_held) do
print(test)
end
--ISInventoryPaneContextMenu.transferIfNeeded(self.chr, item)
-- If we already have the item equipped
if (primary and primary == item) or (secondary and secondary == item) then
ISTimedActionQueue.add(ISUnequipAction:new(self.chr, item, 20))
equip = false
end
-- If we didn't just do something
if equip then
-- Handle holding big objects
if primary and isForceDropHeavyItem(primary) then
ISTimedActionQueue.add(ISUnequipAction:new(self.chr, primary, 50))
----- treat "equip" as if we have something equipped from here down
equip = false
end
if mod then
-- If we still have something equipped in secondary, unequip
if secondary and equip and can_be_held["Left"] then
ISTimedActionQueue.add(ISUnequipAction:new(self.chr, secondary, 20))
end
if can_be_held["Left"] then
ISTimedActionQueue.add(ISEquipWeaponAction:new(self.chr, item, 20, false, item:isTwoHandWeapon()))
else
ISTimedActionQueue.add(ISEquipWeaponAction:new(self.chr, item, 20, true, item:isTwoHandWeapon()))
end
else
-- If we still have something equipped in primary, unequip
if primary and equip and can_be_held["Right"] then
ISTimedActionQueue.add(ISUnequipAction:new(self.chr, primary, 20))
end
-- Equip Primary
if can_be_held["Right"] then
ISTimedActionQueue.add(ISEquipWeaponAction:new(self.chr, item, 20, true, item:isTwoHandWeapon()))
else
ISTimedActionQueue.add(ISEquipWeaponAction:new(self.chr, item, 20, false, item:isTwoHandWeapon()))
end
end
end
self.chr:getInventory():setDrawDirty(true)
getPlayerData(self.chr:getPlayerNum()).playerInventory:refreshBackpacks()
end
local og_FHSwapHandsAction = FHSwapHandsAction.start
function FHSwapHandsAction:start()
local limbs_data = getPlayer():getModData().TOC.Limbs
local can_be_held = {}
TocPopulateCanBeHeldTable(can_be_held, limbs_data)
if self.itemL and can_be_held["Right"] then
self.itemL:setJobType(getText("ContextMenu_Equip_Primary") .. " " .. self.itemL:getName())
self.itemL:setJobDelta(0.0)
else
self:stop()
return
end
if self.itemR and can_be_held["Left"] then
self.itemR:setJobType(getText("ContextMenu_Equip_Secondary") .. " " .. self.itemR:getName())
self.itemR:setJobDelta(0.0)
else
self:stop()
return
end
self:setActionAnim("EquipItem")
self:setOverrideHandModels(self.itemR, self.itemL)
end
end
Events.OnGameStart.Add(OverrideFancyHandwork)

View File

@@ -10,10 +10,10 @@ function ISBaseTimedAction:adjustMaxTime(maxTime)
-- TODO Make the malus for time a little less awful and add some other malus, like fitness and stuff -- TODO Make the malus for time a little less awful and add some other malus, like fitness and stuff
print("TOC: Input max time " .. tostring(maxTime)) --print("TOC: Input max time " .. tostring(maxTime))
local original_max_time = og_ISEquipTimedActionAdjustMaxTime(self, maxTime) local original_max_time = og_ISEquipTimedActionAdjustMaxTime(self, maxTime)
print("TOC: Return original max time: " .. tostring(original_max_time)) --print("TOC: Return original max time: " .. tostring(original_max_time))
if original_max_time ~= -1 then if original_max_time ~= -1 then
@@ -61,7 +61,7 @@ function ISBaseTimedAction:adjustMaxTime(maxTime)
if modified_max_time > 10 * original_max_time then modified_max_time = 10 * original_max_time end if modified_max_time > 10 * original_max_time then modified_max_time = 10 * original_max_time end
print("TOC: Modified Max Time " .. modified_max_time) --print("TOC: Modified Max Time " .. modified_max_time)
return modified_max_time return modified_max_time
else else
@@ -124,24 +124,13 @@ end
local og_ISEquipWeaponActionPerform = ISEquipWeaponAction.perform local og_ISEquipWeaponActionPerform = ISEquipWeaponAction.perform
function ISEquipWeaponAction:perform() function ISEquipWeaponAction:perform()
-- TODO this is only for weapons, not items. Won't work for everything I think
--TODO Block it before even performing
-- TODO in the inventory menu there is something broken, even though this works -- TODO in the inventory menu there is something broken, even though this works
og_ISEquipWeaponActionPerform(self) og_ISEquipWeaponActionPerform(self)
local part_data = self.character:getModData().TOC.Limbs local limbs_data = self.character:getModData().TOC.Limbs
local can_be_held = {} local can_be_held = {}
TocPopulateCanBeHeldTable(can_be_held, limbs_data)
for _, side in ipairs(TOC_sides) do
can_be_held[side] = true
if part_data[side .. "_Hand"].is_cut then
if part_data[side .. "_LowerArm"].is_cut then
if not part_data[side .. "_LowerArm"].is_prosthesis_equipped then
can_be_held[side] = false
end
elseif not part_data[side .. "_Hand"].is_prosthesis_equipped then
can_be_held[side] = false
end
end
end
if not self.item:isRequiresEquippedBothHands() then if not self.item:isRequiresEquippedBothHands() then
if can_be_held["Right"] and not can_be_held["Left"] then if can_be_held["Right"] and not can_be_held["Left"] then