Making it a bit neater
This commit is contained in:
6
media/lua/client/TOC_ItemsHandler.lua
Normal file
6
media/lua/client/TOC_ItemsHandler.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
-- TODO Spawn items
|
||||
|
||||
-- TODO Remove Items
|
||||
|
||||
-- TODO Check if item make sense to be here or whatever
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
local StaticData = require("TOC_StaticData")
|
||||
|
||||
----------------
|
||||
---@alias amputationTable { isCut : boolean?, isInfected : boolean?, isOperated : boolean?, isCicatrized : boolean?, isCauterized : boolean?, isDependant : boolean? }
|
||||
|
||||
----------------
|
||||
-- TODO This class should handle all the stuff related to the mod data
|
||||
|
||||
@@ -33,8 +36,8 @@ function ModDataHandler:createData()
|
||||
self.playerObj:getModData()[StaticData.MOD_NAME] = {}
|
||||
|
||||
-- Initialize limbs
|
||||
for i=1, #StaticData.BP_STRINGS do
|
||||
self:setLimbParams(StaticData.BP_STRINGS[i], false, false, false, false, false, false)
|
||||
for i=1, #StaticData.LIMBS_STRINGS do
|
||||
self:setLimbParams(StaticData.LIMBS_STRINGS[i], false, false, false, false, false, false)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,45 +46,56 @@ end
|
||||
|
||||
---Set a limb and its dependend limbs as cut
|
||||
---@param limbName string
|
||||
function ModDataHandler:setCutLimb(limbName, isOperated, isCicatrized, isCauterized)
|
||||
self:setLimbParams(limbName, true, false, isOperated, isCicatrized, isCauterized, false)
|
||||
---@param amputationStatus amputationTable {isOperated, isCicatrized, isCauterized}
|
||||
---@param surgeonFactor number
|
||||
function ModDataHandler:setCutLimb(limbName, amputationStatus, surgeonFactor)
|
||||
local cicatrizationTime = -1
|
||||
if amputationStatus.isCicatrized == false or amputationStatus.isCauterized == false then
|
||||
cicatrizationTime = StaticData.LIMBS_CICATRIZATION_TIME[limbName] - surgeonFactor
|
||||
end
|
||||
|
||||
for i=1, #StaticData.LIMB_DEPENDENCIES[limbName] do
|
||||
local dependedLimbName = StaticData.LIMB_DEPENDENCIES[limbName][i]
|
||||
---@type amputationTable
|
||||
local params = {isCut = true, isInfected = false, isOperated = amputationStatus.isOperated, isCicatrized = amputationStatus.isCicatrized, isCauterized = amputationStatus.isCauterized, isDependant = false}
|
||||
self:setLimbParams(limbName, params, cicatrizationTime)
|
||||
|
||||
local dependentParams = {isCut = true, isInfected = false, isDependant = true}
|
||||
|
||||
for i=1, #StaticData.LIMBS_DEPENDENCIES[limbName] do
|
||||
local dependedLimbName = StaticData.LIMBS_DEPENDENCIES[limbName][i]
|
||||
|
||||
-- We don't care about isOperated, isCicatrized and isCauterized since this is depending on another limb
|
||||
self:setLimbParams(dependedLimbName, true, false, nil, nil, nil, true)
|
||||
self:setLimbParams(dependedLimbName, dependentParams, cicatrizationTime)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
---Internal use only, set a limb data
|
||||
---@param limbName string
|
||||
---@param isCut boolean?
|
||||
---@param isInfected boolean?
|
||||
---@param isOperated boolean?
|
||||
---@param isCicatrized boolean?
|
||||
---@param isCauterized boolean?
|
||||
---@param isDependant boolean?
|
||||
---@param amputationStatus amputationTable {isCut, isInfected, isOperated, isCicatrized, isCauterized, isDependant}
|
||||
---@param cicatrizationTime integer
|
||||
---@private
|
||||
function ModDataHandler:setLimbParams(limbName, isCut, isInfected, isOperated, isCicatrized, isCauterized, isDependant)
|
||||
function ModDataHandler:setLimbParams(limbName, amputationStatus, cicatrizationTime)
|
||||
local limbData = self.playerObj:getModData()[StaticData.MOD_NAME][limbName]
|
||||
if isCut ~= nil then
|
||||
limbData.isCut = isCut
|
||||
if amputationStatus.isCut ~= nil then
|
||||
limbData.isCut = amputationStatus.isCut
|
||||
end
|
||||
if isInfected ~= nil then
|
||||
limbData.isInfected = isInfected
|
||||
if amputationStatus.isInfected ~= nil then
|
||||
limbData.isInfected = amputationStatus.isInfected
|
||||
end
|
||||
if isOperated ~= nil then
|
||||
limbData.isOperated = isOperated
|
||||
if amputationStatus.isOperated ~= nil then
|
||||
limbData.isOperated = amputationStatus.isOperated
|
||||
end
|
||||
if isCicatrized ~= nil then
|
||||
limbData.isCicatrized = isCicatrized
|
||||
if amputationStatus.isCicatrized ~= nil then
|
||||
limbData.isCicatrized = amputationStatus.isCicatrized
|
||||
end
|
||||
if isCauterized ~= nil then
|
||||
limbData.isCauterized = isCauterized
|
||||
if amputationStatus.isCauterized ~= nil then
|
||||
limbData.isCauterized = amputationStatus.isCauterized
|
||||
end
|
||||
if isDependant ~= nil then
|
||||
limbData.isDependant = isDependant
|
||||
if amputationStatus.isDependant ~= nil then
|
||||
limbData.isDependant = amputationStatus.isDependant
|
||||
end
|
||||
if cicatrizationTime ~= nil then
|
||||
limbData.cicatrizationTime = cicatrizationTime
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -11,36 +11,63 @@ local PlayerHandler = {}
|
||||
---@param _ nil
|
||||
---@param playerObj IsoPlayer
|
||||
function PlayerHandler.InitializePlayer(_, playerObj)
|
||||
|
||||
PlayerHandler.modDataHandler = ModDataHandler:new(playerObj)
|
||||
PlayerHandler.modDataHandler:setup()
|
||||
|
||||
end
|
||||
|
||||
---...
|
||||
---Cut a limb for a trait
|
||||
---@param playerObj IsoPlayer
|
||||
function PlayerHandler.ManageTraits(playerObj)
|
||||
|
||||
for k,v in pairs(StaticData.TRAITS_BP) do
|
||||
if playerObj:HasTrait(k) then PlayerHandler.ForceCutLimb(v) end
|
||||
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)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- -- Setup traits
|
||||
-- if player:HasTrait("Amputee_Hand") then
|
||||
-- TOC.CutLimbForTrait(player, modData.TOC, "Left_Hand")
|
||||
-- elseif player:HasTrait("Amputee_LowerArm") then
|
||||
-- TOC.CutLimbForTrait(player, modData.TOC, "Left_LowerArm")
|
||||
-- elseif player:HasTrait("Amputee_UpperArm") then
|
||||
-- TOC.CutLimbForTrait(player, modData.TOC, "Left_UpperArm")
|
||||
-- end
|
||||
end
|
||||
|
||||
|
||||
---comment
|
||||
---@param patient IsoPlayer
|
||||
---@param surgeon IsoPlayer
|
||||
---@param limbName string
|
||||
---@param surgeryHelpItems table
|
||||
function PlayerHandler.CutLimb(patient, surgeon, limbName, surgeryHelpItems)
|
||||
|
||||
-- TODO Start bleeding and crap like that
|
||||
|
||||
local patientStats = patient:getStats()
|
||||
|
||||
-- TODO Get surgeon ability from his aid skill
|
||||
local surgeonSkill = 50
|
||||
|
||||
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)
|
||||
|
||||
---@type amputationTable
|
||||
local amputationValues = {isOperated = false, isCicatrized = false, isCauterized = false}
|
||||
PlayerHandler.modDataHandler:setCutLimb(limbName, amputationValues)
|
||||
|
||||
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)
|
||||
-- TODO Spawn amputation item
|
||||
end
|
||||
|
||||
|
||||
return PlayerHandler
|
||||
@@ -1,90 +1,63 @@
|
||||
local StaticData = {}
|
||||
|
||||
|
||||
StaticData.MOD_NAME = "TOC"
|
||||
|
||||
|
||||
StaticData.SIDES_STRINGS = {
|
||||
Right = "Right",
|
||||
Left = "Left"
|
||||
}
|
||||
|
||||
StaticData.PARTS_STRINGS = {
|
||||
Hand = "Hand",
|
||||
LowerArm = "LowerArm",
|
||||
ForeArm = "ForeArm",
|
||||
UpperArm = "UpperArm"
|
||||
}
|
||||
|
||||
|
||||
StaticData.SIDES_STRINGS = {
|
||||
R = "R",
|
||||
L = "L"
|
||||
}
|
||||
-- Assembled BodyParts string
|
||||
---@enum
|
||||
StaticData.BP_STRINGS = {}
|
||||
StaticData.LIMB_DEPENDENCIES = {}
|
||||
StaticData.LIMB_CICATRIZATION_TIME = {}
|
||||
StaticData.LIMBS_STRINGS = {}
|
||||
StaticData.LIMBS_DEPENDENCIES = {}
|
||||
StaticData.LIMBS_CICATRIZATION_TIME = {}
|
||||
|
||||
for i=1, #StaticData.SIDES_STRINGS do
|
||||
for i = 1, #StaticData.SIDES_STRINGS do
|
||||
local side = StaticData.PARTS_STRINGS[i]
|
||||
for y=1, #StaticData.PARTS_STRINGS do
|
||||
for y = 1, #StaticData.PARTS_STRINGS do
|
||||
local part = StaticData.PARTS_STRINGS[y]
|
||||
local assembledName = side .. part
|
||||
local assembledName = part .. "_" .. side
|
||||
|
||||
-- Assembled strings
|
||||
StaticData.BP_STRINGS[assembledName] = assembledName
|
||||
StaticData.LIMBS_STRINGS[assembledName] = assembledName
|
||||
|
||||
-- Dependencies and cicatrization time
|
||||
if part == StaticData.PARTS_STRINGS.Hand then
|
||||
StaticData.LIMB_CICATRIZATION_TIME[assembledName] = 1700
|
||||
StaticData.LIMB_DEPENDENCIES[assembledName] = {}
|
||||
elseif part == StaticData.PARTS_STRINGS.LowerArm then
|
||||
StaticData.LIMB_CICATRIZATION_TIME[assembledName] = 1800
|
||||
StaticData.LIMB_DEPENDENCIES[assembledName] = {side .. StaticData.PARTS_STRINGS.Hand}
|
||||
|
||||
StaticData.LIMBS_BASE_DAMAGE[assembledName] = 60
|
||||
StaticData.LIMBS_CICATRIZATION_TIME[assembledName] = 1700
|
||||
StaticData.LIMBS_DEPENDENCIES[assembledName] = {}
|
||||
elseif part == StaticData.PARTS_STRINGS.ForeArm then
|
||||
StaticData.LIMBS_BASE_DAMAGE[assembledName] = 80
|
||||
StaticData.LIMBS_CICATRIZATION_TIME[assembledName] = 1800
|
||||
StaticData.LIMBS_DEPENDENCIES[assembledName] = { side .. StaticData.PARTS_STRINGS.Hand }
|
||||
elseif part == StaticData.PART_STRINGS.UpperArm then
|
||||
StaticData.LIMB_CICATRIZATION_TIME[assembledName] = 2000
|
||||
StaticData.LIMB_DEPENDENCIES[assembledName] = {side .. StaticData.PARTS_STRINGS.Hand, side .. StaticData.PARTS_STRINGS.LowerArm}
|
||||
StaticData.LIMBS_BASE_DAMAGE[assembledName] = 100
|
||||
StaticData.LIMBS_CICATRIZATION_TIME[assembledName] = 2000
|
||||
StaticData.LIMBS_DEPENDENCIES[assembledName] = { side .. "_" .. StaticData.PARTS_STRINGS.Hand,
|
||||
side .. "_" .. StaticData.PARTS_STRINGS.ForeArm }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Link a trait to a specific body part
|
||||
StaticData.TRAITS_BP = {
|
||||
AmputeeHand = "LeftHand",
|
||||
AmputeeLowerArm = "LeftLowerArm",
|
||||
AmputeeUpeerArm = "LeftUpperArm"
|
||||
AmputeeHand = "Hand_L",
|
||||
AmputeeLowerArm = "ForeArm_L",
|
||||
AmputeeUpeerArm = "UpperArm_L"
|
||||
}
|
||||
|
||||
|
||||
--------
|
||||
|
||||
StaticData.AMPUTATION_VALUES = {}
|
||||
|
||||
|
||||
|
||||
return StaticData
|
||||
|
||||
|
||||
-- TODO We should pick BodyPartType or strings, not both. It's a mess
|
||||
|
||||
|
||||
-- TODO We need strings for
|
||||
-- Searching items
|
||||
-- ...
|
||||
-- TODO We need Enums for
|
||||
-- Accessing data in moddata
|
||||
|
||||
|
||||
-- Unified model with single string
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- local SIDES = {"Right", "Left"}
|
||||
-- local PARTS = { "Hand", "LowerArm", "UpperArm", "Foot" }
|
||||
|
||||
|
||||
-- local Data = {}
|
||||
|
||||
-- Data.AmputableBodyParts = {
|
||||
-- BodyPartType.Hand_R, BodyPartType.ForeArm_R, BodyPartType.UpperArm_R,
|
||||
-- BodyPartType.Hand_L, BodyPartType.ForeArm_L, BodyPartType.UpperArm_L
|
||||
-- }
|
||||
|
||||
|
||||
|
||||
0
media/lua/client/TimedActions/TOC_CutLimbAction.lua
Normal file
0
media/lua/client/TimedActions/TOC_CutLimbAction.lua
Normal file
Reference in New Issue
Block a user