Some more refactoring

This commit is contained in:
Pao
2023-02-05 03:30:49 +01:00
parent 2fd686b89b
commit f5d6ff7f9a
13 changed files with 114 additions and 59 deletions

View File

@@ -0,0 +1,226 @@
------------------------------------------
-------- THE ONLY CURE BUT BETTER --------
------------------------------------------
----------- CUT LIMB FUNCTIONS -----------
local function TocCheckIfStillInfected(limbs_data)
if limbs_data == nil then
return
end
-- Check ALL body part types to check if the player is still gonna die
local check = false
for _, v in ipairs(GetBodyParts()) do
if limbs_data[v].is_infected then
check = true
end
end
if limbs_data.is_other_bodypart_infected then
check = true
end
return check
end
local function TocCureInfection(body_damage, part_name)
local body_part_type = body_damage:getBodyPart(TocGetBodyPartFromPartName(part_name))
body_damage:setInfected(false)
body_part_type:SetInfected(false)
body_damage:setInfectionMortalityDuration(-1)
body_damage:setInfectionTime(-1)
body_damage:setInfectionLevel(0)
local body_part_types = body_damage:getBodyParts()
-- TODO I think this is enough... we should just cycle if with everything instead of that crap up there
for i = body_part_types:size() - 1, 0, -1 do
local bodyPart = body_part_types:get(i);
bodyPart:SetInfected(false);
end
if body_part_type:scratched() then body_part_type:setScratched(false, false) end
if body_part_type:haveGlass() then body_part_type:setHaveGlass(false) end
if body_part_type:haveBullet() then body_part_type:setHaveBullet(false, 0) end
if body_part_type:isInfectedWound() then body_part_type:setInfectedWound(false) end
if body_part_type:isBurnt() then body_part_type:setBurnTime(0) end
if body_part_type:isCut() then body_part_type:setCut(false, false) end --Lacerations
if body_part_type:getFractureTime() > 0 then body_part_type:setFractureTime(0) end
end
local function TocDeleteOtherAmputatedLimbs(side)
-- if left hand is cut and we cut left lowerarm, then delete hand
for _, limb in pairs(TOC_limbs) do
local part_name = "TOC.Amputation_" .. side .. "_" .. limb
local amputated_limb = getPlayer():getInventory():FindAndReturn(part_name)
if amputated_limb then
getPlayer():getInventory():Remove(amputated_limb)
end
end
end
---@param heal_bite boolean
local function TocSetParametersForMissingLimb(body_part, heal_bite)
body_part:setBleeding(false)
body_part:setBleedingTime(0)
body_part:setDeepWounded(false)
body_part:setDeepWoundTime(0)
body_part:setScratched(false, false) -- why the fuck are there 2 booleans TIS?
body_part:setScratchTime(0)
body_part:setCut(false)
body_part:setCutTime(0)
if heal_bite then
body_part:SetBitten(false)
body_part:setBiteTime(0)
end
end
function TocDamagePlayerDuringAmputation(patient, part_name)
-- Since we're cutting that specific part, it only makes sense that the bleeding starts from there.
-- Then, we just delete the bleeding somewhere else before applying the other damage to to upper part of the limb
local body_part_type = TocGetBodyPartFromPartName(part_name)
local body_damage = patient:getBodyDamage()
local body_damage_part = body_damage:getBodyPart(body_part_type)
body_damage_part:setBleeding(true)
body_damage_part:setCut(true)
body_damage_part:setBleedingTime(ZombRand(10, 20))
end
----------------------------------------------------------------------------------
--- Main function for cutting a limb
---@param part_name string the part name to amputate
---@param surgeon_factor any the surgeon factor, which will determine some stats for the inflicted wound
---@param bandage_table any bandages info
---@param painkiller_table any painkillers info, not used
function TocCutLimb(part_name, surgeon_factor, bandage_table, painkiller_table)
-- TODO Separate Cut Limb in side and limb instead of single part_name
-- Items get unequipped in ISCutLimb.Start
local player = getPlayer()
local toc_data = player:getModData().TOC
local limbs_data = toc_data.Limbs
-- TODO Stop for a bit,
-- Cut Hand -> Damage in forearm
-- Cut Forearm -> Damage in Upperarm
-- Cut UpperArm -> Damage to torso
local body_damage = player:getBodyDamage()
local body_part = body_damage:getBodyPart(TocGetBodyPartFromPartName(part_name))
local adiacent_body_part = player:getBodyDamage():getBodyPart(TocGetAdiacentBodyPartFromPartName(part_name))
local stats = player:getStats()
-- Reset the status of the first body part, since we just cut it off it shouldn't be bleeding anymore
-- The bit will be checked later since we're not sure if the player is not infected from another wound
TocSetParametersForMissingLimb(body_part, false)
-- Set damage, stress, and low endurance after amputation
adiacent_body_part:AddDamage(100 - surgeon_factor)
adiacent_body_part:setAdditionalPain(100 - surgeon_factor)
adiacent_body_part:setBleeding(true)
adiacent_body_part:setBleedingTime(100 - surgeon_factor)
adiacent_body_part:setDeepWounded(true)
adiacent_body_part:setDeepWoundTime(100 - surgeon_factor)
stats:setEndurance(surgeon_factor)
stats:setStress(100 - surgeon_factor)
-- Set malus for strength and fitness
player:LoseLevel(Perks.Fitness)
player:LoseLevel(Perks.Strength)
-- If bandages are available, use them
adiacent_body_part:setBandaged(bandage_table.use_bandage, 10, bandage_table.is_bandage_sterilized,
bandage_table.bandage_type)
-- If painkillers are available, use them
-- TODO add painkiller support
-- Use a tourniquet if available
-- TODO add tourniquet
if limbs_data[part_name].is_cut == false then
limbs_data[part_name].is_cut = true
limbs_data[part_name].is_amputation_shown = true
limbs_data[part_name].cicatrization_time = limbs_data[part_name].cicatrization_base_time - surgeon_factor * 50
for _, depended_v in pairs(limbs_data[part_name].depends_on) do
limbs_data[depended_v].is_cut = true
limbs_data[depended_v].is_amputation_shown = false
limbs_data[depended_v].cicatrization_time = limbs_data[part_name].cicatrization_base_time -
surgeon_factor * 50
local should_depended_v_be_healed_of_bite = limbs_data[depended_v].is_infected and
body_damage:getInfectionLevel() < 20
local depended_body_part = body_damage:getBodyPart(TocGetBodyPartFromPartName(depended_v))
TocSetParametersForMissingLimb(depended_body_part, should_depended_v_be_healed_of_bite)
if should_depended_v_be_healed_of_bite then
limbs_data[depended_v].is_infected = false
end
end
-- Heal the infection here
local body_damage = player:getBodyDamage()
if limbs_data[part_name].is_infected and body_damage:getInfectionLevel() < 20 then
limbs_data[part_name].is_infected = false
-- NOT THE ADIACENT ONE!!!
body_part:SetBitten(false)
body_part:setBiteTime(0)
-- Second check, let's see if there is any other infected limb.
if TocCheckIfStillInfected(limbs_data) == false then
TocCureInfection(body_damage, part_name)
getPlayer():Say("I'm gonna be fine...") -- TODO Make it visible to other players, check True Actions as reference
else
getPlayer():Say("I'm still gonna die...")
end
end
-- Check for older amputation models and deletes them from player's inventory
local side = string.match(part_name, '(%w+)_')
TocDeleteOtherAmputatedLimbs(side)
--Equip new model for amputation
local amputation_clothing_item = player:getInventory():AddItem(TocFindAmputatedClothingFromPartName(part_name))
TocSetCorrectTextureForAmputation(amputation_clothing_item, player, false)
player:setWornItem(amputation_clothing_item:getBodyLocation(), amputation_clothing_item)
-- Set blood on the amputated limb
TocSetBloodOnAmputation(getPlayer(), adiacent_body_part)
end
end

