diff --git a/media/lua/client/TOC_ModDataHandler.lua b/media/lua/client/TOC_ModDataHandler.lua index e9b5351..d077c19 100644 --- a/media/lua/client/TOC_ModDataHandler.lua +++ b/media/lua/client/TOC_ModDataHandler.lua @@ -27,7 +27,9 @@ end ---Setup a newly instanced ModDataHandler function ModDataHandler:setup() local modData = self.playerObj:getModData()[StaticData.MOD_NAME] - if modData == nil then self:createData() end + if modData == nil or modData.Hand_L == nil or modData.Hand_L.isCut == nil then + self:createData() + end -- TODO Check compatibility or do we just skip it at this point? end @@ -35,13 +37,17 @@ end function ModDataHandler:createData() print("TOC: createData") - self.playerObj:getModData()[StaticData.MOD_NAME] = {} + local modData = self.playerObj:getModData() + modData[StaticData.MOD_NAME] = {} ---@type amputationTable local defaultParams = {isCut = false, isInfected = false, isOperated = false, isCicatrized = false, isCauterized = false, isDependant = false} + local test = StaticData.LIMBS_STRINGS -- Initialize limbs for i=1, #StaticData.LIMBS_STRINGS do + local limbName = StaticData.LIMBS_STRINGS[i] + modData[StaticData.MOD_NAME][limbName] = {} self:setLimbParams(StaticData.LIMBS_STRINGS[i], defaultParams, 0) end end diff --git a/media/lua/client/TOC_PlayerHandler.lua b/media/lua/client/TOC_PlayerHandler.lua index 8f4966a..0ad4f93 100644 --- a/media/lua/client/TOC_PlayerHandler.lua +++ b/media/lua/client/TOC_PlayerHandler.lua @@ -65,7 +65,7 @@ end ---Set an already cut limb, for example for a trait. ---@param limbName string function PlayerHandler.ForceCutLimb(limbName) - PlayerHandler.modDataHandler:setCutLimb(limbName, true, true, true) + PlayerHandler.modDataHandler:setCutLimb(limbName, true, true, true, 0) -- TODO Spawn amputation item end diff --git a/media/lua/client/TOC_StaticData.lua b/media/lua/client/TOC_StaticData.lua index f3988d2..f7f5470 100644 --- a/media/lua/client/TOC_StaticData.lua +++ b/media/lua/client/TOC_StaticData.lua @@ -19,17 +19,25 @@ StaticData.LIMBS_STRINGS = {} StaticData.BODYPARTSTYPES_ENUM = {} StaticData.LIMBS_DEPENDENCIES = {} StaticData.LIMBS_CICATRIZATION_TIME = {} +StaticData.LIMBS_BASE_DAMAGE = {} -for i = 1, #StaticData.SIDES_STRINGS do - local side = StaticData.PARTS_STRINGS[i] - for y = 1, #StaticData.PARTS_STRINGS do - local part = StaticData.PARTS_STRINGS[y] + +-- Link a trait to a specific body part +StaticData.TRAITS_BP = { + AmputeeHand = "Hand_L", + AmputeeLowerArm = "ForeArm_L", + AmputeeUpeerArm = "UpperArm_L" +} + +for side, _ in pairs(StaticData.SIDES_STRINGS) do + for part, _ in pairs(StaticData.PARTS_STRINGS) do local assembledName = part .. "_" .. side -- Assembled strings - StaticData.LIMBS_STRINGS[assembledName] = assembledName + table.insert(StaticData.LIMBS_STRINGS, assembledName) -- We need a table like this to cycle through it easily StaticData.BODYPARTSTYPES_ENUM[assembledName] = BodyPartType[assembledName] - + + print(assembledName) -- Dependencies and cicatrization time if part == StaticData.PARTS_STRINGS.Hand then StaticData.LIMBS_BASE_DAMAGE[assembledName] = 60 @@ -39,7 +47,7 @@ for i = 1, #StaticData.SIDES_STRINGS do StaticData.LIMBS_BASE_DAMAGE[assembledName] = 80 StaticData.LIMBS_CICATRIZATION_TIME[assembledName] = 1800 StaticData.LIMBS_DEPENDENCIES[assembledName] = { side .. StaticData.PARTS_STRINGS.Hand } - elseif part == StaticData.PART_STRINGS.UpperArm then + elseif part == StaticData.PARTS_STRINGS.UpperArm then StaticData.LIMBS_BASE_DAMAGE[assembledName] = 100 StaticData.LIMBS_CICATRIZATION_TIME[assembledName] = 2000 StaticData.LIMBS_DEPENDENCIES[assembledName] = { side .. "_" .. StaticData.PARTS_STRINGS.Hand, @@ -48,17 +56,6 @@ for i = 1, #StaticData.SIDES_STRINGS do end end --- Link a trait to a specific body part -StaticData.TRAITS_BP = { - AmputeeHand = "Hand_L", - AmputeeLowerArm = "ForeArm_L", - AmputeeUpeerArm = "UpperArm_L" -} - - --------- - -StaticData.AMPUTATION_VALUES = {} diff --git a/media/lua/client/TOC_Test.lua b/media/lua/client/TOC_Test.lua index bb6b936..e08a739 100644 --- a/media/lua/client/TOC_Test.lua +++ b/media/lua/client/TOC_Test.lua @@ -6,9 +6,14 @@ local TestUtils = require("TestFramework/TestUtils") TestFramework.registerTestModule("Functionality", "Cut Left Hand", function() local Tests = {} + local PlayerHandler = require("TOC_PlayerHandler") function Tests.CutLeftHand() - + local pl = getPlayer() + PlayerHandler.InitializePlayer(nil, pl) + PlayerHandler.ForceCutLimb("Hand_L") end + return Tests + end) \ No newline at end of file diff --git a/media/lua/client/UI/TOC_CutLimbHandler.lua b/media/lua/client/UI/TOC_CutLimbHandler.lua index 35c6ea5..8cd5b31 100644 --- a/media/lua/client/UI/TOC_CutLimbHandler.lua +++ b/media/lua/client/UI/TOC_CutLimbHandler.lua @@ -2,6 +2,8 @@ local BaseHandler = require("UI/TOC_HealthPanelBaseHandler") local CutLimbAction = require("TimedActions/TOC_CutLimbAction") ---@class CutLimbHandler +---@field panel any +---@field bodyPart any local CutLimbHandler = BaseHandler:derive("CutLimbHandler") diff --git a/media/lua/client/UI/TOC_HealthPanel.lua b/media/lua/client/UI/TOC_HealthPanel.lua index e07d919..4f6210b 100644 --- a/media/lua/client/UI/TOC_HealthPanel.lua +++ b/media/lua/client/UI/TOC_HealthPanel.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: duplicate-set-field local CutLimbHandler = require("UI/TOC_CutLimbHandler") -- TODO Use this to replace the sprites once a limb is cut @@ -22,7 +23,9 @@ local og_ISHealthPanel_doBodyPartContextMenu = ISHealthPanel.doBodyPartContextMe function ISHealthPanel:doBodyPartContextMenu(bodyPart, x, y) og_ISHealthPanel_doBodyPartContextMenu(self, bodyPart, x, y) local playerNum = self.otherPlayer and self.otherPlayer:getPlayerNum() or self.character:getPlayerNum() - local context = getPlayerContextMenu(playerNum) -- To not recreate it but reuse the one that has been created in the original method + + -- To not recreate it but reuse the one that has been created in the original method + local context = getPlayerContextMenu(playerNum) local cutLimbHandler = CutLimbHandler:new(self, bodyPart) cutLimbHandler:addToMenu(context) end @@ -30,6 +33,7 @@ end --* Modification to handle visible amputation on the health menu *-- +-- TODO We need male variations local handL = getTexture("media/ui/Hand_L.png") local forearmL = getTexture("media/ui/ForeArm_L.png")