diff --git a/media/lua/client/TOC/CommonMethods.lua b/media/lua/client/TOC/CommonMethods.lua index 6b4fdea..f9298a7 100644 --- a/media/lua/client/TOC/CommonMethods.lua +++ b/media/lua/client/TOC/CommonMethods.lua @@ -8,4 +8,5 @@ function CommonMethods.GetSide(name) end + return CommonMethods \ No newline at end of file diff --git a/media/lua/client/TOC/Handlers/AmputationHandler.lua b/media/lua/client/TOC/Handlers/AmputationHandler.lua index 741c3a1..9846b7d 100644 --- a/media/lua/client/TOC/Handlers/AmputationHandler.lua +++ b/media/lua/client/TOC/Handlers/AmputationHandler.lua @@ -56,12 +56,38 @@ function AmputationHandler.ApplyDamageDuringAmputation(player, limbName) bodyDamagePart:setBleedingTime(ZombRand(10, 20)) end -function AmputationHandler.HandleBandages(prevAction, limbName, surgeonPl, patientPl, bandageItem) +---comment +---@param prevAction ISBaseTimedAction +---@param limbName string +---@param surgeonPl IsoPlayer +---@param patientPl IsoPlayer +---@param stitchesItem InventoryItem +---@return ISStitch +function AmputationHandler.PrepareStitchesAction(prevAction, limbName, surgeonPl, patientPl, stitchesItem) + local bptEnum = StaticData.BODYLOCS_IND_BPT[limbName] + local bd = patientPl:getBodyDamage() + local bodyPart = bd:getBodyPart(bptEnum) + local stitchesAction = ISStitch:new(surgeonPl, patientPl, stitchesItem, bodyPart, true) + ISTimedActionQueue.addAfter(prevAction, stitchesAction) + + return stitchesAction +end + +---Setup the ISApplyBandage action that will trigger after the amputation +---@param prevAction ISBaseTimedAction +---@param limbName string +---@param surgeonPl IsoPlayer +---@param patientPl IsoPlayer +---@param bandageItem InventoryItem +---@return ISApplyBandage +function AmputationHandler.PrepareBandagesAction(prevAction, limbName, surgeonPl, patientPl, bandageItem) local bptEnum = StaticData.BODYLOCS_IND_BPT[limbName] local bd = patientPl:getBodyDamage() local bodyPart = bd:getBodyPart(bptEnum) local bandageAction = ISApplyBandage:new(surgeonPl, patientPl, bandageItem, bodyPart, true) ISTimedActionQueue.addAfter(prevAction, bandageAction) + + return bandageAction end --* Main methods *-- diff --git a/media/lua/client/TOC/TimedActions/CutLimbAction.lua b/media/lua/client/TOC/TimedActions/CutLimbAction.lua index b324659..0cc8a79 100644 --- a/media/lua/client/TOC/TimedActions/CutLimbAction.lua +++ b/media/lua/client/TOC/TimedActions/CutLimbAction.lua @@ -1,7 +1,8 @@ require "TimedActions/ISBaseTimedAction" local AmputationHandler = require("TOC/Handlers/AmputationHandler") local CommandsData = require("TOC/CommandsData") -local StaticData = require("TOC/StaticData") +local CommonMethods = require("TOC/CommonMethods") + ----------------------------- ---@class CutLimbAction : ISBaseTimedAction @@ -9,15 +10,19 @@ local StaticData = require("TOC/StaticData") ---@field character IsoPlayer ---@field limbName string ---@field item InventoryItem +---@field stitchesItem InventoryItem? +---@field bandageItem InventoryItem? local CutLimbAction = ISBaseTimedAction:derive("CutLimbAction") ---Starts CutLimbAction ----@param patient IsoPlayer ----@param surgeon IsoPlayer +---@param surgeon IsoPlayer This is gonna be self.character to have working animations +---@param patient IsoPlayer ---@param limbName string ----@param item InventoryItem +---@param item InventoryItem This is gonna be the saw, following ISBaseTimedAction +---@param stitchesItem InventoryItem? +---@param bandageItem InventoryItem? ---@return CutLimbAction -function CutLimbAction:new(surgeon, patient, limbName, item) +function CutLimbAction:new(surgeon, patient, limbName, item, stitchesItem, bandageItem) local o = {} setmetatable(o, self) self.__index = self @@ -28,6 +33,9 @@ function CutLimbAction:new(surgeon, patient, limbName, item) o.limbName = limbName o.item = item + o.stitchesItem = stitchesItem or nil + o.bandageItem = bandageItem or nil + o.stopOnWalk = true o.stopOnRun = true @@ -53,19 +61,19 @@ function CutLimbAction:start() sendClientCommand(CommandsData.modules.TOC_RELAY, CommandsData.server.Relay.RelayDamageDuringAmputation, params ) end + ---@type ISBaseTimedAction + local prevAction = self - -- TODO Check bandages, if there are init a bandage process - - --AmputationHandler.HandleBandages(self, self.limbName, self.character, self.patient, ) - local bandageItem = InventoryItemFactory.CreateItem("Base.Bandage") - self.character:getInventory():addItem(bandageItem) - - local bptEnum = StaticData.BODYLOCS_IND_BPT[self.limbName] - local bd = self.character:getBodyDamage() - local bodyPart = bd:getBodyPart(bptEnum) - local bandageAction = ISApplyBandage:new(self.character, self.patient, bandageItem, bodyPart, 100) - ISTimedActionQueue.addAfter(self, bandageAction) + -- Handle stitching + if self.stitchesItem then + TOC_DEBUG.print("Stitches...") + prevAction = AmputationHandler.PrepareStitchesAction(prevAction, self.limbName, self.character, self.patient, self.stitchesItem) + end + -- Handle bandages + if self.bandageItem then + prevAction = AmputationHandler.PrepareBandagesAction(prevAction, self.limbName, self.character, self.patient, self.bandageItem) + end -- Setup cosmetic stuff self:setActionAnim("SawLog") @@ -81,6 +89,16 @@ function CutLimbAction:waitToStart() return self.character:shouldBeTurning() end +function CutLimbAction:update() + self.character:setMetabolicTarget(Metabolics.HeavyWork) + + -- TODO Apply it too on the patient! check if it works online + if self.character ~= self.patient then + self.patient:setMetabolicTarget(Metabolics.HeavyWork) + end + +end + function CutLimbAction:perform() if self.patient == self.character then TOC_DEBUG.print("patient and surgeon are the same, executing on the client") diff --git a/media/lua/client/TOC/UI/CutLimbInteractions.lua b/media/lua/client/TOC/UI/CutLimbInteractions.lua index 6f80e11..d21d066 100644 --- a/media/lua/client/TOC/UI/CutLimbInteractions.lua +++ b/media/lua/client/TOC/UI/CutLimbInteractions.lua @@ -4,8 +4,10 @@ local StaticData = require("TOC/StaticData") local ModDataHandler = require("TOC/Handlers/ModDataHandler") --------------------- +-- TODO Add interaction to cut and bandage! +--* Various functions to help during these pesky checks ---Check if the item type corresponds to a compatible saw ---@param itemType string @@ -14,37 +16,96 @@ local function CheckIfSaw(itemType) end +---Return a compatible bandage +---@param player IsoPlayer +---@return InventoryItem? +local function GetBandageItem(player) + local plInv = player:getInventory() + -- TODO Add other options, like ripped sheets and such items + local bandageItem = plInv:FindAndReturn("Base.Bandage") or plInv:FindAndReturn("Base.RippedSheets") + return bandageItem -- TODO check this warning +end + +---Return a suture needle or thread (only if the player has a needle too) +---@param player IsoPlayer +---@return InventoryItem? +local function GetStitchesItem(player) + -- TODO Search for thread + local plInv = player:getInventory() + local needleItem = plInv:FindAndReturn("Base.SutureNeedle") + if needleItem ~= nil then return needleItem end + + -- Didn't find the suture one, so let's search for the normal one + thread + + needleItem = plInv:FindAndReturn("Base.Needle") + + if needleItem == nil then return nil end + + -- Found the normal one, searching for thread + + local threadItem = plInv:FindAndReturn("Base.Thread") + + if threadItem then return threadItem end + +end + + ---Add the action to the queue ---@param limbName string ---@param surgeon IsoPlayer ---@param patient IsoPlayer -local function PerformAction(surgeon, patient, limbName, item) - ISTimedActionQueue.add(CutLimbAction:new(surgeon, patient, limbName, item)) +---@param sawItem InventoryItem +---@param stitchesItem InventoryItem? +---@param bandageItem InventoryItem? +local function PerformAction(surgeon, patient, limbName, sawItem, stitchesItem, bandageItem) + ISTimedActionQueue.add(CutLimbAction:new(surgeon, patient, limbName, sawItem, stitchesItem, bandageItem)) end + +local textAmp = getText("ContextMenu_Amputate") +local textAmpBandage = getText("ContextMenu_Amputate_Bandage") +local textAmpStitch = getText("ContextMenu_Amputate_Stitch") +local textAmpStitchBandage = getText("ContextMenu_Amputate_Stitch_Bandage") + ---Adds the actions to the inventory context menu ----@param surgeonNum number +---@param player IsoPlayer ---@param context ISContextMenu ----@param item InventoryItem -local function AddInventoryAmputationOptions(surgeonNum, context, item) - local surgeonObj = getSpecificPlayer(surgeonNum) - local option = context:addOption(getText("ContextMenu_Amputate"), nil) +---@param sawItem InventoryItem +---@param stitchesItem InventoryItem? +---@param bandageItem InventoryItem? +local function AddInvAmputationOptions(player, context, sawItem, stitchesItem, bandageItem) + local text + + -- Set the correct text option + if stitchesItem and bandageItem then + text = textAmpStitchBandage + elseif stitchesItem and not bandageItem then + text = textAmpStitch + elseif bandageItem and not stitchesItem then + text = textAmpBandage + else + text = textAmp + end + + local option = context:addOption(text, nil) local subMenu = context:getNew(context) context:addSubMenu(option, subMenu) + for i = 1, #StaticData.LIMBS_STR do local limbName = StaticData.LIMBS_STR[i] if not ModDataHandler.GetInstance():getIsCut(limbName) then local limbTranslatedName = getText("ContextMenu_Limb_" .. limbName) - subMenu:addOption(limbTranslatedName, surgeonObj, PerformAction, surgeonObj, limbName, item) -- TODO Should be patient, not surgeon + subMenu:addOption(limbTranslatedName, player, PerformAction, player, limbName, sawItem, stitchesItem, bandageItem) -- TODO Should be patient, not surgeon end end end + ---Handler for OnFillInventoryObjectContextMenu ----@param player number +---@param playerNum number ---@param context ISContextMenu ---@param items table -local function AddInventoryAmputationMenu(player, context, items) +local function AddInventoryAmputationMenu(playerNum, context, items) local item -- We can't access the item if we don't create the loop and start ipairs. @@ -58,7 +119,17 @@ local function AddInventoryAmputationMenu(player, context, items) local itemType = item:getType() if CheckIfSaw(itemType) then - AddInventoryAmputationOptions(player, context, item) + local player = getSpecificPlayer(playerNum) + local sawItem = item + --AddInvAmputationOptions(player, context, sawItem) + + local stitchesItem = GetStitchesItem(player) + local bandageItem = GetBandageItem(player) + --if bandageItem then + AddInvAmputationOptions(player, context, sawItem, stitchesItem, bandageItem) + --end + + -- TODO Add stitches option and mixes end end diff --git a/media/lua/shared/Translate/EN/ContextMenu_EN.txt b/media/lua/shared/Translate/EN/ContextMenu_EN.txt index eaeb164..c6c45d7 100644 --- a/media/lua/shared/Translate/EN/ContextMenu_EN.txt +++ b/media/lua/shared/Translate/EN/ContextMenu_EN.txt @@ -1,5 +1,8 @@ ContextMenu_EN = { ContextMenu_Amputate = "Amputate", + ContextMenu_Amputate_Bandage = "Amputate and bandage", + ContextMenu_Amputate_Stitch_Bandage = "Amputate and stitches", + ContextMenu_Amputate_Stitch_Bandage = "Amputate, stitches and bandage", ContextMenu_Cauterize = "Cauterize", ContextMenu_Cauterize_TempTooLow_tooltip = "Temperature too low",