Fixing prosthesis equipping and unequipping

This commit is contained in:
ZioPao
2023-11-16 19:45:11 +01:00
parent 43cf52cd02
commit fe6d88fa43
4 changed files with 76 additions and 35 deletions

View File

@@ -291,6 +291,7 @@ function ISBaseTimedAction:perform()
PlayerHandler.playerObj:getXp():AddXP(Perks["Side_" .. side], 1) -- TODO Make it dynamic
local prostGroup = StaticData.LIMBS_TO_PROST_GROUP_MATCH_IND_STR[limbName]
if not modDataHandler:getIsCicatrized(limbName) and modDataHandler:getIsProstEquipped(prostGroup) then
TOC_DEBUG.print("Trying for bleed, player met the criteria")
PlayerHandler.TryRandomBleed(self.character, limbName)
end
end

View File

@@ -61,6 +61,23 @@ function ProsthesisHandler.CheckIfEquippable(bodyLocation)
-- No acceptable cut limbs
return false
end
---Handle equipping or unequipping prosthetics
---@param item InventoryItem
---@param isEquipping boolean
function ProsthesisHandler.SearchAndSetupProsthesis(item, isEquipping)
if not ProsthesisHandler.CheckIfProst(item) then return end
local group = ProsthesisHandler.GetGroup(item)
TOC_DEBUG.print("applying prosthesis stuff for " .. group)
local modDataHandler = ModDataHandler.GetInstance()
modDataHandler:setIsProstEquipped(group, isEquipping)
modDataHandler:apply()
end
-------------------------
--* Events *--
@@ -70,29 +87,41 @@ end
-------------------------
--* Overrides *--
-- ---@diagnostic disable-next-line: duplicate-set-field
-- function ISWearClothing:isValid()
-- TOC_DEBUG.print("ISWearClothing:isValid")
-- local bodyLocation = self.item:getBodyLocation()
-- if not string.contains(bodyLocation, bodyLocArmProst) then
-- return true
-- else
-- return ProsthesisHandler.CheckIfEquippable(bodyLocation)
-- end
-- end
---@diagnostic disable-next-line: duplicate-set-field
local og_ISWearClothing_isValid = ISWearClothing.isValid
function ISWearClothing:isValid()
local isEquippable = og_ISWearClothing_isValid(self)
local isProst = ProsthesisHandler.CheckIfProst(self.item)
if not isProst then return isEquippable end
--the item that we gets is the OG one, so if we're coming from the left one and wanna switch to the right one we're still gonna get the Left bodylocation
local bodyLocation = self.item:getBodyLocation()
if isEquippable and string.contains(bodyLocation, bodyLocArmProst) then
isEquippable = ProsthesisHandler.CheckIfEquippable(bodyLocation)
end
return isEquippable
end
local og_ISWearClothing_perform = ISWearClothing.perform
function ISWearClothing:perform()
og_ISWearClothing_perform(self)
ProsthesisHandler.SearchAndSetupProsthesis(self.item, true)
end
local og_ISClothingExtraAction_isValid = ISClothingExtraAction.isValid
---@diagnostic disable-next-line: duplicate-set-field
function ISClothingExtraAction:isValid()
local isEquippable = og_ISClothingExtraAction_isValid(self)
local isProst = ProsthesisHandler.CheckIfProst(self.itemExtra)
if not isProst then return isEquippable end
--the item that we gets is the OG one, so if we're coming from the left one and wanna switch to the right one we're still gonna get the Left bodylocation
-- TODO isValid can be run multiple times, for some reason.
local testItem = InventoryItemFactory.CreateItem(self.extra)
local bodyLocation = testItem:getBodyLocation()
local isEquippable = og_ISClothingExtraAction_isValid(self)
if isEquippable and not string.contains(bodyLocation, bodyLocArmProst) then
isEquippable = true
else
if isEquippable and string.contains(bodyLocation, bodyLocArmProst) then
isEquippable = ProsthesisHandler.CheckIfEquippable(bodyLocation)
end
@@ -104,21 +133,19 @@ function ISClothingExtraAction:stop()
og_ISClothingExtraAction_stop(self)
if ProsthesisHandler.CheckIfProst(self.item) then
getPlayer():Say(getText("UI_Say_CantEquip"))
end
end
local og_ISClothingExtraAction_perform = ISClothingExtraAction.perform
function ISClothingExtraAction:perform()
if ProsthesisHandler.CheckIfProst(self.item) then
local group = ProsthesisHandler.GetGroup(self.item)
TOC_DEBUG.print("applying prosthesis stuff for " .. group)
local modDataHandler = ModDataHandler.GetInstance()
modDataHandler:setIsProstEquipped(group, true)
modDataHandler:apply()
end
og_ISClothingExtraAction_perform(self)
ProsthesisHandler.SearchAndSetupProsthesis(self.item, true)
end
local og_ISUnequipAction_perform = ISUnequipAction.perform
function ISUnequipAction:perform()
og_ISUnequipAction_perform(self)
ProsthesisHandler.SearchAndSetupProsthesis(self.item, false)
end

