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 @@
|
||||
|
||||
@@ -158,4 +158,16 @@ end
|
||||
|
||||
|
||||
|
||||
---@return ModDataHandler
|
||||
function ModDataHandler.GetInstance()
|
||||
if ModDataHandler.instance ~= nil then
|
||||
return ModDataHandler.instance
|
||||
else
|
||||
return ModDataHandler:new(getPlayer())
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
return ModDataHandler
|
||||
@@ -1,10 +1,21 @@
|
||||
local ModDataHandler = require("TOC_ModDataHandler")
|
||||
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
|
||||
@@ -20,71 +31,20 @@ function PlayerHandler.InitializePlayer(_, playerObj, isForced)
|
||||
end
|
||||
end
|
||||
|
||||
---Cut a limb for a trait
|
||||
---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.
|
||||
PlayerHandler.ForceCutLimb(v)
|
||||
local tempHandler = AmputationHandler:new(v)
|
||||
tempHandler:executeForTrait()
|
||||
tempHandler:close()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--* Amputations *--
|
||||
|
||||
---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)
|
||||
local patientStats = patient:getStats()
|
||||
|
||||
-- TODO Get surgeon ability from his aid skill
|
||||
local surgeonSkill = 50
|
||||
local surgeonFactor = surgeonSkill - 1 -- TODO Should be decided by surgeryHelpItems
|
||||
|
||||
local bd = patient:getBodyDamage()
|
||||
local bodyPart = bd:getBodyPart(BodyPartType[limbName])
|
||||
local baseDamage = StaticData.LIMBS_BASE_DAMAGE[limbName]
|
||||
|
||||
-- Set the bleeding and all the damage stuff in that part
|
||||
bodyPart:AddDamage(baseDamage - surgeonSkill)
|
||||
bodyPart:setAdditionalPain(baseDamage - surgeonSkill)
|
||||
bodyPart:setBleeding(true)
|
||||
bodyPart:setBleedingTime(baseDamage - surgeonSkill)
|
||||
bodyPart:setDeepWounded(true)
|
||||
bodyPart:setDeepWoundTime(baseDamage - surgeonSkill)
|
||||
patientStats:setEndurance(surgeonSkill)
|
||||
patientStats:setStress(baseDamage - surgeonSkill)
|
||||
|
||||
PlayerHandler.modDataHandler:setCutLimb(limbName, false, false, false, surgeonFactor)
|
||||
|
||||
end
|
||||
|
||||
|
||||
---Set an already cut limb, for example for a trait.
|
||||
---@param limbName string
|
||||
function PlayerHandler.ForceCutLimb(limbName)
|
||||
PlayerHandler.modDataHandler:setCutLimb(limbName, true, true, true, 0)
|
||||
-- TODO Spawn amputation item
|
||||
end
|
||||
|
||||
|
||||
|
||||
--* Events *--
|
||||
|
||||
@@ -92,7 +52,7 @@ end
|
||||
---@param character IsoGameCharacter
|
||||
---@param damageType string
|
||||
---@param damage number
|
||||
function PlayerHandler.CheckInfection(character, damageType, damage)
|
||||
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
|
||||
1
media/lua/client/Handlers/TOC_ProsthesisHandler.lua
Normal file
1
media/lua/client/Handlers/TOC_ProsthesisHandler.lua
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
-- TODO Spawn items
|
||||
|
||||
-- TODO Remove Items
|
||||
|
||||
-- TODO Check if item make sense to be here or whatever
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local PlayerHandler = require("TOC_PlayerHandler")
|
||||
local PlayerHandler = require("Handlers/TOC_PlayerHandler")
|
||||
|
||||
|
||||
------------------
|
||||
|
||||
@@ -2,7 +2,7 @@ if not getActivatedMods():contains("TEST_FRAMEWORK") or not isDebugEnabled() the
|
||||
local TestFramework = require("TestFramework/TestFramework")
|
||||
local TestUtils = require("TestFramework/TestUtils")
|
||||
|
||||
local PlayerHandler = require("TOC_PlayerHandler")
|
||||
local PlayerHandler = require("Handlers/TOC_PlayerHandler")
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
local PlayerHandler = require("TOC_PlayerHandler")
|
||||
|
||||
require "TimedActions/ISBaseTimedAction"
|
||||
local AmputationHandler = require("Handlers/TOC_AmputationHandler")
|
||||
|
||||
|
||||
-----------------------------
|
||||
|
||||
---@class CutLimbAction
|
||||
---@field patient IsoPlayer
|
||||
@@ -35,11 +37,10 @@ function CutLimbAction:isValid()
|
||||
end
|
||||
|
||||
function CutLimbAction:start()
|
||||
|
||||
print("Damage patient")
|
||||
if self.patient == self.surgeon then
|
||||
-- Self
|
||||
PlayerHandler.DamageDuringAmputation(self.patient, self.limbName)
|
||||
self.handler = AmputationHandler:new(self.limbName)
|
||||
self.handler:damageDuringAmputation()
|
||||
else
|
||||
-- Other player
|
||||
-- TODO Send Damage
|
||||
@@ -47,8 +48,7 @@ function CutLimbAction:start()
|
||||
end
|
||||
|
||||
function CutLimbAction:perform()
|
||||
|
||||
PlayerHandler.CutLimb(self.patient, self.surgeon, self.limbName, {})
|
||||
self.handler:execute()
|
||||
ISBaseTimedAction.perform(self)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user