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
|
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")
|
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
|
---@class PlayerHandler
|
||||||
local PlayerHandler = {}
|
local PlayerHandler = {}
|
||||||
|
|
||||||
|
-- TODO This should be instanceable for a player. Separate handlers not
|
||||||
|
|
||||||
---Setup player modData
|
---Setup player modData
|
||||||
---@param _ nil
|
---@param _ nil
|
||||||
@@ -20,71 +31,20 @@ function PlayerHandler.InitializePlayer(_, playerObj, isForced)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---Cut a limb for a trait
|
---Handles the traits
|
||||||
---@param playerObj IsoPlayer
|
---@param playerObj IsoPlayer
|
||||||
function PlayerHandler.ManageTraits(playerObj)
|
function PlayerHandler.ManageTraits(playerObj)
|
||||||
for k, v in pairs(StaticData.TRAITS_BP) do
|
for k, v in pairs(StaticData.TRAITS_BP) do
|
||||||
if playerObj:HasTrait(k) then
|
if playerObj:HasTrait(k) then
|
||||||
-- Once we find one, we should be done.
|
-- Once we find one, we should be done.
|
||||||
PlayerHandler.ForceCutLimb(v)
|
local tempHandler = AmputationHandler:new(v)
|
||||||
|
tempHandler:executeForTrait()
|
||||||
|
tempHandler:close()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
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 *--
|
--* Events *--
|
||||||
|
|
||||||
@@ -92,7 +52,7 @@ end
|
|||||||
---@param character IsoGameCharacter
|
---@param character IsoGameCharacter
|
||||||
---@param damageType string
|
---@param damageType string
|
||||||
---@param damage number
|
---@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
|
-- This fucking event barely works. Bleeding seems to be the only thing that triggers it
|
||||||
if character ~= getPlayer() then return end
|
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 TestFramework = require("TestFramework/TestFramework")
|
||||||
local TestUtils = require("TestFramework/TestUtils")
|
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"
|
require "TimedActions/ISBaseTimedAction"
|
||||||
|
local AmputationHandler = require("Handlers/TOC_AmputationHandler")
|
||||||
|
|
||||||
|
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
---@class CutLimbAction
|
---@class CutLimbAction
|
||||||
---@field patient IsoPlayer
|
---@field patient IsoPlayer
|
||||||
@@ -35,11 +37,10 @@ function CutLimbAction:isValid()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function CutLimbAction:start()
|
function CutLimbAction:start()
|
||||||
|
|
||||||
print("Damage patient")
|
|
||||||
if self.patient == self.surgeon then
|
if self.patient == self.surgeon then
|
||||||
-- Self
|
-- Self
|
||||||
PlayerHandler.DamageDuringAmputation(self.patient, self.limbName)
|
self.handler = AmputationHandler:new(self.limbName)
|
||||||
|
self.handler:damageDuringAmputation()
|
||||||
else
|
else
|
||||||
-- Other player
|
-- Other player
|
||||||
-- TODO Send Damage
|
-- TODO Send Damage
|
||||||
@@ -47,8 +48,7 @@ function CutLimbAction:start()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function CutLimbAction:perform()
|
function CutLimbAction:perform()
|
||||||
|
self.handler:execute()
|
||||||
PlayerHandler.CutLimb(self.patient, self.surgeon, self.limbName, {})
|
|
||||||
ISBaseTimedAction.perform(self)
|
ISBaseTimedAction.perform(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user