View File

@@ -0,0 +1,46 @@
------------------------------------------
-------- THE ONLY CURE BUT BETTER --------
------------------------------------------
------------- LOCAL ACTIONS --------------
function TocCutLocal(_, player, part_name)
if TocGetSawInInventory(player) ~= nil then
ISTimedActionQueue.add(ISCutLimb:new(player, player, part_name))
else
player:Say("I don't have a saw on me")
end
end
function TocOperateLocal(_, player, part_name, use_oven)
--local player = getPlayer();
-- todo add a check if the player has already been amputated or somethin
if use_oven then
ISTimedActionQueue.add(ISOperateLimb:new(player, player, _, part_name, use_oven));
else
local kit = TocGetKitInInventory(player) -- TODO Why is it here and only for local?
if kit ~= nil then
ISTimedActionQueue.add(ISOperateLimb:new(player, player, kit, part_name, false))
else
player:Say("I don't have a kit on me")
end
end
end
function TocEquipProsthesisLocal(_, player, part_name)
local surgeon_inventory = player:getInventory()
local prosthesis_to_equip = surgeon_inventory:getItemFromType('TOC.MetalHand') or
surgeon_inventory:getItemFromType('TOC.MetalHook') or
surgeon_inventory:getItemFromType('TOC.WoodenHook')
if prosthesis_to_equip then
ISTimedActionQueue.add(ISInstallProsthesis:new(player, player, prosthesis_to_equip, part_name))
else
player:Say("I need a prosthesis")
end
end
function TocUnequipProsthesisLocal(_, player, part_name)
ISTimedActionQueue.add(ISUninstallProsthesis:new(player, player, part_name))
end

