Reworked structure a bit
This commit is contained in:
85
media/lua/client/Handlers/TOC_AmputationHandler.lua
Normal file
85
media/lua/client/Handlers/TOC_AmputationHandler.lua
Normal file
@@ -0,0 +1,85 @@
|
||||
local ModDataHandler = require("Handlers/TOC_ModDataHandler")
|
||||
local StaticData = require("TOC_StaticData")
|
||||
|
||||
---------------------------
|
||||
|
||||
-- TODO Add Bandages, Torniquet, etc.
|
||||
--- This will be run EXCLUSIVELY on the client which is getting the amputation
|
||||
---@class AmputationHandler
|
||||
---@field patient IsoPlayer
|
||||
---@field limbName string
|
||||
---@field bodyPartType BodyPartType
|
||||
---@field surgeonPl IsoPlayer?
|
||||
local AmputationHandler = {}
|
||||
|
||||
|
||||
---@param limbName string
|
||||
---@param surgeonPl IsoPlayer?
|
||||
---@return AmputationHandler
|
||||
function AmputationHandler:new(limbName, surgeonPl)
|
||||
local o = {}
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
|
||||
o.patient = getPlayer()
|
||||
o.limbName = limbName
|
||||
o.bodyPartType = BodyPartType[self.limbName]
|
||||
if surgeonPl then
|
||||
o.surgeonPl = surgeonPl
|
||||
else
|
||||
o.surgeonPl = o.patient
|
||||
end
|
||||
|
||||
AmputationHandler.instance = o
|
||||
return o
|
||||
end
|
||||
|
||||
---Starts bleeding from the point where the saw is being used
|
||||
function AmputationHandler:damageDuringAmputation()
|
||||
print("TOC: Damage patient")
|
||||
local bodyDamage = self.patient:getBodyDamage()
|
||||
local bodyDamagePart = bodyDamage:getBodyPart(self.bodyPartType)
|
||||
|
||||
bodyDamagePart:setBleeding(true)
|
||||
bodyDamagePart:setCut(true)
|
||||
bodyDamagePart:setBleedingTime(ZombRand(10, 20))
|
||||
end
|
||||
|
||||
---Execute the amputation
|
||||
function AmputationHandler:execute()
|
||||
|
||||
-- TODO Calculate surgeonStats
|
||||
local surgeonFactor = 100
|
||||
|
||||
|
||||
local patientStats = self.patient:getStats()
|
||||
local bd = self.patient:getBodyDamage()
|
||||
local bodyPart = bd:getBodyPart(self.bodyPartType)
|
||||
local baseDamage = StaticData.LIMBS_BASE_DAMAGE[self.limbName]
|
||||
|
||||
-- Set the bleeding and all the damage stuff in that part
|
||||
bodyPart:AddDamage(baseDamage - surgeonFactor)
|
||||
bodyPart:setAdditionalPain(baseDamage - surgeonFactor)
|
||||
bodyPart:setBleeding(true)
|
||||
bodyPart:setBleedingTime(baseDamage - surgeonFactor)
|
||||
bodyPart:setDeepWounded(true)
|
||||
bodyPart:setDeepWoundTime(baseDamage - surgeonFactor)
|
||||
patientStats:setEndurance(surgeonFactor)
|
||||
patientStats:setStress(baseDamage - surgeonFactor)
|
||||
|
||||
-- Set the data in modData
|
||||
ModDataHandler.GetInstance():setCutLimb(self.limbName, false, false, false, self.surgeonFactor)
|
||||
end
|
||||
|
||||
---Force the execution of the amputation for a trait
|
||||
function AmputationHandler:executeForTrait()
|
||||
ModDataHandler.GetInstance():setCutLimb(self.limbName, true, true, true, 0)
|
||||
end
|
||||
|
||||
---Deletes the instance
|
||||
function AmputationHandler:close()
|
||||
AmputationHandler.instance = nil
|
||||
end
|
||||
|
||||
|
||||
return AmputationHandler
|
||||
1
media/lua/client/Handlers/TOC_ItemsHandler.lua
Normal file
1
media/lua/client/Handlers/TOC_ItemsHandler.lua
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
173
media/lua/client/Handlers/TOC_ModDataHandler.lua
Normal file
173
media/lua/client/Handlers/TOC_ModDataHandler.lua
Normal file
@@ -0,0 +1,173 @@
|
||||
local StaticData = require("TOC_StaticData")
|
||||
|
||||
----------------
|
||||
---@alias partData { isCut : boolean?, isInfected : boolean?, isOperated : boolean?, isCicatrized : boolean?, isCauterized : boolean?, isVisible : boolean?, cicatrizationTime : number }
|
||||
---@alias tocModData {Hand_L : partData, ForeArm_L : partData, UpperArm_L : partData, Hand_R : partData, ForeArm_R : partData, UpperArm_R : partData, isIgnoredPartInfected : boolean}
|
||||
----------------
|
||||
-- TODO This class should handle all the stuff related to the mod data
|
||||
|
||||
---@class ModDataHandler
|
||||
---@field playerObj IsoPlayer
|
||||
---@field tocData tocModData
|
||||
local ModDataHandler = {}
|
||||
|
||||
---@param playerObj IsoPlayer
|
||||
---@return ModDataHandler
|
||||
function ModDataHandler:new(playerObj)
|
||||
local o = {}
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
|
||||
o.playerObj = playerObj
|
||||
o.tocData = playerObj:getModData()[StaticData.MOD_NAME]
|
||||
|
||||
ModDataHandler.instance = o
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
---Setup a newly instanced ModDataHandler
|
||||
---@param force boolean?
|
||||
function ModDataHandler:setup(force)
|
||||
local tocData = self.playerObj:getModData()[StaticData.MOD_NAME]
|
||||
if force or tocData == nil or tocData.Hand_L == nil or tocData.Hand_L.isCut == nil then
|
||||
self:createData()
|
||||
end
|
||||
-- TODO Check compatibility or do we just skip it at this point?
|
||||
|
||||
end
|
||||
|
||||
function ModDataHandler:createData()
|
||||
print("TOC: createData")
|
||||
|
||||
local modData = self.playerObj:getModData()
|
||||
modData[StaticData.MOD_NAME] = {
|
||||
|
||||
-- Generic stuff that does not belong anywhere else
|
||||
isIgnoredPartInfected = false
|
||||
}
|
||||
|
||||
---@type partData
|
||||
local defaultParams = {isCut = false, isInfected = false, isOperated = false, isCicatrized = false, isCauterized = false, isVisible = false}
|
||||
|
||||
|
||||
-- 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
|
||||
|
||||
self.tocData = self.playerObj:getModData()[StaticData.MOD_NAME]
|
||||
end
|
||||
|
||||
|
||||
-----------------
|
||||
--* Setters *--
|
||||
|
||||
---Set isCut
|
||||
---@param limbName string
|
||||
---@param isCut boolean
|
||||
function ModDataHandler:setIsCut(limbName, isCut)
|
||||
self.tocData[limbName].isCut = isCut
|
||||
end
|
||||
|
||||
---Set isInfected
|
||||
---@param limbName string
|
||||
---@param isInfected boolean
|
||||
function ModDataHandler:setIsInfected(limbName, isInfected)
|
||||
self.tocData[limbName].isInfected = isInfected
|
||||
end
|
||||
|
||||
---Set isIgnoredPartInfected
|
||||
---@param isIgnoredPartInfected boolean
|
||||
function ModDataHandler:setIsIgnoredPartInfected(isIgnoredPartInfected)
|
||||
self.tocData.isIgnoredPartInfected = isIgnoredPartInfected
|
||||
end
|
||||
|
||||
-----------------
|
||||
--* Getters *--
|
||||
---Get isCut
|
||||
---@param limbName string
|
||||
---@return boolean
|
||||
function ModDataHandler:getIsCut(limbName)
|
||||
return self.tocData[limbName].isCut
|
||||
end
|
||||
|
||||
---Get isIgnoredPartInfected
|
||||
---@return boolean
|
||||
function ModDataHandler:getIsIgnoredPartInfected()
|
||||
return self.tocData.isIgnoredPartInfected
|
||||
end
|
||||
|
||||
---Get isVisible
|
||||
---@return boolean
|
||||
function ModDataHandler:getIsVisible(limbName)
|
||||
return self.tocData[limbName].isVisible
|
||||
end
|
||||
|
||||
|
||||
|
||||
--* Limbs data handling *--
|
||||
|
||||
---Set a limb and its dependend limbs as cut
|
||||
---@param limbName string
|
||||
---@param isOperated boolean
|
||||
---@param isCicatrized boolean
|
||||
---@param isCauterized boolean
|
||||
---@param surgeonFactor number?
|
||||
function ModDataHandler:setCutLimb(limbName, isOperated, isCicatrized, isCauterized, surgeonFactor)
|
||||
local cicatrizationTime = 0
|
||||
if isCicatrized == false or isCauterized == false then
|
||||
cicatrizationTime = StaticData.LIMBS_CICATRIZATION_TIME[limbName] - surgeonFactor
|
||||
end
|
||||
|
||||
---@type partData
|
||||
local params = {isCut = true, isInfected = false, isOperated = isOperated, isCicatrized = isCicatrized, isCauterized = isCauterized, isVisible = true}
|
||||
self:setLimbParams(limbName, params, cicatrizationTime)
|
||||
|
||||
for i=1, #StaticData.LIMBS_DEPENDENCIES[limbName] do
|
||||
local dependedLimbName = StaticData.LIMBS_DEPENDENCIES[limbName][i]
|
||||
|
||||
-- We don't care about isOperated, isCicatrized, isCauterized since this is depending on another limb
|
||||
-- Same story for cicatrizationTime, which will be 0
|
||||
self:setLimbParams(dependedLimbName, {isCut = true, isInfected = false, isVisible = false}, 0)
|
||||
end
|
||||
|
||||
-- Set the highest amputation and caches them.
|
||||
ISHealthPanel.GetHighestAmputation()
|
||||
end
|
||||
|
||||
|
||||
---Internal use only, set a limb data
|
||||
---@param limbName string
|
||||
---@param ampStatus partData {isCut, isInfected, isOperated, isCicatrized, isCauterized, isVisible}
|
||||
---@param cicatrizationTime integer?
|
||||
---@private
|
||||
function ModDataHandler:setLimbParams(limbName, ampStatus, cicatrizationTime)
|
||||
local limbData = self.tocData[limbName]
|
||||
if ampStatus.isCut ~= nil then limbData.isCut = ampStatus.isCut end
|
||||
if ampStatus.isInfected ~= nil then limbData.isInfected = ampStatus.isInfected end
|
||||
if ampStatus.isOperated ~= nil then limbData.isOperated = ampStatus.isOperated end
|
||||
if ampStatus.isCicatrized ~= nil then limbData.isCicatrized = ampStatus.isCicatrized end
|
||||
if ampStatus.isCauterized ~= nil then limbData.isCauterized = ampStatus.isCauterized end
|
||||
if ampStatus.isVisible ~= nil then limbData.isVisible = ampStatus.isVisible end
|
||||
|
||||
if cicatrizationTime ~= nil then limbData.cicatrizationTime = cicatrizationTime end
|
||||
end
|
||||
|
||||
|
||||
|
||||
---@return ModDataHandler
|
||||
function ModDataHandler.GetInstance()
|
||||
if ModDataHandler.instance ~= nil then
|
||||
return ModDataHandler.instance
|
||||
else
|
||||
return ModDataHandler:new(getPlayer())
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
return ModDataHandler
|
||||
92
media/lua/client/Handlers/TOC_PlayerHandler.lua
Normal file
92
media/lua/client/Handlers/TOC_PlayerHandler.lua
Normal file
@@ -0,0 +1,92 @@
|
||||
local ModDataHandler = require("Handlers/TOC_ModDataHandler")
|
||||
local AmputationHandler = require("Handlers/TOC_AmputationHandler")
|
||||
local StaticData = require("TOC_StaticData")
|
||||
-----------
|
||||
|
||||
|
||||
-- LIST OF STUFF THAT THIS CLASS NEEDS TO DO
|
||||
|
||||
-- Main thing, should contain the other handlers when needed
|
||||
-- Handling Items (as in amputations spawns)
|
||||
-- Update current player status (infection checks)
|
||||
-- handle stats increase\decrease
|
||||
|
||||
|
||||
---@class PlayerHandler
|
||||
local PlayerHandler = {}
|
||||
|
||||
-- TODO This should be instanceable for a player. Separate handlers not
|
||||
|
||||
---Setup player modData
|
||||
---@param _ nil
|
||||
---@param playerObj IsoPlayer
|
||||
---@param isForced boolean?
|
||||
function PlayerHandler.InitializePlayer(_, playerObj, isForced)
|
||||
PlayerHandler.modDataHandler = ModDataHandler:new(playerObj)
|
||||
PlayerHandler.modDataHandler:setup(isForced)
|
||||
|
||||
-- Since isForced is used to reset an existing player data, we're gonna clean their ISHealthPanel table too
|
||||
if isForced then
|
||||
ISHealthPanel.highestAmputations = {}
|
||||
end
|
||||
end
|
||||
|
||||
---Handles the traits
|
||||
---@param playerObj IsoPlayer
|
||||
function PlayerHandler.ManageTraits(playerObj)
|
||||
for k, v in pairs(StaticData.TRAITS_BP) do
|
||||
if playerObj:HasTrait(k) then
|
||||
-- Once we find one, we should be done.
|
||||
local tempHandler = AmputationHandler:new(v)
|
||||
tempHandler:executeForTrait()
|
||||
tempHandler:close()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--* Events *--
|
||||
|
||||
---Check if the player has an infected (as in, zombie infection) body part
|
||||
---@param character IsoGameCharacter
|
||||
---@param damageType string
|
||||
---@param damage number
|
||||
function PlayerHandler.CheckInfection(character)
|
||||
|
||||
-- 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
|
||||
local limbName = StaticData.LIMBS_STRINGS[i]
|
||||
local bptEnum = StaticData.BODYPARTSTYPES_ENUM[limbName]
|
||||
local bodyPart = bd:getBodyPart(bptEnum)
|
||||
|
||||
if bodyPart:bitten() or bodyPart:IsInfected() then
|
||||
if PlayerHandler.modDataHandler:getIsCut(limbName) then
|
||||
bodyPart:SetBitten(false)
|
||||
else
|
||||
PlayerHandler.modDataHandler:setIsInfected(limbName, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Check other body parts that are not included in the mod, if there's a bite there then the player is fucked
|
||||
-- We can skip this loop if the player has been infected. The one before we kinda need it to handle correctly the bites in case the player wanna cut stuff off anyway
|
||||
if PlayerHandler.modDataHandler:getIsIgnoredPartInfected() then return end
|
||||
|
||||
for i=1, #StaticData.IGNORED_PARTS_STRINGS do
|
||||
local bodyPartType = BodyPartType[StaticData.IGNORED_PARTS_STRINGS[i]]
|
||||
local bodyPart = bd:getBodyPart(bodyPartType)
|
||||
if bodyPart:bitten() or bodyPart:IsInfected() then
|
||||
PlayerHandler.modDataHandler:setIsIgnoredPartInfected(true)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Events.OnPlayerGetDamage.Add(PlayerHandler.CheckInfection)
|
||||
|
||||
return PlayerHandler
|
||||
1
media/lua/client/Handlers/TOC_ProsthesisHandler.lua
Normal file
1
media/lua/client/Handlers/TOC_ProsthesisHandler.lua
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user