From 33d46be4b9657d945763418d361f68bcc777490f Mon Sep 17 00:00:00 2001 From: Pao Date: Sun, 15 Jan 2023 02:44:09 +0100 Subject: [PATCH] Holy shit it's working --- media/lua/client/TOC_ContextMenus.lua | 23 ++++++++++++++-- media/lua/client/TOC_UI.lua | 32 +++++++--------------- media/lua/client/TOC_Update.lua | 1 + media/lua/client/Utils/UsefulFunctions.lua | 16 +++++------ 4 files changed, 39 insertions(+), 33 deletions(-) diff --git a/media/lua/client/TOC_ContextMenus.lua b/media/lua/client/TOC_ContextMenus.lua index ade665e..5e04008 100644 --- a/media/lua/client/TOC_ContextMenus.lua +++ b/media/lua/client/TOC_ContextMenus.lua @@ -34,12 +34,25 @@ function TryTocAction(_, part_name, action, surgeon, patient) ui = GetConfirmUIMP() end + + if patient == nil then + patient = surgeon + end + if action == "Cut" then AskCanCutLimb(patient, part_name) elseif action == "Operate" then AskCanOperateLimb(patient, part_name) elseif action == "Equip" then - + local surgeon_inventory = surgeon: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(patient, prosthesis_to_equip, patient:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromBodyPart(part_name)))) + else + surgeon:Say("I need a prosthesis") + end @@ -47,13 +60,17 @@ function TryTocAction(_, part_name, action, surgeon, patient) elseif action == "Unequip" then --AskCanUnequipProsthesis(patient, part_name) - + local equipped_prosthesis = FindTocItemWorn(part_name, patient) + ISTimedActionQueue.add(ISUninstallProsthesis:new(patient, equipped_prosthesis, patient:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromBodyPart(part_name)))) end ui.actionAct = action ui.partNameAct = part_name ui.patient = patient - SendCommandToConfirmUIMP("Wait server") + --TODO just a workaround for now + if action ~= "Equip" and action ~= "Unequip" then + SendCommandToConfirmUIMP("Wait server") + end end end diff --git a/media/lua/client/TOC_UI.lua b/media/lua/client/TOC_UI.lua index cfa0fa3..5f74b62 100644 --- a/media/lua/client/TOC_UI.lua +++ b/media/lua/client/TOC_UI.lua @@ -164,37 +164,26 @@ end local function OnClickTocDescUI(button, args) -- Gets every arg from main - local patient = args.patient - local surgeon = args.surgeon + local patient = desc_ui.patient + local surgeon = desc_ui.surgeon + - if patient == nil then - patient = surgeon - end -- Validate action if args.option == "Cut" then TryTocAction(_, desc_ui.part_name, "Cut", surgeon, patient) elseif args.option == "Operate" then TryTocAction(_, desc_ui.part_name, "Operate", surgeon, patient) - elseif args.option == "Equip" then + TryTocAction(_, desc_ui.part_name, "Equip", surgeon, patient) -- TODO probably completely broken for MP -- TODO this is really janky - local surgeon_inventory = surgeon: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(patient, prosthesis_to_equip, patient:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromBodyPart(desc_ui.part_name)))) - else - surgeon:Say("I need a prosthesis") - end - main_ui:close() + elseif args.option == "Unequip" then - local equipped_prosthesis = FindTocItemWorn(desc_ui.part_name, patient) - ISTimedActionQueue.add(ISUninstallProsthesis:new(patient, equipped_prosthesis, patient:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromBodyPart(desc_ui.part_name)))) - main_ui:close() + TryTocAction(_, desc_ui.part_name, "Unequip", surgeon, patient) + end + main_ui:close() end @@ -388,6 +377,8 @@ function SetupTocDescUI(surgeon, patient, toc_data, part_name) local part_data = toc_data[part_name] desc_ui["textTitle"]:setText(TocGetDisplayText(part_name)) desc_ui.part_name = part_name + desc_ui.surgeon = surgeon + desc_ui.patient = patient if IsProsthesisInstalled(part_data) then -- Limb cut with prosthesis @@ -431,7 +422,6 @@ function SetupTocDescUI(surgeon, patient, toc_data, part_name) -- Set the operate button desc_ui["b1"]:setText("Operate") desc_ui["b1"]:addArg("option", "Operate") - desc_ui["b1"]:addArg("surgeon", surgeon) desc_ui["b1"]:setVisible(true) if part_data.cicatrization_time > 1000 then @@ -461,8 +451,6 @@ function SetupTocDescUI(surgeon, patient, toc_data, part_name) desc_ui["b1"]:setVisible(true) desc_ui["b1"]:setText("Cut") desc_ui["b1"]:addArg("option", "Cut") - desc_ui["b1"]:addArg("surgeon", surgeon) - desc_ui["b1"]:addArg("patient", patient) elseif GetSawInInventory(surgeon) and not CanLimbBeAmputated(toc_data, part_name) then desc_ui["b1"]:setVisible(true) desc_ui["b1"]:setText("Cut") diff --git a/media/lua/client/TOC_Update.lua b/media/lua/client/TOC_Update.lua index 16ff5be..f0879a3 100644 --- a/media/lua/client/TOC_Update.lua +++ b/media/lua/client/TOC_Update.lua @@ -142,6 +142,7 @@ function TheOnlyCure.HealSpecificPart(toc_data, part_name, player) toc_data[part_name].is_cicatrized = true -- TODO make this random if the player gets it or not + --FIXME they're gonna stack!!!! player:getTraits():add("Brave") player:getTraits():add("Insensitive") body_part_type:setBleeding(false); diff --git a/media/lua/client/Utils/UsefulFunctions.lua b/media/lua/client/Utils/UsefulFunctions.lua index ebe4360..11e4a77 100644 --- a/media/lua/client/Utils/UsefulFunctions.lua +++ b/media/lua/client/Utils/UsefulFunctions.lua @@ -21,12 +21,11 @@ end function GetAcceptingProsthesisBodyParts() - function GetLimbsBodyPartTypes() - return {BodyPartType.Hand_R, BodyPartType.ForeArm_R, - BodyPartType.Hand_L, BodyPartType.ForeArm_L} - - end + return {BodyPartType.Hand_R, BodyPartType.ForeArm_R, + BodyPartType.Hand_L, BodyPartType.ForeArm_L} + + end @@ -45,12 +44,13 @@ end function FindTocItemWorn(part_name, patient) local worn_items = patient:getWornItems() - for _, v in ipairs(worn_items) do - local item = v.getItem() + for i=1,worn_items:size()-1 do -- Maybe wornItems:size()-1 + local item = worn_items:get(i):getItem(); if item:getBodyLocation() == PartNameToBodyLocation(part_name) then - return item + return item; end end + end