From 9a4572258e9374a3c66db9f12db119ed50f69bc9 Mon Sep 17 00:00:00 2001 From: Pao Date: Fri, 17 Feb 2023 12:50:15 +0100 Subject: [PATCH] Added changes from hotfix --- .../lua/client/ActionsMethods/TOC_CutLimb.lua | 15 ++- media/lua/client/TOC_ModCompatibility.lua | 126 ++++++++++++++++-- 2 files changed, 130 insertions(+), 11 deletions(-) diff --git a/media/lua/client/ActionsMethods/TOC_CutLimb.lua b/media/lua/client/ActionsMethods/TOC_CutLimb.lua index 0d07300..9b4494e 100644 --- a/media/lua/client/ActionsMethods/TOC_CutLimb.lua +++ b/media/lua/client/ActionsMethods/TOC_CutLimb.lua @@ -66,6 +66,17 @@ local function TocDeleteOtherAmputatedLimbs(side) end +---@param player any +---@param perk any The perk to scale down +local function LosePerkLevel(player, perk) + player:LoseLevel(perk) + local actual_level = player:getPerkLevel(perk) + local perk_xp = player:getXp() + perk_xp:setXPToLevel(perk, actual_level) + SyncXp(player) + +end + ---@param heal_bite boolean local function TocSetParametersForMissingLimb(body_part, heal_bite) body_part:setBleeding(false) @@ -172,8 +183,8 @@ function TocCutLimb(part_name, surgeon_factor, bandage_table, painkiller_table) -- Set malus for strength and fitness -- TODO Make it more "random" with just some XP scaling down instead of a whole level, depending on the limb that we're cutting - player:LoseLevel(Perks.Fitness) - player:LoseLevel(Perks.Strength) + LosePerkLevel(player, Perks.Fitness) + LosePerkLevel(player, Perks.Strength) diff --git a/media/lua/client/TOC_ModCompatibility.lua b/media/lua/client/TOC_ModCompatibility.lua index 3262d42..1dc70e1 100644 --- a/media/lua/client/TOC_ModCompatibility.lua +++ b/media/lua/client/TOC_ModCompatibility.lua @@ -4,20 +4,15 @@ TOC_ModTable = { FancyHandwork = false, + SwapIt = false, LeftIsRight = false, } - local function SetCompatibilityFancyHandwork() - if getActivatedMods():contains('FancyHandwork') == false then return end - require "TimedActions/FHSwapHandsAction" - - 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() @@ -26,8 +21,10 @@ local function SetCompatibilityFancyHandwork() local limbs_data = getPlayer():getModData().TOC.Limbs local can_be_held = {} + -- TODO not totally realiable TocPopulateCanBeHeldTable(can_be_held, limbs_data) + -- 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)) @@ -76,6 +73,7 @@ local function SetCompatibilityFancyHandwork() local og_FHSwapHandsAction = FHSwapHandsAction.start + function FHSwapHandsAction:isValid() local limbs_data = getPlayer():getModData().TOC.Limbs local can_be_held = {} @@ -91,8 +89,118 @@ local function SetCompatibilityLeftIsRight() -- This check is needed since we're gonna add a little check in adjustMaxTime -- to prevent problems with maxTime scaling TOC_ModTable.LeftIsRight = true - + end -Events.OnGameStart.Add(SetCompatibilityFancyHandwork) -Events.OnGameStart.Add(SetCompatibilityLeftIsRight) +local function SetCompatibilityFancyHandWorkAndSwapIt() + + SetCompatibilityFancyHandwork() + + -- Override equip Item once again with the necessary changes + function ISHotbar:equipItem(item) + 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 = {} + + -- TODO not totally realiable + TocPopulateCanBeHeldTable(can_be_held, limbs_data) + + + -- 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 + --print("TOC: Fancy Handwork modifier") + -- 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())) + elseif can_be_held["Right"] then + 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())) + elseif can_be_held["Left"] then + ISTimedActionQueue.add(ISEquipWeaponAction:new(self.chr, item, 20, false, item:isTwoHandWeapon())) + + end + end + + -- Swap It part + local i_slotinuse = item:getAttachedSlot() + local slot = self.availableSlot[i_slotinuse] + local slotIndexID = "swap_Hotbar"..i_slotinuse + if slot and SwapItConfig.config[slotIndexID] == true then + if primary and not self:isInHotbar(primary) and self:canBeAttached(slot, primary) then + self:removeItem(item, false)--false = don't run animation + self:attachItem(primary, slot.def.attachments[primary:getAttachmentType()], i_slotinuse, slot.def, true) + end + end + + end + + self.chr:getInventory():setDrawDirty(true) + getPlayerData(self.chr:getPlayerNum()).playerInventory:refreshBackpacks() + end + + +end + +-------------------------------------------------------- + +function TOC_CheckModCompatibility() + local activated_mods = getActivatedMods() + print("TOC: Checking mods") + + + if activated_mods:contains("FancyHandwork") then + + if activated_mods:contains("SwapIt") then + require "SwapIt Main" + print("TOC: Overriding FancyHandwork and SwapIt methods") + SetCompatibilityFancyHandWorkAndSwapIt() + else + print("TOC: Overriding FancyHandwork methods") + require "TimedActions/FHSwapHandsAction" + SetCompatibilityFancyHandwork() + end + end + + if activated_mods:contains("LeftIsRight") then + TOC_ModTable.LeftIsRight = true + end + + + + +end + +print("TOC: Starting CheckModCompatibility") + +Events.OnGameStart.Add(TOC_CheckModCompatibility) +