From 36bee73878b8767c2a13dda42ea348b66138437a Mon Sep 17 00:00:00 2001 From: Pao Date: Sun, 22 Jan 2023 19:37:11 +0100 Subject: [PATCH] That's a lot of stuff, fixed X on online UI, prosthesis unequipping, prosthesis equipping for MP, ecc. --- media/lua/client/TOC_Checks.lua | 17 ++- media/lua/client/TOC_Client.lua | 72 +++++++++++- media/lua/client/TOC_CommonFunctions.lua | 24 +--- media/lua/client/TOC_HelperFunctions.lua | 31 +++++ media/lua/client/TOC_LocalActions.lua | 3 +- media/lua/client/TOC_UI.lua | 82 ++++++++++--- media/lua/client/TOC_main.lua | 108 +++++++++++++++--- media/lua/client/TimedActions/ISCutLimb.lua | 6 +- .../TimedActions/ISInstallProsthesis.lua | 46 +++++--- .../lua/client/TimedActions/ISOperateLimb.lua | 1 - .../TimedActions/ISUninstallProsthesis.lua | 94 +++++++++------ 11 files changed, 370 insertions(+), 114 deletions(-) diff --git a/media/lua/client/TOC_Checks.lua b/media/lua/client/TOC_Checks.lua index e437458..b3543a5 100644 --- a/media/lua/client/TOC_Checks.lua +++ b/media/lua/client/TOC_Checks.lua @@ -24,7 +24,22 @@ function CheckIfCanBeOperated(part_name) end -function CheckIfProsthesisCanBeEquipped(part_name) +function CheckIfProsthesisCanBeEquipped(part_name, item) + local part_data = getPlayer():getModData().TOC.Limbs + + + if item ~= nil then + if part_data[part_name].is_operated then + return true + end + else + + return false + end + + -- check if prosthesis is in the surgeon inventory... we need to get it before + + end diff --git a/media/lua/client/TOC_Client.lua b/media/lua/client/TOC_Client.lua index c89c1e9..c10789a 100644 --- a/media/lua/client/TOC_Client.lua +++ b/media/lua/client/TOC_Client.lua @@ -3,6 +3,9 @@ local Commands = {} Commands["ResponseCanAct"] = function(arg) + + + print("TOC: ResponseCanAct") local ui = GetConfirmUIMP() ui.responseReceive = true ui.responseAction = arg["toSend"][2] @@ -32,6 +35,24 @@ function SendOperateLimb(player, part_name, surgeon_factor, use_oven) sendClientCommand("TOC", "SendServer", arg) end +function SendEquipProsthesis(player, part_name, prosthesis_base_name) + local arg = {} + arg["From"] = getPlayer():getOnlineID() + arg["To"] = player:getOnlineID() + arg["command"] = "EquipProsthesis" + arg["toSend"] = { part_name, prosthesis_base_name} + sendClientCommand("TOC", "SendServer", arg) +end + +function SendUnequipProsthesis(player, part_name, equipped_prosthesis) + local arg = {} + arg["From"] = getPlayer():getOnlineID() + arg["To"] = player:getOnlineID() + arg["command"] = "UnequipProsthesis" + arg["toSend"] = { part_name, equipped_prosthesis} + sendClientCommand("TOC", "SendServer", arg) +end + function AskCanCutLimb(player, part_name) GetConfirmUIMP().responseReceive = false local arg = {} @@ -59,9 +80,23 @@ function AskCanEquipProsthesis(player, part_name) arg["To"] = player:getOnlineID() arg["command"] = "CanEquipProsthesis" arg["toSend"] = part_name + sendClientCommand("TOC", "SendServer", arg) end + +function AskCanUnequipProsthesis(player, part_name) + GetConfirmUIMP().responseReceive = false + local arg = {} + arg["From"] = getPlayer():getOnlineID() + arg["To"] = player:getOnlineID() + arg["command"] = "CanUnequipProsthesis" + arg["toSend"] = part_name + + sendClientCommand("TOC", "SendServer", arg) +end + + -- Patient (receive) Commands["CutLimb"] = function(arg) local arg = arg["toSend"] @@ -73,6 +108,28 @@ Commands["OperateLimb"] = function(arg) TheOnlyCure.OperateLimb(arg[1], arg[2], arg[3]) end + +Commands["EquipProsthesis"] = function(arg) + + -- part_name = arg[1] + -- prosthesis = arg[2] + + local arg = arg["toSend"] + + TheOnlyCure.EquipProsthesis(arg[1], arg[2]) + +end + +Commands["UnequipProsthesis"] = function(arg) + + -- part_name = arg[1] + + local arg = arg["toSend"] + + TheOnlyCure.UnequipProsthesis(arg[1]) + +end + Commands["CanCutLimb"] = function(arg) local part_name = arg["toSend"] @@ -95,14 +152,23 @@ end Commands["CanEquipProsthesis"] = function(arg) local part_name = arg["toSend"] - arg["To"] = arg["From"] arg["From"] = getPlayer():getOnlineID() arg["command"] = "ResponseCanAct" - arg["toSend"] = { part_name, "Equip", CheckIfProsthesisCanBeEquipped(part_name) } + arg["toSend"] = { part_name, "Equip", true } -- FIXME true just for test + sendClientCommand("TOC", "SendServer", arg) end +Commands["CanUnequipProsthesis"] = function(arg) + local part_name = arg["toSend"] + arg["To"] = arg["From"] + arg["From"] = getPlayer():getOnlineID() + arg["command"] = "ResponseCanAct" + arg["toSend"] = { part_name, "Unequip", true } -- FIXME true just for test + sendClientCommand("TOC", "SendServer", arg) + +end Commands["CanResetEverything"] = function(arg) local part_name = "RightHand" --useless @@ -112,7 +178,6 @@ Commands["CanResetEverything"] = function(arg) arg["command"] = "ResponseCanAct" arg["toSend"] = { part_name, "Cut", true } sendClientCommand("TOC", "SendServer", arg) - --TocResetEverything() end Commands["ResetEverything"] = function(arg) @@ -155,6 +220,7 @@ local function OnTocServerCommand(module, command, args) if module == 'TOC' then print("OnTocServerCommand " .. command) if Commands[command] then + print("Found command, executing it now") args = args or {} Commands[command](args) diff --git a/media/lua/client/TOC_CommonFunctions.lua b/media/lua/client/TOC_CommonFunctions.lua index f9c4f20..748208b 100644 --- a/media/lua/client/TOC_CommonFunctions.lua +++ b/media/lua/client/TOC_CommonFunctions.lua @@ -7,7 +7,7 @@ function GetBodyParts() end function GetProsthesisList() - return {"TOC.WoodenHook", "TOC.MetalHook", "TOC.MetalHand"} + return {"WoodenHook", "MetalHook", "MetalHand"} end @@ -100,26 +100,4 @@ function TocFindCorrectClothingProsthesis(item_name, part_name) end -local function PartNameToBodyLocation(name) - -- This is still correct but naming sucks - if name == "Right_Hand" then return "ArmRight_Prot" end - if name == "Right_LowerArm" then return "ArmRight_Prot" end - if name == "Right_UpperArm" then return "ArmRight_Prot" end - if name == "Left_Hand" then return "ArmLeft_Prot" end - if name == "Left_LowerArm" then return "ArmLeft_Prot" end - if name == "Left_UpperArm" then return "ArmLeft_Prot" end -end -function TocFindItemInProstBodyLocation(part_name, patient) - -- FIXME this can return even amputated limbs, and we're using it only for prosthetics. This is gonna break sooner or later - - local worn_items = patient:getWornItems() - - 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 - end - end - -end diff --git a/media/lua/client/TOC_HelperFunctions.lua b/media/lua/client/TOC_HelperFunctions.lua index f52b6ae..edfc276 100644 --- a/media/lua/client/TOC_HelperFunctions.lua +++ b/media/lua/client/TOC_HelperFunctions.lua @@ -121,6 +121,37 @@ function FixSingleBodyPartType(body_part_type, use_oven) end end + + +-- Unequip Prosthesis + +local function PartNameToBodyLocation(name) + -- This is still correct but naming sucks + if name == "Right_Hand" then return "ArmRight_Prot" end + if name == "Right_LowerArm" then return "ArmRight_Prot" end + if name == "Right_UpperArm" then return "ArmRight_Prot" end + if name == "Left_Hand" then return "ArmLeft_Prot" end + if name == "Left_LowerArm" then return "ArmLeft_Prot" end + if name == "Left_UpperArm" then return "ArmLeft_Prot" end +end + +function TocFindItemInProstBodyLocation(part_name, patient) + -- FIXME this can return even amputated limbs, and we're using it only for prosthetics. This is gonna break sooner or later + + -- Can't be used for online purposes, since we can't get the online inventory of another player + local worn_items = patient:getWornItems() + + 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 + end + end + +end + + + ------------------------------------- -- Override helper diff --git a/media/lua/client/TOC_LocalActions.lua b/media/lua/client/TOC_LocalActions.lua index 8d2bf53..22fdd80 100644 --- a/media/lua/client/TOC_LocalActions.lua +++ b/media/lua/client/TOC_LocalActions.lua @@ -29,8 +29,7 @@ function TocEquipProsthesisLocal(_, patient, surgeon, part_name) 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(TocGetBodyPartTypeFromPartName(part_name)))) + ISTimedActionQueue.add(ISInstallProsthesis:new(surgeon, patient, prosthesis_to_equip, part_name)) else surgeon:Say("I need a prosthesis") end diff --git a/media/lua/client/TOC_UI.lua b/media/lua/client/TOC_UI.lua index b2f5921..cef32bb 100644 --- a/media/lua/client/TOC_UI.lua +++ b/media/lua/client/TOC_UI.lua @@ -174,7 +174,7 @@ function OnClickTocConfirmUIMP(button, args) if confirm_ui_mp.actionAct == "Cut" and args.option == "yes" then ISTimedActionQueue.add(ISCutLimb:new(confirm_ui_mp.patient, player, confirm_ui_mp.partNameAct)) elseif confirm_ui_mp.actionAct == "Operate" and args.option == "yes" then - local playerInv = player:getInventory(); + local playerInv = player:getInventory() local item = playerInv:getItemFromType('TOC.Real_surgeon_kit') or playerInv:getItemFromType('TOC.Surgeon_kit') or playerInv:getItemFromType('TOC.Improvised_surgeon_kit') if item then @@ -185,11 +185,36 @@ function OnClickTocConfirmUIMP(button, args) end elseif confirm_ui_mp.actionAct == "Equip" and args.option == "yes" then - print("Equip mp comp") - + 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, confirm_ui_mp.patient, prosthesis_to_equip, confirm_ui_mp.partNameAct)) + else + player:Say("I don't have a prosthesis right now") + end + elseif confirm_ui_mp.actionAct == "Unequip" and args.option == "yes" then - print("Unequip mp comp") + + -- We can't check if the player has a prosthesis right now, we need to do it later + + -- TODO should check if player has a prosthesis equipped before doing it + + -- TODO Player is surgeon, but we don't have a confirm_ui_mp.surgeon... awful awful awful + + -- TODO Workaround for now, we'd need to send data from patient before doing it since we can't access his inventory from the surgeon + if confirm_ui_mp.patient == player then + ISTimedActionQueue.add(ISUninstallProsthesis:new(player, confirm_ui_mp.patient, confirm_ui_mp.partNameAct)) + + else + player:Say("I can't do that, they need to do it themselves") + + end + + end @@ -477,15 +502,17 @@ function SendCommandToConfirmUIMP(action, isBitten, userName, partName) confirm_ui_mp:bringToTop() confirm_ui_mp:open() - if action == "Cut" or action == "Operate" then + + if action ~= "Wait server" then confirm_ui_mp["text4"]:setText("You're gonna " .. - action .. " the " .. getText("UI_ContextMenu_" .. partName) .. " of " .. userName) + action .. " the " .. getText("UI_ContextMenu_" .. partName) .. " of " .. userName) + confirm_ui_mp["text2"]:setText("Are you sure?") confirm_ui_mp["text2"]:setColor(1, 0, 0, 0) - confirm_ui_mp["b1"]:setVisible(true); - confirm_ui_mp["b2"]:setVisible(true); + confirm_ui_mp["b1"]:setVisible(true) + confirm_ui_mp["b2"]:setVisible(true) + else - elseif action == "Wait server" then confirm_ui_mp["text4"]:setText(action) confirm_ui_mp["text3"]:setText("") confirm_ui_mp["text2"]:setText("") @@ -493,7 +520,6 @@ function SendCommandToConfirmUIMP(action, isBitten, userName, partName) confirm_ui_mp["b2"]:setVisible(false) end - end -------------------------------------------- @@ -503,6 +529,14 @@ local ISHealthPanel_render = ISHealthPanel.render -- Add button to health panel +TocTempTable = { + TempPatient = nil, + TempSurgeon = nil +} + + + + function ISNewHealthPanel.onClick_TOC(button) local surgeon = button.otherPlayer @@ -511,17 +545,19 @@ function ISNewHealthPanel.onClick_TOC(button) if surgeon then if surgeon == patient then SetupTocMainUI(surgeon, surgeon, surgeon:getModData().TOC) - --SetupTocConfirmUI(surgeon, surgeon) else -- MP stuff, try to get the other player data and display it on the surgeon display sendClientCommand(surgeon, "TOC", "GetPlayerData", { surgeon:getOnlineID(), patient:getOnlineID() }) - SetupTocMainUI(surgeon, patient, MP_other_player_toc_data) - --SetupTocConfirmUI(surgeon, patient) + + TocTempTable.TempPatient = patient + TocTempTable.TempSurgeon = surgeon + + -- Wait for ack + Events.OnTick.Add(TocWaitForOnlinePlayerData) end else -- This is when surgeon doesnt exist for some reason. SetupTocMainUI(patient, patient, patient:getModData().TOC) - -- SetupTocConfirmUI(patient, patient) end main_ui:toggle() @@ -529,6 +565,24 @@ function ISNewHealthPanel.onClick_TOC(button) end + +function TocWaitForOnlinePlayerData(numberTicks) + if MP_other_player_toc_data ~= nil then + SetupTocMainUI(TocTempTable.TempSurgeon, TocTempTable.TempPatient, MP_other_player_toc_data) + + + TocTempTable.TempSurgeon = nil + TocTempTable.TempPatient = nil + MP_other_player_toc_data = nil + Events.OnTick.Remove(TocWaitForOnlinePlayerData) + + + end + + +end + + function ISHealthPanel:createChildren() ISHealthPanel_createChildren(self) diff --git a/media/lua/client/TOC_main.lua b/media/lua/client/TOC_main.lua index 17576aa..ffaaa57 100644 --- a/media/lua/client/TOC_main.lua +++ b/media/lua/client/TOC_main.lua @@ -341,6 +341,68 @@ function TheOnlyCure.OperateLimb(part_name, surgeon_factor, use_oven) player:transmitModData() end + +function TheOnlyCure.EquipProsthesis(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 -- TODO should we show that the hand has a prost too if it's installed in the forearm? + toc_data.Limbs[part_name].equipped_prosthesis = toc_data.Prosthesis[prosthesis_base_name][part_name] + + player:setWornItem(added_prosthesis:getBodyLocation(), added_prosthesis) + + + end + end + + + + + +end + + +function TheOnlyCure.UnequipProsthesis(part_name, equipped_prosthesis) + local player = getPlayer() + + local toc_data = player:getModData().TOC + + + + -- we've got equipped_prosthesis, so we should be able to get it directly + 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 + player:getInventory():AddItem("TOC." .. prosthesis_name) + + player:setWornItem(equipped_prosthesis:getBodyLocation(), nil) + player:getInventory():Remove(equipped_prosthesis) + player:transmitModData() + + -- needed to remove from queue / start next. + end + + end + + +end + + + + function TryTocAction(_, part_name, action, surgeon, patient) -- TODO add checks so that we don't show these menus if a player has already beeen operated or amputated -- TODO at this point surgeon doesnt do anything. We'll fix this later @@ -379,35 +441,45 @@ function TryTocAction(_, part_name, action, surgeon, patient) 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(TocGetBodyPartTypeFromPartName(part_name)))) - else - surgeon:Say("I need a prosthesis") - end + + --local surgeon_inventory = surgeon:getInventory() + + --local prosthesis_to_equip = surgeon_inventory:getItemFromType('TOC.MetalHook') + --local prosthesis_to_equip = surgeon_inventory:getItemFromType('TOC.MetalHand') or + -- surgeon_inventory:getItemFromType('TOC.MetalHook') or + -- surgeon_inventory:getItemFromType('TOC.WoodenHook') + + + + AskCanEquipProsthesis(patient, part_name) + + + + + -- if prosthesis_to_equip then + -- ISTimedActionQueue.add(ISInstallProsthesis:new(patient, prosthesis_to_equip, + -- patient:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromPartName(part_name)))) + -- else + -- surgeon:Say("I need a prosthesis") + -- end --AskCanEquipProsthesis(patient, part_name, item) elseif action == "Unequip" then - --AskCanUnequipProsthesis(patient, part_name) - local equipped_prosthesis = TocFindItemInProstBodyLocation(part_name, patient) - ISTimedActionQueue.add(ISUninstallProsthesis:new(patient, equipped_prosthesis, - patient:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromPartName(part_name)))) + AskCanUnequipProsthesis(patient, part_name) + -- local equipped_prosthesis = TocFindItemInProstBodyLocation(part_name, patient) + -- ISTimedActionQueue.add(ISUninstallProsthesis:new(patient, equipped_prosthesis, + -- patient:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromPartName(part_name)))) end ui.actionAct = action ui.partNameAct = part_name ui.patient = patient - --TODO just a workaround for now - if action ~= "Equip" and action ~= "Unequip" then - SendCommandToConfirmUIMP("Wait server") - end + + SendCommandToConfirmUIMP("Wait server") + end end diff --git a/media/lua/client/TimedActions/ISCutLimb.lua b/media/lua/client/TimedActions/ISCutLimb.lua index dffe9e0..e5c3368 100644 --- a/media/lua/client/TimedActions/ISCutLimb.lua +++ b/media/lua/client/TimedActions/ISCutLimb.lua @@ -125,8 +125,12 @@ function ISCutLimb:perform() end function ISCutLimb:new(patient, surgeon, part_name) + + -- TODO align surgeon, patient not patient, surgeon + + local o = {} - setmetatable(o, self) + setmetatable(o, self) -- TODO what's this crap? self.__index = self o.part_name = part_name o.character = surgeon -- For anim diff --git a/media/lua/client/TimedActions/ISInstallProsthesis.lua b/media/lua/client/TimedActions/ISInstallProsthesis.lua index b753c9b..868dc1b 100644 --- a/media/lua/client/TimedActions/ISInstallProsthesis.lua +++ b/media/lua/client/TimedActions/ISInstallProsthesis.lua @@ -13,8 +13,14 @@ end function ISInstallProsthesis:start() self.item:setJobType("Install prosthesis") self.item:setJobDelta(0.0) + + self:setActionAnim("WearClothing") self:setAnimVariable("WearClothingLocation", "Jacket") + + + + end function ISInstallProsthesis:stop() @@ -31,42 +37,46 @@ function ISInstallProsthesis:perform() self.item:setJobDelta(0.0) - local toc_data = self.character:getModData().TOC - local part_name = TocGetPartNameFromBodyPartType(self.bodyPart:getType()) + -- local toc_data = self.character:getModData().TOC + --local part_name = TocGetPartNameFromBodyPartType(self.bodyPart:getType()) + + local body_part_type = TocGetBodyPartTypeFromPartName(self.part_name) -- Check if can be performed. This shouldn't be necessary, but just to be sure - if self.bodyPart:getType() == BodyPartType.UpperArm_L or self.bodyPart:getType() == BodyPartType.UpperArm_R then + if body_part_type == BodyPartType.UpperArm_L or body_part_type == BodyPartType.UpperArm_R then print("Can't equip prosthesis") return end - local prosthesis_name = TocFindCorrectClothingProsthesis(prosthesis_base_name, part_name) - self.cloth = self.character:getInventory():AddItem(prosthesis_name) - - if self.cloth ~= nil then + self.surgeon:getInventory():Remove(prosthesis_base_name) -- Removes the base item and substitute it with the part one - if part_name then - toc_data.Limbs[part_name].is_prosthesis_equipped = true -- TODO should we show that the hand has a prost too if it's installed in the forearm? - toc_data.Limbs[part_name].equipped_prosthesis = toc_data.Prosthesis[prosthesis_base_name][part_name] - - self.character:getInventory():Remove(self.item) - self.character:setWornItem(self.cloth:getBodyLocation(), self.cloth) - end + if self.patient ~= self.surgeon and isClient() then + SendEquipProsthesis(self.patient, self.part_name, prosthesis_base_name) + else + TheOnlyCure.EquipProsthesis(self.part_name, prosthesis_base_name) end - self.character:transmitModData() -- needed to remove from queue / start next. ISBaseTimedAction.perform(self) end -function ISInstallProsthesis:new(character, item, bodyPart) - local o = ISBaseTimedAction.new(self, character) +function ISInstallProsthesis:new(surgeon, patient, item, part_name) + + local o = ISBaseTimedAction.new(self, patient) + + o.character = surgeon -- For animation, since self.startAnim or whatever relies on this + o.surgeon = surgeon + o.patient = patient + o.item = item - o.bodyPart = bodyPart + + o.part_name = part_name + + --o.bodyPart = bodyPart o.maxTime = 100 o.stopOnWalk = true o.stopOnRun = true diff --git a/media/lua/client/TimedActions/ISOperateLimb.lua b/media/lua/client/TimedActions/ISOperateLimb.lua index c8d1f6d..f5d1580 100644 --- a/media/lua/client/TimedActions/ISOperateLimb.lua +++ b/media/lua/client/TimedActions/ISOperateLimb.lua @@ -58,7 +58,6 @@ function ISOperateLimb:perform() if self.patient ~= self.surgeon and isClient() then SendOperateLimb(self.patient, self.part_name, surgeon_factor, use_oven) - --SendOperateArm(self.patient, self.part_name, surgeon_factor, use_oven) else TheOnlyCure.OperateLimb(self.part_name, surgeon_factor, use_oven) end diff --git a/media/lua/client/TimedActions/ISUninstallProsthesis.lua b/media/lua/client/TimedActions/ISUninstallProsthesis.lua index a79119e..c6046b5 100644 --- a/media/lua/client/TimedActions/ISUninstallProsthesis.lua +++ b/media/lua/client/TimedActions/ISUninstallProsthesis.lua @@ -3,7 +3,16 @@ require "TimedActions/ISBaseTimedAction" ISUninstallProsthesis = ISBaseTimedAction:derive("ISUninstallProsthesis"); function ISUninstallProsthesis:isValid() - return true; + + if self.item ~= nil then + return true + else + return false + end + + + + end function ISUninstallProsthesis:update() @@ -41,40 +50,50 @@ function ISUninstallProsthesis:perform() end end - local toc_data = self.character:getModData().TOC - local body_part_type = self.bodyPart:getType() - local accepting_body_parts = GetAcceptingProsthesisBodyPartTypes() - if accepting_body_parts == nil then - return -- should never happen + if self.patient ~= self.surgeon and isClient() then + + SendUnequipProsthesis(self.patient, self.part_name, self.item) + else + TheOnlyCure.UnequipProsthesis(self.part_name, self.item) end + self.character:transmitModData() - for _, v in ipairs(GetAcceptingProsthesisBodyPartTypes()) do - if self.bodyPart:getType() == v then - local part_name = TocGetPartNameFromBodyPartType(v) - print("Found prost in " .. part_name) - if part_name then - toc_data.Limbs[part_name].is_prosthesis_equipped = false - local item_full_type = self.item:getFullType() - print("Searching for " .. item_full_type) - for _, prost_v in ipairs(GetProsthesisList()) do - local prosthesis_name = string.match(item_full_type, prost_v) + ISBaseTimedAction.perform(self) - if prosthesis_name then - self.character:getInventory():AddItem(prosthesis_name) + - self.character:setWornItem(self.item:getBodyLocation(), nil) - self.character:getInventory():Remove(self.item) - self.character:transmitModData() - -- needed to remove from queue / start next. - ISBaseTimedAction.perform(self) - end - end - end + + -- for _, v in ipairs(GetAcceptingProsthesisBodyPartTypes()) do + -- if self.bodyPart:getType() == v then + -- local part_name = TocGetPartNameFromBodyPartType(v) + + -- print("Found prost in " .. part_name) + -- if part_name then + -- toc_data.Limbs[part_name].is_prosthesis_equipped = false + -- local item_full_type = self.item:getFullType() + -- print("Searching for " .. item_full_type) + -- for _, prost_v in ipairs(GetProsthesisList()) do + -- local prosthesis_name = string.match(item_full_type, prost_v) + + -- if prosthesis_name then + -- self.character:getInventory():AddItem(prosthesis_name) + + -- self.character:setWornItem(self.item:getBodyLocation(), nil) + -- self.character:getInventory():Remove(self.item) + -- self.character:transmitModData() + + -- -- needed to remove from queue / start next. + -- ISBaseTimedAction.perform(self) + + -- end + -- end + + -- end @@ -84,18 +103,27 @@ function ISUninstallProsthesis:perform() - end - end + -- end + -- end -- TODO Make the object currently on the hand return to the inventory end -function ISUninstallProsthesis:new(character, item, bodyPart) - local o = ISBaseTimedAction.new(self, character); - o.item = item; - o.character = character; - o.bodyPart = bodyPart; +function ISUninstallProsthesis:new(surgeon, patient, part_name) + local o = ISBaseTimedAction.new(self, surgeon) + + o.item = TocFindItemInProstBodyLocation(part_name, patient) + o.character = surgeon -- For animation purposes + + o.patient = patient + o.surgeon = surgeon + + o.part_name = part_name + + + + o.maxTime = 100; o.stopOnWalk = true; o.stopOnRun = true;