From bd8e4d6c86e5582974baf40362e08886db87eefe Mon Sep 17 00:00:00 2001 From: ZioPao Date: Tue, 30 Apr 2024 17:09:18 +0200 Subject: [PATCH] Implemented Tourniquet functionality for amputations --- .../TOC/Controllers/LocalPlayerController.lua | 41 ------------------- media/lua/client/TOC/Events.lua | 1 - .../client/TOC/Handlers/AmputationHandler.lua | 39 +++++++++++++++++- media/lua/shared/TOC/BodyLocations.lua | 3 ++ media/scripts/TOC_surgery_items.txt | 4 +- 5 files changed, 43 insertions(+), 45 deletions(-) diff --git a/media/lua/client/TOC/Controllers/LocalPlayerController.lua b/media/lua/client/TOC/Controllers/LocalPlayerController.lua index 4816021..c0ae031 100644 --- a/media/lua/client/TOC/Controllers/LocalPlayerController.lua +++ b/media/lua/client/TOC/Controllers/LocalPlayerController.lua @@ -282,47 +282,6 @@ function LocalPlayerController.ToggleUpdateAmputations() CommonMethods.SafeStartEvent("EveryHours", LocalPlayerController.UpdateAmputations) end ---* Tourniquet handling -function LocalPlayerController.HandleTourniquet() - -- TODO Add it!!! - - -- TODO Triggered at startup or when Clothing Updates. - - - - -- local playerObj = getPlayer() - - - -- for bl, ampGroup in pairs(StaticData.TOURNIQUET_BODYLOCS_TO_GROUPS_IND_STR) do - -- local item = playerObj:getWornItem(bl) - - -- if item then - -- -- TODO Set to DataControlle - -- local cicTime = DataController.GetInstance():setTourniquet - - -- end - - -- end - - -- for i=1, #tourniquetBodyLocations do - -- local bl = tourniquetBodyLocations[i] - - - -- if item and item:getFullType():contains("Surg_Arm_Tourniquet_") - - -- end - -- local item = playerObj:getWornItem(bodyLocation) - - -- local wornItems = playerObj:getWornItems() - -- for j=1,wornItems:size() do - -- local wornItem = wornItems:get(j-1) - - -- end -end - -Events.OnPuttingTourniquet.Add(LocalPlayerController.HandleTourniquet) - - --* Object drop handling when amputation occurs diff --git a/media/lua/client/TOC/Events.lua b/media/lua/client/TOC/Events.lua index f9620de..13b9246 100644 --- a/media/lua/client/TOC/Events.lua +++ b/media/lua/client/TOC/Events.lua @@ -1,4 +1,3 @@ --* Setup Events *-- LuaEventManager.AddEvent("OnAmputatedLimb") --Triggered when a limb has been amputated LuaEventManager.AddEvent("OnReceivedTocData") -- Triggered when TOC data is ready -LuaEventManager.AddEvent("OnPuttingTourniquet") \ No newline at end of file diff --git a/media/lua/client/TOC/Handlers/AmputationHandler.lua b/media/lua/client/TOC/Handlers/AmputationHandler.lua index 0f8c9ae..2c11fc8 100644 --- a/media/lua/client/TOC/Handlers/AmputationHandler.lua +++ b/media/lua/client/TOC/Handlers/AmputationHandler.lua @@ -3,6 +3,7 @@ local ItemsController = require("TOC/Controllers/ItemsController") local CachedDataHandler = require("TOC/Handlers/CachedDataHandler") local LocalPlayerController = require("TOC/Controllers/LocalPlayerController") local StaticData = require("TOC/StaticData") +local CommonMethods = require("TOC/CommonMethods") --------------------------- --- Manages an amputation. Will be run on the patient client @@ -41,6 +42,31 @@ end --* Static methods *-- + +---@param player IsoPlayer +---@param limbName string +---@return boolean +function AmputationHandler.CheckTourniquet(player, limbName) + + local side = CommonMethods.GetSide(limbName) + + local wornItems = player:getWornItems() + for j=1,wornItems:size() do + local wornItem = wornItems:get(j-1) + + local fType = wornItem:getItem():getFullType() + if string.contains(fType, "Surg_Arm_Tourniquet_") then + -- Check side + if luautils.stringEnds(fType, side) then + TOC_DEBUG.print("Found acceptable tourniquet") + return true + end + end + end + + return false +end + ---@param player IsoPlayer ---@param limbName string function AmputationHandler.ApplyDamageDuringAmputation(player, limbName) @@ -120,7 +146,7 @@ end ---Set the damage to the adjacent part of the cut area ---@param surgeonFactor number function AmputationHandler:damageAfterAmputation(surgeonFactor) - -- TODO Torniquet should reduce the damage in total, less blood loss + TOC_DEBUG.print("Applying damage after amputation") local patientStats = self.patientPl:getStats() @@ -130,6 +156,17 @@ function AmputationHandler:damageAfterAmputation(surgeonFactor) local bodyPart = bd:getBodyPart(BodyPartType[adjacentLimb]) local baseDamage = StaticData.LIMBS_BASE_DAMAGE_IND_NUM[self.limbName] + + -- TODO Torniquet should reduce the damage in total, less blood loss + -- Check if player has tourniquet equipped on the limb + + local hasTourniquet = AmputationHandler.CheckTourniquet(self.patientPl, self.limbName) + if hasTourniquet then + TOC_DEBUG.print("Do something different for the damage calculation because tourniquet is applied") + baseDamage = baseDamage * 0.5 -- 50% less damage due to tourniquet + end + + bodyPart:AddDamage(baseDamage - surgeonFactor) bodyPart:setAdditionalPain(baseDamage - surgeonFactor) bodyPart:setBleeding(true) diff --git a/media/lua/shared/TOC/BodyLocations.lua b/media/lua/shared/TOC/BodyLocations.lua index 76b9203..aa1fb2e 100644 --- a/media/lua/shared/TOC/BodyLocations.lua +++ b/media/lua/shared/TOC/BodyLocations.lua @@ -53,3 +53,6 @@ group:setMultiItem("TOC_Arm", true) BodyLocationsAPI.MoveOrCreateBeforeOrAfter("TOC_ArmProst", "TOC_Arm", true) group:setMultiItem("TOC_ArmProst", true) + +BodyLocationsAPI.MoveOrCreateBeforeOrAfter("TOC_ArmAccessory", "TOC_ArmProst", true) +group:setMultiItem("TOC_ArmAccessory", true) \ No newline at end of file diff --git a/media/scripts/TOC_surgery_items.txt b/media/scripts/TOC_surgery_items.txt index da46bd9..44e6939 100644 --- a/media/scripts/TOC_surgery_items.txt +++ b/media/scripts/TOC_surgery_items.txt @@ -15,7 +15,7 @@ module TOC ClothingItemExtra = Surg_Arm_Tourniquet_R, ClothingItemExtraOption = PutTourniquetArmRight, clothingExtraSubmenu = PutTourniquetArmLeft, - BodyLocation = HandsLeft, + BodyLocation = TOC_ArmAccessory, BloodLocation = UpperArms;UpperBody, Weight = 1, @@ -34,7 +34,7 @@ module TOC ClothingItemExtra = Surg_Arm_Tourniquet_L, ClothingItemExtraOption = PutTourniquetArmLeft, clothingExtraSubmenu = PutTourniquetArmRight, - BodyLocation = HandsRight, + BodyLocation = TOC_ArmAccessory, BloodLocation = UpperArms;UpperBody, Weight = 1,