View File

@@ -1,5 +1,6 @@
local PlayerHandler = require("TOC/Handlers/PlayerHandler")
local CommonMethods = require("TOC/CommonMethods")
local CommandsData = require("TOC/CommandsData")
------------------
@@ -51,6 +52,9 @@ end
function Main.Initialize()
-- TODO In SP we should clean Global Mod Data when a player dies!
---Looop until we've successfully initialized the mod
local function TryToInitialize()
local pl = getPlayer()
@@ -66,7 +70,18 @@ function Main.Initialize()
CommonMethods.SafeStartEvent("OnTick", TryToInitialize)
end
---Clean the TOC table for that SP player, to prevent from clogging it up
---@param player IsoPlayer
function Main.WipeSinglePlayerData(player)
local key = CommandsData.GetKey(player:getUsername())
ModData.remove(key)
ModData.transmit(key)
end
--* Events *--
Events.OnGameBoot.Add(Main.Start)
if not isClient() and not isServer() then
Events.OnPlayerDeath.Add(Main.WipeSinglePlayerData)
end

View File

@@ -17,8 +17,8 @@ module TOC
ClothingItemExtraOption = InstallProstRight,
clothingExtraSubmenu = InstallProstLeft,
BodyLocation = TOC_ArmProst_L,
Weight = 0,
CombatSpeedModifier = 0.7,
Weight = 1.5,
CombatSpeedModifier = 1.1,
BloodLocation = UpperArms;UpperBody,
Insulation = 1.0,
WindResistance = 1.0,
@@ -36,9 +36,8 @@ module TOC
ClothingItemExtraOption = InstallProstLeft,
clothingExtraSubmenu = InstallProstRight,
BodyLocation = TOC_ArmProst_R,
Weight = 0,
CombatSpeedModifier = 0.7,
Weight = 1.5,
CombatSpeedModifier = 1.1,
BloodLocation = UpperArms;UpperBody,
Insulation = 1.0,
WindResistance = 1.0,
@@ -57,8 +56,8 @@ module TOC
ClothingItemExtraOption = InstallProstRight,
clothingExtraSubmenu = InstallProstLeft,
BodyLocation = TOC_ArmProst_L,
Weight = 0,
CombatSpeedModifier = 0.7,
Weight = 2,
CombatSpeedModifier = 1.5,
BloodLocation = UpperArms;UpperBody,
Insulation = 1.0,
WindResistance = 1.0,
@@ -76,9 +75,8 @@ module TOC
ClothingItemExtraOption = InstallProstLeft,
clothingExtraSubmenu = InstallProstRight,
BodyLocation = TOC_ArmProst_R,
Weight = 0,
CombatSpeedModifier = 0.7,
Weight = 2,
CombatSpeedModifier = 1.5,
BloodLocation = UpperArms;UpperBody,
Insulation = 1.0,
WindResistance = 1.0,