View File

@@ -0,0 +1,69 @@
------------------------------------------
-------- THE ONLY CURE BUT BETTER --------
------------------------------------------
--------- OPERATE LIMB FUNCTIONS ---------
local function FixSingleBodyPartType(body_part_type, use_oven)
body_part_type:setDeepWounded(false) --Basically like stitching
body_part_type:setDeepWoundTime(0)
if use_oven then
body_part_type:AddDamage(100)
body_part_type:setAdditionalPain(100);
body_part_type:setBleeding(false)
body_part_type:setBleedingTime(0) -- no bleeding since it's been cauterized
else
-- TODO Think a little better about this, do we want to trigger bleeding or not?
body_part_type:setBleeding(false)
--body_part_type:setBleedingTime(ZombRand(1, 5)) -- Reset the bleeding, maybe make it random
end
end
local function SetBodyPartsStatusAfterOperation(player, limbs_data, part_name, use_oven)
--for _, v in ipairs(GetBodyParts()) do
local body_part_type = player:getBodyDamage():getBodyPart(TocGetAdiacentBodyPartFromPartName(part_name))
FixSingleBodyPartType(body_part_type, use_oven)
for _, v in ipairs(limbs_data[part_name].depends_on) do
local depended_body_part_type = player:getBodyDamage():getBodyPart(TocGetAdiacentBodyPartFromPartName(v))
FixSingleBodyPartType(depended_body_part_type, use_oven)
end
end
----------------------------------------------------------------------------------
---Main function to operate a limb after amputation
---@param part_name any
---@param surgeon_factor any
---@param use_oven boolean wheter using oven instead of a kit or not
function TocOperateLimb(part_name, surgeon_factor, use_oven)
local player = getPlayer()
local limbs_data = player:getModData().TOC.Limbs
if use_oven then
local stats = player:getStats()
stats:setEndurance(100)
stats:setStress(100)
end
if limbs_data[part_name].is_operated == false and limbs_data[part_name].is_cut == true then
limbs_data[part_name].is_operated = true
limbs_data[part_name].cicatrization_time = limbs_data[part_name].cicatrization_time - (surgeon_factor * 200)
if use_oven then limbs_data[part_name].is_cauterized = true end
for _, depended_v in pairs(limbs_data[part_name].depends_on) do
limbs_data[depended_v].is_operated = true
limbs_data[depended_v].cicatrization_time = limbs_data[depended_v].cicatrization_time -
(surgeon_factor * 200)
if use_oven then limbs_data[depended_v].is_cauterized = true end -- TODO does this make sense?
end
end
SetBodyPartsStatusAfterOperation(player, limbs_data, part_name, use_oven)
end

View File

@@ -0,0 +1,63 @@
------------------------------------------
-------- THE ONLY CURE BUT BETTER --------
------------------------------------------
---------- PROSTHESIS FUNCTIONS ----------
---Equip a prosthesis transforming a normal item into a clothing item
---@param part_name string
---@param prosthesis_base_name string
function TocEquipProsthesis(part_name, prosthesis_base_name)
local player = getPlayer()
local toc_data = player:getModData().TOC
local prosthesis_name = TocFindCorrectClothingProsthesis(prosthesis_base_name, part_name)
local added_prosthesis = player:getInventory():AddItem(prosthesis_name)
if part_name ~= nil then
if added_prosthesis ~= nil then
toc_data.Limbs[part_name].is_prosthesis_equipped = true
toc_data.Limbs[part_name].equipped_prosthesis = toc_data.Prosthesis[prosthesis_base_name][part_name]
if player:isFemale() then
added_prosthesis:getVisual():setTextureChoice(1)
else
added_prosthesis:getVisual():setTextureChoice(0)
end
player:setWornItem(added_prosthesis:getBodyLocation(), added_prosthesis)
end
end
end
---Unequip a prosthesis clothing item and returns it to the inventory as a normal item
---@param part_name string
function TocUnequipProsthesis(patient, part_name, equipped_prosthesis)
local toc_data = patient:getModData().TOC
toc_data.Limbs[part_name].is_prosthesis_equipped = false
local equipped_prosthesis_full_type = equipped_prosthesis:getFullType()
for _, prost_v in ipairs(GetProsthesisList()) do
local prosthesis_name = string.match(equipped_prosthesis_full_type, prost_v)
if prosthesis_name then
patient:getInventory():AddItem("TOC." .. prosthesis_name)
patient:setWornItem(equipped_prosthesis:getBodyLocation(), nil)
patient:getInventory():Remove(equipped_prosthesis)
toc_data.Limbs[part_name].equipped_prosthesis = nil
end
end
end