diff --git a/media/lua/client/Handlers/TOC_AmputationHandler.lua b/media/lua/client/Handlers/TOC_AmputationHandler.lua index 71b4a5a..2e3d82c 100644 --- a/media/lua/client/Handlers/TOC_AmputationHandler.lua +++ b/media/lua/client/Handlers/TOC_AmputationHandler.lua @@ -86,6 +86,8 @@ function AmputationHandler:execute(damagePlayer) -- Add it to the list of cut limbs PlayerHandler.AddLocalAmputatedLimb(self.limbName) + -- Set the highest amputation and caches them. + ISHealthPanel.GetHighestAmputation() end ---Deletes the instance diff --git a/media/lua/client/Handlers/TOC_ModDataHandler.lua b/media/lua/client/Handlers/TOC_ModDataHandler.lua index 4646d07..8243bc5 100644 --- a/media/lua/client/Handlers/TOC_ModDataHandler.lua +++ b/media/lua/client/Handlers/TOC_ModDataHandler.lua @@ -155,8 +155,7 @@ function ModDataHandler:setCutLimb(limbName, isOperated, isCicatrized, isCauteri -- Set that a limb has been cut, to activate some functions without having to loop through the parts self:setIsAnyLimbCut(true) - -- Set the highest amputation and caches them. - ISHealthPanel.GetHighestAmputation() + end diff --git a/media/lua/client/Handlers/TOC_ProsthesisHandler.lua b/media/lua/client/Handlers/TOC_ProsthesisHandler.lua index 5c1db4c..d838f01 100644 --- a/media/lua/client/Handlers/TOC_ProsthesisHandler.lua +++ b/media/lua/client/Handlers/TOC_ProsthesisHandler.lua @@ -7,12 +7,12 @@ local PlayerHandler = require("Handlers/TOC_PlayerHandler") local ProsthesisHandler = {} - +---Cache the correct texture for the Health Panel for the currently equipped prosthesis function ProsthesisHandler.SetHealthPanelTexture() -- TODO do it end ----comment +---Check if a prosthesis is equippable. It depends whether the player has a cut limb or not on that specific side. There's an exception for Upper arm, obviously ---@param bodyLocation string ---@return boolean function ProsthesisHandler.CheckIfEquippable(bodyLocation) @@ -33,9 +33,6 @@ end --* Overrides *-- - - - function ISWearClothing:isValid() local bodyLocation = self.item:getBodyLocation() if not string.contains(bodyLocation, "TOC_ArmProst") then @@ -45,7 +42,6 @@ function ISWearClothing:isValid() end end - local og_ISClothingExtraAction_isValid = ISClothingExtraAction.isValid function ISClothingExtraAction:isValid() local bodyLocation = self.item:getBodyLocation() diff --git a/media/lua/client/TimedActions/TOC_CutLimbAction.lua b/media/lua/client/TimedActions/TOC_CutLimbAction.lua index dc60fd4..ec75758 100644 --- a/media/lua/client/TimedActions/TOC_CutLimbAction.lua +++ b/media/lua/client/TimedActions/TOC_CutLimbAction.lua @@ -4,9 +4,9 @@ local AmputationHandler = require("Handlers/TOC_AmputationHandler") ----------------------------- ----@class CutLimbAction +---@class CutLimbAction : ISBaseTimedAction ---@field patient IsoPlayer ----@field surgeon IsoPlayer +---@field character IsoPlayer ---@field limbName string local CutLimbAction = ISBaseTimedAction:derive("CutLimbAction") @@ -15,18 +15,21 @@ local CutLimbAction = ISBaseTimedAction:derive("CutLimbAction") ---@param surgeon IsoPlayer ---@param limbName string ---@return CutLimbAction -function CutLimbAction:new(patient, surgeon, limbName) +function CutLimbAction:new(surgeon, patient, limbName) local o = {} setmetatable(o, self) self.__index = self + -- We need to follow ISBaseTimedAction. self.character is gonna be the surgeon + o.character = surgeon o.patient = patient - o.surgeon = surgeon o.limbName = limbName o.stopOnWalk = true o.stopOnRun = true - if o.surgeon:isTimedActionInstant() then o.maxTime = 1 end + + o.maxTime = 100 + if o.character:isTimedActionInstant() then o.maxTime = 1 end return o end @@ -37,7 +40,7 @@ function CutLimbAction:isValid() end function CutLimbAction:start() - if self.patient == self.surgeon then + if self.patient == self.character then -- Self self.handler = AmputationHandler:new(self.limbName) self.handler:damageDuringAmputation() diff --git a/media/lua/client/UI/TOC_CutLimbHandler.lua b/media/lua/client/UI/TOC_CutLimbHandler.lua deleted file mode 100644 index 8cd5b31..0000000 --- a/media/lua/client/UI/TOC_CutLimbHandler.lua +++ /dev/null @@ -1,57 +0,0 @@ -local BaseHandler = require("UI/TOC_HealthPanelBaseHandler") -local CutLimbAction = require("TimedActions/TOC_CutLimbAction") - ----@class CutLimbHandler ----@field panel any ----@field bodyPart any -local CutLimbHandler = BaseHandler:derive("CutLimbHandler") - - ----Creates new CutLimbHandler ----@param panel any ----@param bodyPart any ----@return CutLimbHandler -function CutLimbHandler:new(panel, bodyPart) - local o = BaseHandler.new(self, panel, bodyPart) - o.items.ITEMS = {} - return o -end - -function CutLimbHandler:checkItem(item) - local itemType = item:getType() - if itemType == "Saw" or itemType == "GardenSaw" or itemType == "Chainsaw" then - self:addItem(self.items.ITEMS, item) - end - -end - -function CutLimbHandler:addToMenu(context) - local types = self:getAllItemTypes(self.items.ITEMS) - if #types > 0 then - context:addOption(getText("ContextMenu_Amputate"), self, self.onMenuOptionSelected) - end -end - -function CutLimbHandler:dropItems(items) - local types = self:getAllItemTypes(items) - if #self.items.ITEMS > 0 and #types == 1 then - self:onMenuOptionSelected(types[1]) - return true - end - return false -end - -function CutLimbHandler:isValid(itemType) - return self:getItemOfType(self.items.ITEMS, itemType) -end - -function CutLimbHandler:perform(previousAction, itemType) - print("perform cutlimbhandler") - local item = self:getItemOfType(self.items.ITEMS, itemType) - previousAction = self:toPlayerInventory(item, previousAction) - - local action = CutLimbAction:new(self:getPatient(), self:getDoctor(), self.bodyPart) - ISTimedActionQueue.addAfter(previousAction, action) -end - -return CutLimbHandler \ No newline at end of file diff --git a/media/lua/client/UI/TOC_CutLimbInteractions.lua b/media/lua/client/UI/TOC_CutLimbInteractions.lua new file mode 100644 index 0000000..0d25114 --- /dev/null +++ b/media/lua/client/UI/TOC_CutLimbInteractions.lua @@ -0,0 +1,104 @@ +local BaseHandler = require("UI/TOC_HealthPanelBaseHandler") +local CutLimbAction = require("TimedActions/TOC_CutLimbAction") +local StaticData = require("TOC_StaticData") +local ModDataHandler = require("Handlers/TOC_ModDataHandler") + +--------------------- + + +---comment +---@param itemName string +local function CheckIfSaw(itemName) + return itemName == "Saw" or itemName == "GardenSaw" or itemName == "Chainsaw" +end + +local function PerformAction(limbName, surgeon, patient) + ISTimedActionQueue.add(CutLimbAction:new(surgeon, patient, limbName)) +end + +local function AddInventoryAmputationOptions(surgeonNum, context) + local surgeonObj = getSpecificPlayer(surgeonNum) + local option = context:addOption(getText("ContextMenu_Amputate"), nil) + local subMenu = context:getNew(context) + context:addSubMenu(option, subMenu) + for i=1, #StaticData.LIMBS_STRINGS do + local limbName = StaticData.LIMBS_STRINGS[i] + if not ModDataHandler.GetInstance():getIsCut(limbName) then + local limbTranslatedName = getText("ContextMenu_Limb_" .. limbName) + subMenu:addOption(limbTranslatedName, limbName, PerformAction, surgeonObj, surgeonObj) -- TODO Should be patient, not surgeon + end + end +end + +local function AddInventoryAmputationMenu(player, context, items) + local item = items[1] + if CheckIfSaw(item.name) then + AddInventoryAmputationOptions(player, context) + end +end + + +Events.OnFillInventoryObjectContextMenu.Add(AddInventoryAmputationMenu) + +------------------------------------- + +---@class CutLimbHandler : BaseHandler +local CutLimbHandler = BaseHandler:derive("CutLimbHandler") + + +---Creates new CutLimbHandler +---@param panel any +---@param bodyPart any +---@return CutLimbHandler +function CutLimbHandler:new(panel, bodyPart) + local o = BaseHandler.new(self, panel, bodyPart) + o.items.ITEMS = {} + return o +end + +function CutLimbHandler:checkItem(item) + local itemType = item:getType() + if CheckIfSaw(itemType) then + self:addItem(self.items.ITEMS, item) + end +end + +function CutLimbHandler:addToMenu(context) + --local types = self:getAllItemTypes(self.items.ITEMS) + --if #types > 0 then + local option = context:addOption(getText("ContextMenu_Amputate"), nil) + local subMenu = context:getNew(context) + context:addSubMenu(option, subMenu) + for i=1, #StaticData.LIMBS_STRINGS do + local limbName = StaticData.LIMBS_STRINGS[i] + if not ModDataHandler.GetInstance():getIsCut(limbName) then + local limbTranslatedName = getText("ContextMenu_Limb_" .. limbName) + subMenu:addOption(limbTranslatedName, self.onMenuOptionSelected, nil) + end + end + --end +end + +function CutLimbHandler:dropItems(items) + local types = self:getAllItemTypes(items) + if #self.items.ITEMS > 0 and #types == 1 then + self:onMenuOptionSelected(types[1]) + return true + end + return false +end + +function CutLimbHandler:isValid(itemType) + return self:getItemOfType(self.items.ITEMS, itemType) +end + +function CutLimbHandler:perform(previousAction, itemType) + print("perform cutlimbhandler") + local item = self:getItemOfType(self.items.ITEMS, itemType) + previousAction = self:toPlayerInventory(item, previousAction) + + local action = CutLimbAction:new(self:getPatient(), self:getDoctor(), self.bodyPart) + ISTimedActionQueue.addAfter(previousAction, action) +end + +return CutLimbHandler \ No newline at end of file diff --git a/media/lua/client/UI/TOC_HealthPanel.lua b/media/lua/client/UI/TOC_HealthPanel.lua index d93c281..6f1b697 100644 --- a/media/lua/client/UI/TOC_HealthPanel.lua +++ b/media/lua/client/UI/TOC_HealthPanel.lua @@ -3,7 +3,7 @@ local StaticData = require("TOC_StaticData") local CommonMethods = require("TOC_Common") ---@diagnostic disable: duplicate-set-field -local CutLimbHandler = require("UI/TOC_CutLimbHandler") +local CutLimbHandler = require("UI/TOC_CutLimbInteractions") -- TODO Use this to replace the sprites once a limb is cut ISHealthBodyPartPanel = ISBodyPartPanel:derive("ISHealthBodyPartPanel") diff --git a/media/lua/client/UI/TOC_HealthPanelBaseHandler.lua b/media/lua/client/UI/TOC_HealthPanelBaseHandler.lua index 0ff724a..9849c6e 100644 --- a/media/lua/client/UI/TOC_HealthPanelBaseHandler.lua +++ b/media/lua/client/UI/TOC_HealthPanelBaseHandler.lua @@ -1,5 +1,9 @@ -- Had to cop and paste this stuff from the base game since this is a local only class. Kinda shit, but eh +---@class BaseHandler : ISBaseObject +---@field panel ISUIElement +---@field bodyPart BodyPart +---@field items table local BaseHandler = ISBaseObject:derive("BaseHandler") function BaseHandler:new(panel, bodyPart) diff --git a/media/lua/shared/Translate/EN/ContextMenu_EN.txt b/media/lua/shared/Translate/EN/ContextMenu_EN.txt index e924b75..1f83731 100644 --- a/media/lua/shared/Translate/EN/ContextMenu_EN.txt +++ b/media/lua/shared/Translate/EN/ContextMenu_EN.txt @@ -1,5 +1,12 @@ ContextMenu_EN = { ContextMenu_Amputate = "Amputate", + + ContextMenu_Limb_Hand_L = "Left Hand", + ContextMenu_Limb_ForeArm_L = "Left forearm", + ContextMenu_Limb_UpperArm_L = "Left UpperArm" + ContextMenu_Limb_Hand_R = "Right Hand", + ContextMenu_Limb_ForeArm_R = "Right forearm", + ContextMenu_Limb_UpperArm_R = "Right UpperArm" ContextMenu_InstallProstRight = "Install prosthesis on right arm",