From 835c57faaab3c3f487c4d87f9d82137bd3b2a608 Mon Sep 17 00:00:00 2001 From: ZioPao Date: Tue, 7 Nov 2023 00:39:40 +0100 Subject: [PATCH] Base for working UI --- media/lua/client/TOC_PlayerHandler.lua | 23 ++++++--- media/lua/client/TOC_StaticData.lua | 9 ++++ .../client/TimedActions/TOC_CutLimbAction.lua | 50 ++++++++++++++++++- media/lua/client/UI/TOC_HealthPanel.lua | 48 ++++++++++++++++-- 4 files changed, 118 insertions(+), 12 deletions(-) diff --git a/media/lua/client/TOC_PlayerHandler.lua b/media/lua/client/TOC_PlayerHandler.lua index 97c4551..2df4438 100644 --- a/media/lua/client/TOC_PlayerHandler.lua +++ b/media/lua/client/TOC_PlayerHandler.lua @@ -2,7 +2,6 @@ local ModDataHandler = require("TOC_ModDataHandler") local StaticData = require("TOC_StaticData") ----------- - ---@class PlayerHandler local PlayerHandler = {} @@ -27,16 +26,26 @@ function PlayerHandler.ManageTraits(playerObj) end end +--* Amputations *-- ----comment +---Starts bleeding from the point where the saw is being used +---@param patient IsoPlayer +---@param limbName string +function PlayerHandler.DamageDuringAmputation(patient, limbName) + local bodyDamage = patient:getBodyDamage() + local bodyDamagePart = bodyDamage:getBodyPart(BodyPartType[limbName]) + + bodyDamagePart:setBleeding(true) + bodyDamagePart:setCut(true) + bodyDamagePart:setBleedingTime(ZombRand(10, 20)) +end + +---Do the amputation ---@param patient IsoPlayer ---@param surgeon IsoPlayer ---@param limbName string ---@param surgeryHelpItems table function PlayerHandler.CutLimb(patient, surgeon, limbName, surgeryHelpItems) - - -- TODO Start bleeding and crap like that - local patientStats = patient:getStats() -- TODO Get surgeon ability from his aid skill @@ -78,8 +87,10 @@ end ---@param damageType string ---@param damage number function PlayerHandler.CheckInfection(character, damageType, damage) - + -- This fucking event barely works. Bleeding seems to be the only thing that triggers it + if character ~= getPlayer() then return end + local bd = character:getBodyDamage() for i=1, #StaticData.LIMBS_STRINGS do diff --git a/media/lua/client/TOC_StaticData.lua b/media/lua/client/TOC_StaticData.lua index f748e8d..b63a44e 100644 --- a/media/lua/client/TOC_StaticData.lua +++ b/media/lua/client/TOC_StaticData.lua @@ -73,4 +73,13 @@ for side, _ in pairs(StaticData.SIDES_STRINGS) do end + +--- Textures +StaticData.HEALTH_PANEL_TEXTURES = { + Hand_L = getTexture("media/ui/Hand_L.png"), + ForeArm_L = getTexture("media/ui/ForeArm_L.png"), + UpeerArm_L = getTexture("media/ui/UpperArm_L.png") +} + + return StaticData diff --git a/media/lua/client/TimedActions/TOC_CutLimbAction.lua b/media/lua/client/TimedActions/TOC_CutLimbAction.lua index 5645b63..94aa2a0 100644 --- a/media/lua/client/TimedActions/TOC_CutLimbAction.lua +++ b/media/lua/client/TimedActions/TOC_CutLimbAction.lua @@ -1,9 +1,55 @@ +local PlayerHandler = require("TOC_PlayerHandler") + require "TimedActions/ISBaseTimedAction" +---@class CutLimbAction +---@field patient IsoPlayer +---@field surgeon IsoPlayer +---@field limbName string local CutLimbAction = ISBaseTimedAction:derive("CutLimbAction") -function CutLimbAction:new(patient, surgeon, partName) - print("CUTLIMBACTION") +---Starts CutLimbAction +---@param patient IsoPlayer +---@param surgeon IsoPlayer +---@param limbName string +---@return CutLimbAction +function CutLimbAction:new(patient, surgeon, limbName) + local o = {} + setmetatable(o, self) + self.__index = self + + o.patient = patient + o.surgeon = surgeon + o.limbName = limbName + + o.stopOnWalk = true + o.stopOnRun = true + if o.surgeon:isTimedActionInstant() then o.maxTime = 1 end + + return o +end + +function CutLimbAction:isValid() + -- TODO Surgeon should be close to patient + return true +end + +function CutLimbAction:start() + + print("Damage patient") + if self.patient == self.surgeon then + -- Self + PlayerHandler.DamageDuringAmputation(self.patient, self.limbName) + else + -- Other player + -- TODO Send Damage + end +end + +function CutLimbAction:perform() + + PlayerHandler.CutLimb(self.patient, self.surgeon, self.limbName, {}) + ISBaseTimedAction.perform(self) end return CutLimbAction \ No newline at end of file diff --git a/media/lua/client/UI/TOC_HealthPanel.lua b/media/lua/client/UI/TOC_HealthPanel.lua index 4f6210b..01e0b60 100644 --- a/media/lua/client/UI/TOC_HealthPanel.lua +++ b/media/lua/client/UI/TOC_HealthPanel.lua @@ -1,3 +1,6 @@ +local PlayerHandler = require("TOC_PlayerHandler") +local StaticData = require("TOC_StaticData") + ---@diagnostic disable: duplicate-set-field local CutLimbHandler = require("UI/TOC_CutLimbHandler") @@ -35,18 +38,55 @@ end -- TODO We need male variations -local handL = getTexture("media/ui/Hand_L.png") -local forearmL = getTexture("media/ui/ForeArm_L.png") -local upperarmL = getTexture("media/ui/UpperArm_L.png") + +---@return {partL : string?, partR : string?} +local function GetHighestAmputation() + -- TODO Cache this instead of doing it here! + + local tab = {} + local prevDepSize = {} + for i=1, #StaticData.LIMBS_STRINGS do + local limbName = StaticData.LIMBS_STRINGS[i] + local index + if string.find(limbName, "_L") then index = "L" else index = "R" end + if PlayerHandler.modDataHandler:getIsCut(limbName) then + + if tab[index] ~= nil then + local cDependencySize = #StaticData.LIMBS_DEPENDENCIES[limbName] + if cDependencySize > prevDepSize[index] then + tab[index] = limbName + prevDepSize[index] = StaticData.LIMBS_DEPENDENCIES[limbName] + end + else + tab[index] = limbName + prevDepSize[index] = #StaticData.LIMBS_DEPENDENCIES[limbName] + end + end + + end + return tab +end + local og_ISHealthPanel_render = ISHealthPanel.render function ISHealthPanel:render() og_ISHealthPanel_render(self) + -- TODO Handle another player health panel + + local highestAmputations = GetHighestAmputation() + -- Left Texture + if highestAmputations["L"] then + local textureL = StaticData.HEALTH_PANEL_TEXTURES[highestAmputations["L"]] + self:drawTextureScaled(textureL, self.healthPanel.x/2 - 2, self.healthPanel.y/2, 123, 302, 1, 1, 0, 0) + end + + if highestAmputations["R"] then + + end - --self:drawTextureScaled(forearmL, self.healthPanel.x/2 - 2, self.healthPanel.y/2, 123, 302, 1, 1, 0, 0) -- Right Texture