From 28dde140628b6c70a02cd128fbc50f31a2887fa2 Mon Sep 17 00:00:00 2001 From: Pao Date: Thu, 12 Jan 2023 21:25:13 +0100 Subject: [PATCH] i'm burning --- .../lua/client/MP_commands/TOC_MP_client.lua | 22 ++++ media/lua/client/TOC_Client.lua | 5 + media/lua/client/TOC_GlobalFunctions.lua | 14 +- media/lua/client/TOC_HelperFunctions.lua | 65 ++++++++++ media/lua/client/TOC_UI.lua | 4 +- media/lua/client/TOC_main.lua | 98 ++++++++++++++ media/lua/client/TimedActions/NewOnCut2.lua | 121 ++++++++++++++++++ media/lua/client/Utils/UsefulFunctions.lua | 14 ++ media/lua/server/TOC_MP_server.lua | 4 +- 9 files changed, 337 insertions(+), 10 deletions(-) create mode 100644 media/lua/client/TOC_HelperFunctions.lua create mode 100644 media/lua/client/TimedActions/NewOnCut2.lua diff --git a/media/lua/client/MP_commands/TOC_MP_client.lua b/media/lua/client/MP_commands/TOC_MP_client.lua index 16ac6b1..a660859 100644 --- a/media/lua/client/MP_commands/TOC_MP_client.lua +++ b/media/lua/client/MP_commands/TOC_MP_client.lua @@ -11,6 +11,19 @@ function SendCutArm(player, partName, surgeonFact, useBandage, bandageAlcool, us sendClientCommand("TOC", "SendServer", arg); end + +function TheOnlyCure.SendCutLimb(player, part_name, surgeon_factor, bandage_table, painkiller_table) + local arg = {} + arg["From"] = getPlayer():getOnlineID() + arg["To"] = player:getOnlineID() + arg["command"] = "CutLimb" + arg["toSend"] = {part_name, surgeon_factor, bandage_table, painkiller_table} + sendClientCommand("TOC", "SendServer", arg) +end + + + + function SendOperateArm(player, partName, surgeonFact, useOven) local arg = {}; arg["From"] = getPlayer():getOnlineID(); @@ -52,11 +65,20 @@ end -- Patient (receive) +Commands["CutLimb"] = function(arg) + local arg = arg["toSend"] + TheOnlyCure.CutLimb(arg[1], arg[2], arg[3], arg[4]) +end + + Commands["CutArm"] = function(arg) local arg = arg["toSend"]; CutArm(arg[1], arg[2], arg[3], arg[4], arg[5], arg[6]); end + + + Commands["OperateArm"] = function(arg) local arg = arg["toSend"]; OperateArm(arg[1], arg[2], arg[3]); diff --git a/media/lua/client/TOC_Client.lua b/media/lua/client/TOC_Client.lua index 4061acd..b6c7d42 100644 --- a/media/lua/client/TOC_Client.lua +++ b/media/lua/client/TOC_Client.lua @@ -1,3 +1,7 @@ + + + + local function OnTocServerCommand(module, command, args) -- TODO Change name of the func @@ -28,6 +32,7 @@ local function OnTocServerCommand(module, command, args) -- ew a global var.... but dunno if there's a better way to do this MP_other_player_toc_data = args[2] + end end end diff --git a/media/lua/client/TOC_GlobalFunctions.lua b/media/lua/client/TOC_GlobalFunctions.lua index 4682dcc..e029f29 100644 --- a/media/lua/client/TOC_GlobalFunctions.lua +++ b/media/lua/client/TOC_GlobalFunctions.lua @@ -1,4 +1,4 @@ - +-- TODO OLD TO DELETE local function CheckIfStillInfected(toc_data) for k,v in pairs(GetBodyParts()) do if toc_data[v].is_infected == true then @@ -12,7 +12,7 @@ local function CheckIfStillInfected(toc_data) end - +-- TODO OLD TO DELETE local function CureInfection(bodyDamage) bodyDamage:setInfected(false); bodyDamage:setInfectionMortalityDuration(-1); @@ -23,9 +23,6 @@ local function CureInfection(bodyDamage) local bodyPart = bodyParts:get(i); bodyPart:SetInfected(false); end - - getPlayer().Say("I'm gonna be fine") - end -- TODO change it to CutLimb or CutBodyPart @@ -133,7 +130,6 @@ function OperateArm(partName, surgeonFact, useOven) player:transmitModData(); end - function SetBodyPartsStatus(player, partName, useOven) -- TODO use GetBodyParts with depends_on @@ -166,8 +162,12 @@ function SetBodyPartsStatus(player, partName, useOven) end + + + for k,v in pairs(chosen_array) do - local tmpBodyPart = player:getBodyDamage():getBodyPart(TOC_getBodyPart(v)); + local tmpBodyPart = player:getBodyDamage():getBodyPart(TheOnlyCure.GetBodyPartTypeFromBodyPart(v)) + tmpBodyPart:setDeepWounded(false); -- Basically like stictching tmpBodyPart:setDeepWoundTime(0); if useOven then diff --git a/media/lua/client/TOC_HelperFunctions.lua b/media/lua/client/TOC_HelperFunctions.lua new file mode 100644 index 0000000..3426920 --- /dev/null +++ b/media/lua/client/TOC_HelperFunctions.lua @@ -0,0 +1,65 @@ +-- CutLimb +function TheOnlyCure.CheckIfStillInfected(toc_data) + + -- Check ALL body part types to check if the player is still gonna die + local check = false + + for _, v in ipairs(GetBodyParts()) do + if toc_data[v].is_infected then + check = true + end + end + + if toc_data.is_other_bodypart_infected then + check = true + end + + return check +end + + +function TheOnlyCure.CureInfection(body_damage) + body_damage:setInfected(false) + body_damage:setInfectionMortalityDuration(-1) + body_damage:setInfectionTime(-1) + body_damage:setInfectionLevel(0) + local body_part_types = body_damage:getBodyParts() + for i=body_part_types:size()-1, 0, -1 do + local bodyPart = body_part_types:get(i) + bodyPart:SetInfected(false) + end + + getPlayer().Say("I'm gonna be fine") + +end + + +-- OperateLimb +function TheOnlyCure.SetBodyPartsStatusAfterOperation(player, toc_data, part_name, use_oven) + --for _, v in ipairs(GetBodyParts()) do + + + local body_part_type = player:getBodyDamage():getBodyPart(TheOnlyCure.GetBodyPartTypeFromBodyPart(part_name)) + FixSingleBodyPartType(body_part_type, use_oven) + + for _, v in ipairs(toc_data[part_name].depends_on) do + local depended_body_part_type = player:getBodyDamage():getBodyPart(TheOnlyCure.GetBodyPartTypeFromBodyPart(v)) + FixSingleBodyPartType(depended_body_part_type, use_oven) + + end +end + +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 + body_part_type:setBleeding(true); + body_part_type:setBleedingTime(ZombRand(1, 5)); -- Reset the bleeding, maybe make it random + end +end + diff --git a/media/lua/client/TOC_UI.lua b/media/lua/client/TOC_UI.lua index b36e0f1..966567c 100644 --- a/media/lua/client/TOC_UI.lua +++ b/media/lua/client/TOC_UI.lua @@ -340,7 +340,7 @@ local function confirmPress(button, args) local player = getPlayer(); if confirmUI.actionAct == "Cut" then if args.option == "yes" then - ISTimedActionQueue.add(IsCutArm:new(player, player, descUI.partNameAct)); + ISTimedActionQueue.add(ISCutLimb:new(player, player, descUI.partNameAct)); else getPlayer():Say("Never mind"); end @@ -366,7 +366,7 @@ local function confirmPressMP(button, args) if confirmUIMP.actionAct == "Cut" then if args.option == "yes" then getPlayer():Say("Hold on, I believe in you!"); - ISTimedActionQueue.add(IsCutArm:new(confirmUIMP.patient, player, confirmUIMP.partNameAct)); + ISTimedActionQueue.add(ISCutLimb:new(confirmUIMP.patient, player, confirmUIMP.partNameAct)); else getPlayer():Say("Alright..."); end diff --git a/media/lua/client/TOC_main.lua b/media/lua/client/TOC_main.lua index dd94491..a36f5f7 100644 --- a/media/lua/client/TOC_main.lua +++ b/media/lua/client/TOC_main.lua @@ -119,5 +119,103 @@ end + + +----------------------------------------------------------------------- +function TheOnlyCure.CutLimb(part_name, surgeon_factor, bandage_table, painkiller_table) + + -- TODO Check if this works in MP through MENU UI + local player = getPlayer() + local toc_data = player:getModDare().TOC + local body_part_type = player:getBodyDamage():getBodyPart(TheOnlyCure.GetBodyPartTypeFromBodyPart(part_name)) + local stats = player:getStats(); + + -- Set damage, stress, and low endurance after amputation + body_part_type:AddDamage(100 - surgeon_factor) + body_part_type:setAdditionalPain(100 - surgeon_factor) + body_part_type:setBleeding(true) + body_part_type:setBleedingTime(100 - surgeon_factor) + body_part_type:setDeepWounded(true) + body_part_type:setDeepWoundTime(100 - surgeon_factor) + stats:setEndurance(surgeon_factor) + stats:setStress(100 - surgeon_factor) + + -- If bandages are available, use them + body_part_type:setBandaged(bandage_table.use_bandage, 10, bandage_table.is_bandage_sterilized, bandage_table.bandage_type) + + + + -- If painkillers are available, use them + -- ... + + if toc_data[part_name].is_cut == false then + toc_data[part_name].is_cut = true + toc_data[part_name].is_amputation_shown = true + toc_data[part_name].cicatrization_time = toc_data[part_name].cicatrization_base_time - surgeon_factor * 50 + + -- Heal the infection here + local body_damage = player:getBodyDamage() + if toc_data[part_name].is_infected and body_damage.getInfectionLevel() < 20 then + toc_data[part_name].is_infected = false + body_part_type:SetBitten(false) + + -- Second check, let's see if there is any other infected limb. + if TheOnlyCure.CheckIfStillInfected(toc_data) == false then + TheOnlyCure.CureInfection(body_damage) + getPlayer():Say("I'm gonna be fine") + else + getPlayer():Say("I'm still gonna die...") + end + end + + -- Cut the depended part + for _, depended_v in pairs(toc_data[part_name].depends_on) do + toc_data[depended_v].is_cut = true + toc_data[depended_v].is_amputation_shown = true + toc_data[depended_v].cicatrization_time = toc_data[part_name].cicatrization_base_time - surgeon_factor * 50 + end + + --Equip model for amputation + local cloth = player:getInventory():AddItem(find_clothName2_TOC(part_name)) + player:setWornItem(cloth:getBodyLocation(), cloth) + player:transmitModData() + + end + + + + +end + +function TheOnlyCure.OperateLimb(part_name, surgeon_factor, use_oven) + + local player = getPlayer() + local toc_data = player:getModData().TOC + + if use_oven then + local stats = player:getStats() + stats:setEndurance(100) + stats:setStress(100) + end + + if toc_data[part_name].is_operated == false and toc_data[part_name].is_cut == true then + toc_data[part_name].is_operated = true + toc_data[part_name].cicatrization_time = toc_data[part_name].cicatrization_time - (surgeon_factor * 200) + if use_oven then toc_data[part_name].is_cauterized = true end + for _, depended_v in pairs(toc_data[part_name].depends_on) do + toc_data[depended_v].is_operated = true + toc_data[depended_v].cicatrization_time = toc_data[depended_v].cicatrization_time - (surgeon_factor * 200) + if use_oven then toc_data[depended_v].is_cauterized = true end -- TODO does this make sense? + + end + + end + + TheOnlyCure.SetBodyPartsStatusAfterOperation(player, toc_data, part_name, use_oven) + player:transmitModData() +end + + + Events.OnCreatePlayer.Add(TheOnlyCure.InitTheOnlyCure) Events.OnGameBoot.Add(TheOnlyCure.DeclareTraits) \ No newline at end of file diff --git a/media/lua/client/TimedActions/NewOnCut2.lua b/media/lua/client/TimedActions/NewOnCut2.lua new file mode 100644 index 0000000..f7d6f5f --- /dev/null +++ b/media/lua/client/TimedActions/NewOnCut2.lua @@ -0,0 +1,121 @@ +require "TimedActions/ISBaseTimedAction" + +ISCutLimb = ISBaseTimedAction:derive("ISCutLimb") + + +function ISCutLimb:isValid() + return self.patientX == self.patient:getX() and self.patientY == self.patient:getY() +end + +function ISCutLimb:waitToStart() + if self.patient == self.surgeon then + return false + end + self.surgeon:faceThisObject(self.patient) + return self.surgeon:shouldBeTurning() +end + +function ISCutLimb:update() + if self.patient ~= self.surgeon then + self.surgeon:faceThisObject(self.patient) + end +end + +function ISCutLimb:start() + if self.patient == self.surgeon then + self:setActionAnim("WearClothing") -- TODO Change it to a better animation + self:setAnimVariable("WearClothingLocation", "Jacket") + else + self:setActionAnim("Loot") + self.patient:SetVariable("LootPosition", "Mid") + end +end + + +function ISCutLimb:findArgs() + local surgeon_factor = self.surgeon:getPerkLevel(Perks.Doctor) + if self.surgeon:getDescriptor():getProfession() == "surgeon" then surgeon_factor = surgeon_factor + 15 end + if self.surgeon:getDescriptor():getProfession() == "doctor" then surgeon_factor = surgeon_factor + 9 end + if self.surgeon:getDescriptor():getProfession() == "nurse" then surgeon_factor = surgeon_factor + 4 end + + local bandage_table = { + use_bandage = false, + bandage_type = nil, + is_bandage_sterilized = nil} + local painkiller_table = {} + + + local bandage = self.surgeon:getInventory():FindAndReturn('Bandage') + local sterilized_bandage = self.surgeon:getInventory():FindAndReturn('AlcoholBandage') + + if sterilized_bandage then + bandage_table.bandage_type = sterilized_bandage:getType() + bandage_table.is_bandage_sterilized = true + bandage_table.use_bandage = true + self.surgeon:getInventory():Remove(sterilized_bandage) + surgeon_factor = surgeon_factor + 4 + elseif bandage then + bandage_table.bandage_type = bandage:getType() + bandage_table.is_bandage_sterilized = false + self.surgeon:getInventory():Remove(bandage) + surgeon_factor = surgeon_factor + 2 + else + bandage_table.bandage_type = "" + bandage_table.use_bandage = false + bandage_table.is_bandage_sterilized = false + end + + + + -- local painkiller = self.surgeon:getInventory():FindAndReturn('Pills'); + -- if painkiller then + -- usePainkiller = true; + -- painkillerCount = painkiller:getRemainingUses(); + -- end + + return surgeon_factor, bandage_table, painkiller_table +end + + +function ISCutLimb:perform() + local surgeon_factor, bandage_table, painkiller_table = self:findArgs() + + if self.patient ~= self.surgoen and isClient() then + SendCutLimb() + else + TheOnlyCure.CutLimb(self.part_name, surgeon_factor, bandage_table, painkiller_table) + end + + if self.patient ~= self.surgeon and isClient() then + SendCutArm(self.patient, self.partName, surgeonFact, useBandage, bandageAlcool, usePainkiller, painkillerCount); + else + CutArm(self.partName, surgeonFact, useBandage, bandageAlcool, usePainkiller, painkillerCount); + end + self.surgeon:getXp():AddXP(Perks.Doctor, 400); + + ISBaseTimedAction.perform(self); +end + + +function ISCutLimb:new(patient, surgeon, part_name) + local o = {} + setmetatable(o, self) + self.__index = self + o.partName = part_name + o.bodyPart = TheOnlyCure.GetBodyPartTypeFromBodyPart(part_name) + o.character = surgeon -- For anim + + o.surgeon = surgeon; -- Surgeon or player that make the operation + o.patient = patient; -- Player to amputate + + o.patientX = patient:getX() + o.patientY = patient:getY() + + o.maxTime = 1000 - (surgeon:getPerkLevel(Perks.Doctor) * 50) + o.stopOnWalk = true + o.stopOnRun = true + o.ignoreHandsWounds = false + o.fromHotbar = true + if o.patient:isTimedActionInstant() then o.maxTime = 1 end + return o +end \ No newline at end of file diff --git a/media/lua/client/Utils/UsefulFunctions.lua b/media/lua/client/Utils/UsefulFunctions.lua index 38ea2a1..21004b7 100644 --- a/media/lua/client/Utils/UsefulFunctions.lua +++ b/media/lua/client/Utils/UsefulFunctions.lua @@ -40,7 +40,21 @@ function getDisplayText_TOC(name) if name == "LeftArm" then return getText("UI_ContextMenu_LeftArm") end end + + +function TheOnlyCure.GetBodyPartTypeFromBodyPart(part_name) + if part_name == "RightHand" then return BodyPartType.Hand_R end + if part_name == "RightForearm" then return BodyPartType.ForeArm_R end + if part_name == "RightArm" then return BodyPartType.UpperArm_R end + if part_name == "LeftHand" then return BodyPartType.Hand_L end + if part_name == "LeftForearm" then return BodyPartType.ForeArm_L end + if part_name == "LeftArm" then return BodyPartType.UpperArm_L end +end + + + function TOC_getBodyPart(name) + --TODO Delete this if name == "RightHand" then return BodyPartType.Hand_R end if name == "RightForearm" then return BodyPartType.ForeArm_R end if name == "RightArm" then return BodyPartType.UpperArm_R end diff --git a/media/lua/server/TOC_MP_server.lua b/media/lua/server/TOC_MP_server.lua index 6c9e806..84d26ef 100644 --- a/media/lua/server/TOC_MP_server.lua +++ b/media/lua/server/TOC_MP_server.lua @@ -3,10 +3,12 @@ if isClient() then return end + + ---Server side local Commands = {} --- todo what is this? +-- TODO what is this? Commands["SendServer"] = function(player, arg) local otherPlayer = getPlayerByOnlineID(arg["To"]) print("The Only Cure Command: ", arg['command'])