From fca316299d63a1b63e016355c7de4784bff4e024 Mon Sep 17 00:00:00 2001 From: Pao Date: Wed, 11 Jan 2023 20:47:54 +0100 Subject: [PATCH] Fixed a lot of stuff, broke a lot of stuff --- media/lua/client/HealthStuff/HealthUpdate.lua | 1 - media/lua/client/TOC_ContextMenus.lua | 189 ++++++++++++------ media/lua/client/TOC_GlobalFunctions.lua | 31 ++- media/lua/client/TOC_UI.lua | 8 +- media/lua/client/TOC_main.lua | 6 + 5 files changed, 149 insertions(+), 86 deletions(-) diff --git a/media/lua/client/HealthStuff/HealthUpdate.lua b/media/lua/client/HealthStuff/HealthUpdate.lua index 25ae0a6..44a6aa4 100644 --- a/media/lua/client/HealthStuff/HealthUpdate.lua +++ b/media/lua/client/HealthStuff/HealthUpdate.lua @@ -87,7 +87,6 @@ end function UpdatePlayerHealth(player, modData) local bodyDamage = player:getBodyDamage() - --local partNames = {"RightHand", "RightForearm", "RightArm", "LeftHand", "LeftForearm", "LeftArm"} if player:HasTrait("Insensitive") then bodyDamage:setPainReduction(49) end diff --git a/media/lua/client/TOC_ContextMenus.lua b/media/lua/client/TOC_ContextMenus.lua index 4d42f79..bb96cfd 100644 --- a/media/lua/client/TOC_ContextMenus.lua +++ b/media/lua/client/TOC_ContextMenus.lua @@ -1,3 +1,4 @@ + local function operateLocal(worldobjects, partName) local player = getPlayer(); ISTimedActionQueue.add(ISOperateArm:new(player, player, _, partName, true)); @@ -37,78 +38,142 @@ end -local function TOC_onFillWorldObjectContextMenu(playerId, context, worldobjects, _) - local player = getSpecificPlayer(playerId); - local clickedPlayer - local modData = player:getModData(); - - for _,object in ipairs(worldobjects) do - local square = object:getSquare() - if square then - for i=1,square:getObjects():size() do - local object2 = square:getObjects():get(i-1); - --For the oven operate part - if CheckIfCanBeOperated(modData) then - - - if instanceof(object2, "IsoStove") and (player:HasTrait("Brave") or player:getPerkLevel(Perks.Strength) >= 6) then - if not object2:isMicrowave() and object2:getCurrentTemperature() > 250 then - local rootMenu = context:addOption(getText('UI_ContextMenu_OperateOven'), worldobjects, nil); - local subMenu = context:getNew(context); + +-- why local? +function ISWorldObjectContextMenu.OnFillOperateWithOven(player, context, worldObjects, test) + local player_obj = getSpecificPlayer(player) + --local clickedPlayer + local modData = player_obj:getModData() + + local is_main_menu_already_created = false + + + --local props = v:getSprite() and v:getSprite():getProperties() or nil + + for k_stove, v_stove in pairs(worldObjects) do + if instanceof(v_stove, "IsoStove") and (player_obj:HasTrait("Brave") or player_obj:getPerkLevel(Perks.Strength) >= 6) then + + -- Check temperature + if v_stove:getCurrentTemperature() > 250 then + + for k_bodypart, v_bodypart in ipairs(GetBodyParts()) do + if modData.TOC[v_bodypart].is_cut and not modData.TOC[v_bodypart].is_operated then + local subMenu = context:getNew(context); + + if is_main_menu_already_created == false then + local rootMenu = context:addOption(getText('UI_ContextMenu_OperateOven'), worldObjects, nil); context:addSubMenu(rootMenu, subMenu) - - for k, v in pairs(GetBodyParts()) do - -- todo this is awful but it should work - if modData.TOC[v].is_cut and not modData.TOC[v].is_operated then - subMenu:addOption(getText('UI_ContextMenu_' .. v), worldobjects, operateLocal, v); - - end - - - end - - + is_main_menu_already_created = true end + subMenu:addOption(getText('UI_ContextMenu_' .. v_bodypart), worldObjects, operateLocal, v_bodypart) end end end - local movingObjects = square:getMovingObjects() - for i = 0, movingObjects:size() - 1 do - local o = movingObjects:get(i) - if instanceof(o, "IsoPlayer") then - clickedPlayer = o; - break - end - end - if clickedPlayer then - -- Pretty sure this check is kinda broken - if not ((-1 < clickedPlayer:getX() - player:getX() and clickedPlayer:getX() - player:getX() < 1) and (-1 < clickedPlayer:getY() - player:getY() and clickedPlayer:getY() - player:getY() < 1)) then - return false; - end - local rootOption = context:addOption("The Only Cure on " .. clickedPlayer:getUsername()); - local rootMenu = context:getNew(context); - local cutOption = rootMenu:addOption("Cut"); - local operateOption = rootMenu:addOption("Operate"); - local cutMenu = context:getNew(context); - local operateMenu = context:getNew(context); + break -- stop searching for stoves - context:addSubMenu(rootOption, rootMenu); - context:addSubMenu(cutOption, cutMenu); - context:addSubMenu(operateOption, operateMenu); - -- todo add checks so that we don't show these menus if a player has already beeen operated or amputated - for k, v in pairs(GetBodyParts()) do - cutMenu:addOption(getText('UI_ContextMenu_' .. v), worldobjects, otherPlayerLocal, v, "Cut", clickedPlayer) - operateMenu:addOption(getText('UI_ContextMenu_' .. v), worldobjects, otherPlayerLocal, v, "Operate", clickedPlayer); - - end - - - end end + end end -Events.OnFillWorldObjectContextMenu.Add(TOC_onFillWorldObjectContextMenu); \ No newline at end of file + + + + -- if instanceof(vtest, "IsoStove") and (player_obj:HasTrait("Brave") or player_obj:getPerkLevel(Perks.Strength) >= 6) then + -- --if v:getCurrentTemperature() > 250 then + -- local rootMenu = context:addOption(getText('UI_ContextMenu_OperateOven'), worldObjects, nil); + -- local subMenu = context:getNew(context); + -- context:addSubMenu(rootMenu, subMenu) + + -- for k_bodypart, v_bodypart in pairs(GetBodyParts()) do + -- -- todo this is awful but it should work + -- if modData.TOC[v_bodypart].is_cut and not modData.TOC[v_bodypart].is_operated then + -- subMenu:addOption(getText('UI_ContextMenu_' .. v_bodypart), worldObjects, operateLocal, v_bodypart); + + -- end + + + -- end + -- --end + -- end + + + + + + + + -- for _,object in ipairs(worldobjects) do + -- local square = object:getSquare() + -- if square then + -- for i=1,square:getObjects():size() do + -- local object2 = square:getObjects():get(i-1); + -- --For the oven operate part + + + -- if CheckIfCanBeOperated(modData) then + + + -- if instanceof(object2, "IsoStove") and (player:HasTrait("Brave") or player:getPerkLevel(Perks.Strength) >= 6) then + -- if not object2:isMicrowave() and object2:getCurrentTemperature() > 250 then + -- local rootMenu = context:addOption(getText('UI_ContextMenu_OperateOven'), worldobjects, nil); + -- local subMenu = context:getNew(context); + -- context:addSubMenu(rootMenu, subMenu) + + -- for k, v in pairs(GetBodyParts()) do + -- -- todo this is awful but it should work + -- if modData.TOC[v].is_cut and not modData.TOC[v].is_operated then + -- subMenu:addOption(getText('UI_ContextMenu_' .. v), worldobjects, operateLocal, v); + + -- end + + + -- end + + + -- end + -- end + -- end + -- end + + -- local movingObjects = square:getMovingObjects() + -- for i = 0, movingObjects:size() - 1 do + -- local o = movingObjects:get(i) + -- if instanceof(o, "IsoPlayer") then + -- clickedPlayer = o; + -- break + -- end + -- end + -- if clickedPlayer then + -- -- Pretty sure this check is kinda broken + -- if not ((-1 < clickedPlayer:getX() - player:getX() and clickedPlayer:getX() - player:getX() < 1) and (-1 < clickedPlayer:getY() - player:getY() and clickedPlayer:getY() - player:getY() < 1)) then + -- return false; + -- end + -- local rootOption = context:addOption("The Only Cure on " .. clickedPlayer:getUsername()); + -- local rootMenu = context:getNew(context); + -- local cutOption = rootMenu:addOption("Cut"); + -- local operateOption = rootMenu:addOption("Operate"); + -- local cutMenu = context:getNew(context); + -- local operateMenu = context:getNew(context); + + -- context:addSubMenu(rootOption, rootMenu); + -- context:addSubMenu(cutOption, cutMenu); + -- context:addSubMenu(operateOption, operateMenu); + -- -- todo add checks so that we don't show these menus if a player has already beeen operated or amputated + -- for k, v in ipairs(GetBodyParts()) do + -- cutMenu:addOption(getText('UI_ContextMenu_' .. v), worldobjects, otherPlayerLocal, v, "Cut", clickedPlayer) + -- operateMenu:addOption(getText('UI_ContextMenu_' .. v), worldobjects, otherPlayerLocal, v, "Operate", clickedPlayer); + + -- end + + + -- end + -- end + -- end + + +--Events.OnTick.Add(TheOnlyCure.CheckState); +Events.OnFillWorldObjectContextMenu.Add(ISWorldObjectContextMenu.OnFillOperateWithOven) -- this is probably too much \ No newline at end of file diff --git a/media/lua/client/TOC_GlobalFunctions.lua b/media/lua/client/TOC_GlobalFunctions.lua index 7c0d6ea..fd68837 100644 --- a/media/lua/client/TOC_GlobalFunctions.lua +++ b/media/lua/client/TOC_GlobalFunctions.lua @@ -115,25 +115,19 @@ function OperateArm(partName, surgeonFact, useOven) stats:setStress(100); end + if toc_data[partName].is_operated == false then + toc_data[partName].is_operated = true + toc_data[partName].cicatrization_time = toc_data[partName].cicatrization_time - (surgeonFact * 200) + if useOven then toc_data[partName].is_cauterized = true end + for depended_k, depended_v in pairs(toc_data[partName].depends_on) do + toc_data[depended_v].is_operated = true + toc_data[depended_v].cicatrization_time = toc_data[depended_v].cicatrization_time - (surgeonFact * 200) + if useOven then toc_data[depended_v].is_cauterized = true end - for k,v in pairs(GetBodyParts()) do - - if not toc_data[v].is_operated then - toc_data[v].is_operated = true - toc_data[v].cicatrization_time = toc_data[v].cicatrization_time - (surgeonFact * 200) - - if useOven then toc_data[v].is_cauterized = true end - - - for depended_k, depended_v in pairs(toc_data[v].depends_on) do - toc_data[depended_v].is_operated = true - toc_data[depended_v].cicatrization_time = toc_data[depended_v].cicatrization_time - (surgeonFact * 200) - if useOven then toc_data[depended_v].is_cauterized = true end - - end end - + end + SetBodyPartsStatus(player, partName, useOven) player:transmitModData(); end @@ -179,10 +173,9 @@ function SetBodyPartsStatus(player, partName, useOven) tmpBodyPart:setAdditionalPain(100); tmpBodyPart:setBleeding(false) tmpBodyPart:setBleedingTime(0) -- no bleeding since it's been cauterized - else - + else tmpBodyPart:setBleeding(true); - tmpBodyPart:setBleedingTime(10); -- Reset the bleeding + tmpBodyPart: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 b30831d..cc83044 100644 --- a/media/lua/client/TOC_UI.lua +++ b/media/lua/client/TOC_UI.lua @@ -47,9 +47,9 @@ end end elseif partData.is_cut and partData.is_cicatrized and not partData.has_prothesis_equipped and partData.is_amputation_shown then -- Cut and heal name = "media/ui/TOC/" .. partName .. "/Cut.png"; - elseif partData.is_cut and not partData.is_cicatrized and partData.is_amputation_shown and not partData.IsOperated then -- Cut not heal + elseif partData.is_cut and not partData.is_cicatrized and partData.is_amputation_shown and not partData.is_operated then -- Cut not heal name = "media/ui/TOC/" .. partName .. "/Bleed.png"; - elseif partData.is_cut and not partData.is_cicatrized and partData.is_amputation_shown and partData.IsOperated then -- Cut not heal + elseif partData.is_cut and not partData.is_cicatrized and partData.is_amputation_shown and partData.is_operated then -- Cut not heal name = "media/ui/TOC/" .. partName .. "/Operate.png"; elseif partData.is_cut and not partData.is_amputation_shown then -- Empty (like hand if forearm cut) name = "media/ui/TOC/Empty.png"; @@ -154,7 +154,7 @@ local function setDescUI(partName) -- Cut but not healed elseif partData.is_cut and not partData.is_cicatrized and partData.is_amputation_shown then - if partData.IsOperated then + if partData.is_operated then if partData.cicatrization_time > 1000 then descUI["textEtat"]:setText("Still a long way to go") descUI["textEtat"]:setColor(1, 0.8, 1, 0.2); @@ -181,7 +181,7 @@ local function setDescUI(partName) -- Set visibility - if partData.IsOperated then + if partData.is_operated then descUI["b1"]:setVisible(false); else descUI["b1"]:setText("Operate"); diff --git a/media/lua/client/TOC_main.lua b/media/lua/client/TOC_main.lua index 6db1775..b6fac86 100644 --- a/media/lua/client/TOC_main.lua +++ b/media/lua/client/TOC_main.lua @@ -1,3 +1,9 @@ +if not TheOnlyCure then + TheOnlyCure = {} +end + + + local function dropItem(player, modData) if (modData.TOC.RightHand.is_cut and not (modData.TOC.RightHand.IsEquiped or modData.TOC.RightForearm.IsEquiped)) or (modData.TOC.RightForearm.is_cut and not modData.TOC.RightForearm.IsEquiped) then if player:getPrimaryHandItem() ~= nil then