diff --git a/media/lua/client/TOC/Handlers/PlayerHandler.lua b/media/lua/client/TOC/Handlers/PlayerHandler.lua index 79ce2d5..787a990 100644 --- a/media/lua/client/TOC/Handlers/PlayerHandler.lua +++ b/media/lua/client/TOC/Handlers/PlayerHandler.lua @@ -251,6 +251,14 @@ function PlayerHandler.ToggleCicatrizationUpdate() end +--* Helper functions for overrides *-- + +local function CheckHandFeasibility(limbName) + local modDataHandler = ModDataHandler.GetInstance() + + return not modDataHandler:getIsCut(limbName) or modDataHandler:getIsProstEquipped(StaticData.LIMBS_TO_PROST_GROUP_MATCH_IND_STR[limbName]) +end + ------------------------------------------ --* OVERRIDES *-- @@ -315,14 +323,9 @@ end --* Equipping items overrides *-- -local equipPrimaryText = getText("ContextMenu_Equip_Primary") -local equipSecondaryText = getText("ContextMenu_Equip_Secondary") - local primaryHand = StaticData.PARTS_IND_STR.Hand .. "_" .. StaticData.SIDES_IND_STR.R local secondaryHand = StaticData.PARTS_IND_STR.Hand .. "_" .. StaticData.SIDES_IND_STR.L -local prostTopR = StaticData.PROSTHESES_GROUPS_IND_STR.Top_R -local prostTopL = StaticData.PROSTHESES_GROUPS_IND_STR.Top_L local og_ISEquipWeaponAction_isValid = ISEquipWeaponAction.isValid ---Add a condition to check the feasibility of having 2 handed weapons or if both arms are cut off @@ -332,30 +335,30 @@ function ISEquipWeaponAction:isValid() local isValid = og_ISEquipWeaponAction_isValid(self) local modDataHandler = ModDataHandler.GetInstance(self.character:getUsername()) if isValid and modDataHandler:getIsAnyLimbCut() then - local isPrimaryHandValid = not modDataHandler:getIsCut(primaryHand) or modDataHandler:getIsProstEquipped(prostTopR) - local isSecondaryHandValid = not modDataHandler:getIsCut(secondaryHand) or modDataHandler:getIsProstEquipped(prostTopL) + local isPrimaryHandValid = CheckHandFeasibility(primaryHand) + local isSecondaryHandValid = CheckHandFeasibility(secondaryHand) --TOC_DEBUG.print("isPrimaryHandValid: " .. tostring(isPrimaryHandValid)) --TOC_DEBUG.print("isSecondaryHandValid: " .. tostring(isSecondaryHandValid)) - -- Both hands are cut off + -- Both hands are cut off, so it's impossible to equip in any way if not isPrimaryHandValid and not isSecondaryHandValid then --TOC_DEBUG.print("Both hands invalid") isValid = false end - - -- Equip primary and no right hand (with no prost) - if self.jobType:contains(equipPrimaryText) and not isPrimaryHandValid then - --TOC_DEBUG.print("Equip primary, no right hand, not valid") - isValid = false - end - - -- Equip secondary and no left hand (with no prost) - if self.jobType:contains(equipSecondaryText) and not isSecondaryHandValid then - --TOC_DEBUG.print("Equip secondary, no left hand, not valid") - isValid = false - end end + -- -- Equip primary and no right hand (with no prost) + -- if self.jobType:contains(equipPrimaryText) and not isPrimaryHandValid then + -- --TOC_DEBUG.print("Equip primary, no right hand, not valid") + -- isValid = false + -- end + + -- -- Equip secondary and no left hand (with no prost) + -- if self.jobType:contains(equipSecondaryText) and not isSecondaryHandValid then + -- --TOC_DEBUG.print("Equip secondary, no left hand, not valid") + -- isValid = false + -- end + -- end --TOC_DEBUG.print("isValid to return -> " .. tostring(isValid)) --print("_________________________________") @@ -372,9 +375,7 @@ function ISEquipWeaponAction:performWithAmputation(modDataHandler) -- TODO Simplify this local hand = nil - local prostGroup = nil local otherHand = nil - local otherProstGroup = nil local getMethodFirst = nil local setMethodFirst = nil local getMethodSecond = nil @@ -382,18 +383,14 @@ function ISEquipWeaponAction:performWithAmputation(modDataHandler) if self.primary then hand = StaticData.LIMBS_IND_STR.Hand_R - prostGroup = StaticData.PROSTHESES_GROUPS_IND_STR.Top_R otherHand = StaticData.LIMBS_IND_STR.Hand_L - otherProstGroup = StaticData.PROSTHESES_GROUPS_IND_STR.Top_L getMethodFirst = self.character.getSecondaryHandItem setMethodFirst = self.character.setSecondaryHandItem getMethodSecond = self.character.getPrimaryHandItem setMethodSecond = self.character.setPrimaryHandItem else hand = StaticData.LIMBS_IND_STR.Hand_L - prostGroup = StaticData.PROSTHESES_GROUPS_IND_STR.Top_L otherHand = StaticData.LIMBS_IND_STR.Hand_R - otherProstGroup = StaticData.PROSTHESES_GROUPS_IND_STR.Top_R getMethodFirst = self.character.getPrimaryHandItem setMethodFirst = self.character.setPrimaryHandItem getMethodSecond = self.character.getSecondaryHandItem @@ -404,35 +401,33 @@ function ISEquipWeaponAction:performWithAmputation(modDataHandler) if not self.twoHands then if getMethodFirst(self.character) and getMethodFirst(self.character):isRequiresEquippedBothHands() then setMethodFirst(self.character, nil) - end -- if this weapon is already equiped in the 2nd hand, we remove it - if(getMethodFirst(self.character) == self.item or getMethodFirst(self.character) == getMethodSecond(self.character)) then + elseif (getMethodFirst(self.character) == self.item or getMethodFirst(self.character) == getMethodSecond(self.character)) then setMethodFirst(self.character, nil) - end -- if we are equipping a handgun and there is a weapon in the secondary hand we remove it - if instanceof(self.item, "HandWeapon") and self.item:getSwingAnim() and self.item:getSwingAnim() == "Handgun" then + elseif instanceof(self.item, "HandWeapon") and self.item:getSwingAnim() and self.item:getSwingAnim() == "Handgun" then if getMethodFirst(self.character) and instanceof(getMethodFirst(self.character), "HandWeapon") then setMethodFirst(self.character, nil) end - end - if not getMethodSecond(self.character) or getMethodSecond(self.character) ~= self.item then + else setMethodSecond(self.character, nil) - -- TODO We should use the CachedData indexable instead of modDataHandler if not modDataHandler:getIsCut(hand) then setMethodSecond(self.character, self.item) - else + -- Check other HAND! + elseif not modDataHandler:getIsCut(otherHand) then setMethodFirst(self.character, self.item) end end + else setMethodFirst(self.character, nil) setMethodSecond(self.character, nil) - local isFirstValid = not modDataHandler:getIsCut(hand) or modDataHandler:getIsProstEquipped(prostGroup) - local isSecondValid = not modDataHandler:getIsCut(otherHand) or modDataHandler:getIsProstEquipped(otherProstGroup) + local isFirstValid = CheckHandFeasibility(hand) + local isSecondValid = CheckHandFeasibility(otherHand) -- TOC_DEBUG.print("First Hand: " .. tostring(hand)) -- TOC_DEBUG.print("Prost Group: " .. tostring(prostGroup)) -- TOC_DEBUG.print("Other Hand: " .. tostring(otherHand)) @@ -455,11 +450,11 @@ end local og_ISEquipWeaponAction_perform = ISEquipWeaponAction.perform ---@diagnostic disable-next-line: duplicate-set-field function ISEquipWeaponAction:perform() + og_ISEquipWeaponAction_perform(self) -- TODO Can we do it earlier? local modDataHandler = ModDataHandler.GetInstance(self.character:getUsername()) - -- Just check it any limb has been cut. If not, we can just return from here if modDataHandler:getIsAnyLimbCut() == true then self:performWithAmputation(modDataHandler) @@ -467,5 +462,38 @@ function ISEquipWeaponAction:perform() end +function ISInventoryPaneContextMenu.doEquipOption(context, playerObj, isWeapon, items, player) + + + -- check if hands if not heavy damaged + if (not playerObj:isPrimaryHandItem(isWeapon) or (playerObj:isPrimaryHandItem(isWeapon) and playerObj:isSecondaryHandItem(isWeapon))) and not getSpecificPlayer(player):getBodyDamage():getBodyPart(BodyPartType.Hand_R):isDeepWounded() and (getSpecificPlayer(player):getBodyDamage():getBodyPart(BodyPartType.Hand_R):getFractureTime() == 0 or getSpecificPlayer(player):getBodyDamage():getBodyPart(BodyPartType.Hand_R):getSplintFactor() > 0) then + -- forbid reequipping skinned items to avoid multiple problems for now + local add = true + if playerObj:getSecondaryHandItem() == isWeapon and isWeapon:getScriptItem():getReplaceWhenUnequip() then + add = false + end + if add then + local equipOption = context:addOption(getText("ContextMenu_Equip_Primary"), items, ISInventoryPaneContextMenu.OnPrimaryWeapon, player) + equipOption.notAvailable = not CheckHandFeasibility(StaticData.LIMBS_IND_STR.Hand_R) + end + + + end + + if (not playerObj:isSecondaryHandItem(isWeapon) or (playerObj:isPrimaryHandItem(isWeapon) and playerObj:isSecondaryHandItem(isWeapon))) and not getSpecificPlayer(player):getBodyDamage():getBodyPart(BodyPartType.Hand_L):isDeepWounded() and (getSpecificPlayer(player):getBodyDamage():getBodyPart(BodyPartType.Hand_L):getFractureTime() == 0 or getSpecificPlayer(player):getBodyDamage():getBodyPart(BodyPartType.Hand_L):getSplintFactor() > 0) then + -- forbid reequipping skinned items to avoid multiple problems for now + local add = true + if playerObj:getPrimaryHandItem() == isWeapon and isWeapon:getScriptItem():getReplaceWhenUnequip() then + add = false + end + if add then + local equipOption = context:addOption(getText("ContextMenu_Equip_Secondary"), items, ISInventoryPaneContextMenu.OnSecondWeapon, player) + + equipOption.notAvailable = not CheckHandFeasibility(StaticData.LIMBS_IND_STR.Hand_L) + + end + end +end + return PlayerHandler \ No newline at end of file diff --git a/media/lua/client/TOC/UI/SurgeryInteractions.lua b/media/lua/client/TOC/UI/SurgeryInteractions.lua index faeb0ca..7f722f4 100644 --- a/media/lua/client/TOC/UI/SurgeryInteractions.lua +++ b/media/lua/client/TOC/UI/SurgeryInteractions.lua @@ -51,18 +51,26 @@ local function AddOvenContextMenu(playerNum, context, worldObjects, test) local isTempLow = stoveObj:getCurrentTemperature() < 250 local tempTooltip = ISToolTip:new() tempTooltip:initialise() - tempTooltip:setName("ContextMenu_Cauterize_TempTooLow_tooltip") + tempTooltip:setName(getText("ContextMenu_Cauterize_TempTooLow_tooltip")) tempTooltip.description = getText("Tooltip_Surgery_TempTooLow") tempTooltip:setVisible(false) - local optionMain = context:addOption(getText("ContextMenu_Cauterize"), nil) - local subMenu = context:getNew(context) - context:addSubMenu(optionMain, subMenu) + local addMainOption = false + local subMenu + for k, _ in pairs(amputatedLimbs) do -- We need to let the player cauterize ONLY the visible one! local limbName = k - if modDataHandler:getIsVisible(limbName) then + if modDataHandler:getIsVisible(limbName) and not modDataHandler:getIsCicatrized(limbName) then + if addMainOption == false then + -- Adds the cauterize option ONLY when it's needed + local optionMain = context:addOption(getText("ContextMenu_Cauterize"), nil) + subMenu = context:getNew(context) + context:addSubMenu(optionMain, subMenu) + addMainOption = true + end + local option = subMenu:addOption(getText("ContextMenu_Limb_" .. limbName), limbName, Cauterize) option.notAvailable = isTempLow if isTempLow then