This commit is contained in:
ZioPao
2023-11-13 03:15:37 +01:00
parent 980545a07e
commit deb6dcc056
9 changed files with 31 additions and 136 deletions

View File

@@ -5,9 +5,9 @@ local StaticData = require("TOC/StaticData")
---------------------------
-- TODO Add Bandages, Torniquet, etc.
--- This will be run EXCLUSIVELY on the client which is getting the amputation
--- Manages an amputation. Could be run on either clients
---@class AmputationHandler
---@field patient IsoPlayer
---@field patientPl IsoPlayer
---@field limbName string
---@field bodyPartType BodyPartType
---@field surgeonPl IsoPlayer?
@@ -22,13 +22,13 @@ function AmputationHandler:new(limbName, surgeonPl)
setmetatable(o, self)
self.__index = self
o.patient = getPlayer()
o.patientPl = getPlayer() -- TODO This isn't necessarily true anymore.
o.limbName = limbName
o.bodyPartType = BodyPartType[self.limbName]
if surgeonPl then
o.surgeonPl = surgeonPl
else
o.surgeonPl = o.patient
o.surgeonPl = o.patientPl
end
AmputationHandler.instance = o
@@ -41,7 +41,7 @@ end
---Starts bleeding from the point where the saw is being used
function AmputationHandler:damageDuringAmputation()
TOC_DEBUG.print("damage patient")
local bodyDamage = self.patient:getBodyDamage()
local bodyDamage = self.patientPl:getBodyDamage()
local bodyDamagePart = bodyDamage:getBodyPart(self.bodyPartType)
bodyDamagePart:setBleeding(true)
@@ -58,8 +58,8 @@ function AmputationHandler:execute(damagePlayer)
local surgeonFactor = 1
if damagePlayer == nil then damagePlayer = true end -- Default at true
if damagePlayer then
local patientStats = self.patient:getStats()
local bd = self.patient:getBodyDamage()
local patientStats = self.patientPl:getStats()
local bd = self.patientPl:getBodyDamage()
local bodyPart = bd:getBodyPart(self.bodyPartType)
local baseDamage = StaticData.LIMBS_BASE_DAMAGE[self.limbName]
@@ -76,20 +76,20 @@ function AmputationHandler:execute(damagePlayer)
-- Set the data in modData
-- TODO This could be run on another player!
local modDataHandler = ModDataHandler.GetInstance()
modDataHandler:setCutLimb(self.limbName, false, false, false, surgeonFactor)
modDataHandler:apply()
modDataHandler:apply() -- This will force rechecking the cached amputated limbs on the other client
-- Give the player the correct amputation item
ItemsHandler.DeleteOldAmputationItem(self.patient, self.limbName)
ItemsHandler.SpawnAmputationItem(self.patient, self.limbName)
-- Add it to the list of cut limbs
PlayerHandler.AddLocalAmputatedLimb(self.patient:getUsername(), self.limbName)
-- Set the highest amputation and caches them.
--ISHealthPanel.GetHighestAmputation()
-- TODO We need to consider where this will be ran.
if self.patientPl == self.surgeonPl then
ItemsHandler.DeleteOldAmputationItem(self.patientPl, self.limbName)
ItemsHandler.SpawnAmputationItem(self.patientPl, self.limbName)
else
-- TODO Send server command to manage items and spawn on another player
end
-- Add it to the list of cut limbs on this local client
PlayerHandler.AddLocalAmputatedLimb(self.patientPl:getUsername(), self.limbName)
end
---Deletes the instance

View File

@@ -3,7 +3,7 @@ local CommonMethods = require("TOC/CommonMethods")
---------------------------
--- Submodule to handle spawning the correct items after certain actions (ie: cutting a hand)
--- Submodule to handle spawning the correct items after certain actions (ie: cutting a hand). LOCAL ONLY!
---@class ItemsHandler
local ItemsHandler = {}

View File

@@ -70,7 +70,6 @@ end
---Cache the currently amputated limbs
---@param limbName string
---@private
function PlayerHandler.AddLocalAmputatedLimb(username, limbName)
TOC_DEBUG.print("added " .. limbName .. " to known amputated limbs for " .. username)
table.insert(PlayerHandler.amputatedLimbs[username], limbName) -- TODO This should be player specific, not generic