Implemented Tourniquet functionality for amputations

This commit is contained in:
ZioPao
2024-04-30 17:09:18 +02:00
parent c4529d0890
commit bd8e4d6c86
5 changed files with 43 additions and 45 deletions

View File

@@ -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

View File

@@ -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")

View File

@@ -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)

View File

@@ -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)

View File

@@ -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,