Some More stuff

This commit is contained in:
Pao
2023-02-26 22:01:14 +01:00
parent 6d2be51cd4
commit a536980d12
16 changed files with 314 additions and 315 deletions

View File

@@ -0,0 +1,123 @@
-- TODO this should be moved
local function TryToToResetEverythingOtherPlayer(_, patient, surgeon)
sendClientCommand(surgeon, "JCIO", "AskToResetEverything", { patient:getOnlineID() })
end
----------------------------------------------------------------------------------------------------------
if JCIO_ContextMenu == nil then
JCIO_ContextMenu = {}
end
JCIO_ContextMenu.CreateCheatsMenu = function(playerId, context, worldObjects, _)
local clickedPlayers = {}
local currentClickedPlayer = nil
local localPlayer = getSpecificPlayer(playerId)
--local players = getOnlinePlayers()
for _, v in pairs(worldObjects) do
-- help detecting a player by checking nearby squares
for x = v:getSquare():getX() - 1, v:getSquare():getX() + 1 do
for y = v:getSquare():getY() - 1, v:getSquare():getY() + 1 do
local sq = getCell():getGridSquare(x, y, v:getSquare():getZ())
if sq then
for i = 0, sq:getMovingObjects():size() - 1 do
local o = sq:getMovingObjects():get(i)
if instanceof(o, "IsoPlayer") then
currentClickedPlayer = o
if clickedPlayers[currentClickedPlayer:getUsername()] == nil then
-- FIXME this is to prevent context menu spamming. Find a better way
clickedPlayers[currentClickedPlayer:getUsername()] = true
if localPlayer:getAccessLevel() == "Admin" or isDebugEnabled() then
local rootOption = context:addOption("Just Cut It Off Cheats on " .. currentClickedPlayer:getUsername())
local rootMenu = context:getNew(context)
if currentClickedPlayer == localPlayer then
rootMenu:addOption("Reset JCIO for me", _, JCIO_Cheat.ResetEverything)
else
rootMenu:addOption("Reset JCIO for " .. currentClickedPlayer:getUsername(), _, TryToToResetEverythingOtherPlayer,
currentClickedPlayer, localPlayer)
end
context:addSubMenu(rootOption, rootMenu)
end
-- TocContextMenus.FillCutAndOperateMenus(local_player, clicked_player, worldObjects,
-- cut_menu, operate_menu)
--TocContextMenus.FillCheatMenu(context, cheat_menu)
break
end
end
end
end
end
end
end
end
JCIO_ContextMenu.CreateOperateWithOvenMenu = function(playerId, context, worldObjects, test)
local player = getSpecificPlayer(playerId)
-- TODO Let the player move towards the oven
local partData = player:getModData().JCIO.limbs
local isMainMenuAlreadyCreated = false
for _, currentObject in pairs(worldObjects) do
if instanceof(currentObject, "IsoStove") and (player:HasTrait("Brave") or player:getPerkLevel(Perks.Strength) >= 6) then
-- Check temperature
if currentObject:getCurrentTemperature() > 250 then
for _, partName in ipairs(JCIO_Common.GetPartNames()) do
if partData[partName].isCut and partData[partName].isAmputationShown and
not partData[partName].isOperated then
local subMenu = context:getNew(context);
if isMainMenuAlreadyCreated == false then
local rootMenu = context:addOption(getText('UI_ContextMenu_OperateOven'), worldObjects, nil);
context:addSubMenu(rootMenu, subMenu)
isMainMenuAlreadyCreated = true
end
subMenu:addOption(getText('UI_ContextMenu_' .. partName), worldObjects, TocOperateLocal,
getSpecificPlayer(playerId), partName,true)
end
end
end
break -- stop searching for stoves
end
end
end
JCIO_ContextMenu.CreateNewMenu = function(name, context, rootMenu)
local new_option = rootMenu:addOption(name)
local new_menu = context:getNew(context)
context:addSubMenu(new_option, new_menu)
return new_menu
end
JCIO_ContextMenu.FillCheatMenus = function(context, cheat_menu)
if cheat_menu then
local cheat_cut_and_fix_menu = JCIO_ContextMenu.CreateNewMenu("Cut and Fix", context, cheat_menu)
end
end
Events.OnFillWorldObjectContextMenu.Add(JCIO_ContextMenu.CreateOperateWithOvenMenu) -- this is probably too much
Events.OnFillWorldObjectContextMenu.Add(JCIO_ContextMenu.CreateCheatsMenu) -- TODO Add check only when admin is active

View File

@@ -60,7 +60,7 @@ local function GetImageName(partName, limbsData)
name = "media/ui/TOC/Empty.png"
elseif not part_data.isCut and
-- FIXME This doesn't work in MP on another player since we're trying to retrieve bodyDamage from another player
getPlayer():getBodyDamage():getBodyPart(TocGetBodyPartFromPartName(partName)):bitten() then -- Not cut but bitten
getPlayer():getBodyDamage():getBodyPart(JCIO_Common.GetBodyPartFromPartName(partName)):bitten() then -- Not cut but bitten
name = "media/ui/TOC/" .. partName .. "/Bite.png"
else -- Not cut
name = "media/ui/TOC/" .. partName .. "/Base.png"
@@ -100,7 +100,7 @@ end
local function IsPartBitten(partData, partName)
return not partData.isCut and
getPlayer():getBodyDamage():getBodyPart(TocGetBodyPartFromPartName(partName)):bitten()
getPlayer():getBodyDamage():getBodyPart(JCIO_Common.GetBodyPartFromPartName(partName)):bitten()
end
local function FindMinMax(lv)
@@ -243,11 +243,11 @@ JCIO_UI.SetupDescUI = function(surgeon, patient, limbsData, partName)
-- TODO add check for cuts and scratches
descUI["status"]:setText("Not cut")
descUI["status"]:setColor(1, 1, 1, 1)
if TocGetSawInInventory(surgeon) and not CheckIfProsthesisAlreadyInstalled(limbsData, partName) then
if JCIO_Common.GetSawInInventory(surgeon) and not CheckIfProsthesisAlreadyInstalled(limbsData, partName) then
descUI["b1"]:setVisible(true)
descUI["b1"]:setText("Cut")
descUI["b1"]:addArg("option", "Cut")
elseif TocGetSawInInventory(surgeon) and CheckIfProsthesisAlreadyInstalled(limbsData, partName) then
elseif JCIO_Common.GetSawInInventory(surgeon) and CheckIfProsthesisAlreadyInstalled(limbsData, partName) then
descUI["b1"]:setVisible(true)
descUI["b1"]:setText("Remove prosthesis before")
descUI["b1"]:addArg("option", "Nothing")
@@ -582,18 +582,18 @@ end
TocTempTable = {patient = nil, surgeon = nil}
JCIO_UI.onlineTempTable = {patient = nil, surgeon = nil}
JCIO.RefreshClientMenu = function(_)
if mainUI:getIsVisible() == false then
Events.OnTick.Remove(JCIO.RefreshClientMenu)
TocTempTable.patient = nil
TocTempTable.surgeon = nil
JCIO_UI.onlineTempTable.patient = nil
JCIO_UI.onlineTempTable.surgeon = nil
else
local limbs_data = TocTempTable.patient:getModData().TOC.Limbs
JCIO_UI.SetupMainUI(TocTempTable.patient, TocTempTable.patient, limbs_data)
local limbs_data = JCIO_UI.onlineTempTable.patient:getModData().TOC.Limbs
JCIO_UI.SetupMainUI(JCIO_UI.onlineTempTable.patient, JCIO_UI.onlineTempTable.patient, limbs_data)
end
end
@@ -604,14 +604,14 @@ JCIO.RefreshOtherPlayerMenu = function(_)
if mainUI:getIsVisible() == false then
Events.OnTick.Remove(JCIO.RefreshOtherPlayerMenu)
TocTempTable.patient = nil
TocTempTable.surgeon = nil
JCIO_UI.onlineTempTable.patient = nil
JCIO_UI.onlineTempTable.surgeon = nil
else
if ModData.get("TOC_PLAYER_DATA")[TocTempTable.patient:getUsername()] ~= nil then
local other_player_part_data = ModData.get("TOC_PLAYER_DATA")[TocTempTable.patient:getUsername()]
if ModData.get("JCIO_PLAYER_DATA")[JCIO_UI.onlineTempTable.patient:getUsername()] ~= nil then
local otherPlayerPartData = ModData.get("JCIO_PLAYER_DATA")[JCIO_UI.onlineTempTable.patient:getUsername()]
JCIO_UI.SetupMainUI(TocTempTable.surgeon, TocTempTable.patient, other_player_part_data[1])
JCIO_UI.SetupMainUI(JCIO_UI.onlineTempTable.surgeon, JCIO_UI.onlineTempTable.patient, otherPlayerPartData[1])
end
@@ -630,8 +630,8 @@ function ISNewHealthPanel.onClickJCIO(button)
local surgeon = button.otherPlayer
local patient = button.character
TocTempTable.patient = patient
TocTempTable.surgeon = surgeon
JCIO_UI.onlineTempTable.patient = patient
JCIO_UI.onlineTempTable.surgeon = surgeon
-- MP Handling
if surgeon then
@@ -671,10 +671,6 @@ function ISNewHealthPanel.onClickJCIO(button)
end
function ISHealthPanel:createChildren()
ISHealthPanel_createChildren(self)

View File

@@ -1,144 +0,0 @@
-- TODO this should be moved
local function TryToToResetEverythingOtherPlayer(_, patient, surgeon)
sendClientCommand(surgeon, "TOC", "AskToResetEverything", { patient:getOnlineID() })
end
----------------------------------------------------------------------------------------------------------
TocContextMenus = {}
TocContextMenus.CreateMenus = function(player, context, worldObjects, test)
local clicked_players_table = {}
local clicked_player = nil
local local_player = getSpecificPlayer(player)
--local players = getOnlinePlayers()
for k, v in pairs(worldObjects) do
-- help detecting a player by checking nearby squares
for x = v:getSquare():getX() - 1, v:getSquare():getX() + 1 do
for y = v:getSquare():getY() - 1, v:getSquare():getY() + 1 do
local sq = getCell():getGridSquare(x, y, v:getSquare():getZ())
if sq then
for i = 0, sq:getMovingObjects():size() - 1 do
local o = sq:getMovingObjects():get(i)
if instanceof(o, "IsoPlayer") then
clicked_player = o
if clicked_players_table[clicked_player:getUsername()] == nil then
-- FIXME this is to prevent context menu spamming. Find a better way
clicked_players_table[clicked_player:getUsername()] = true
if local_player:getAccessLevel() == "Admin" or isDebugEnabled() then
local root_option = context:addOption("The Only Cure Cheats on " .. clicked_player:getUsername())
local root_menu = context:getNew(context)
if clicked_player == local_player then
root_menu:addOption("Reset TOC for me", _, TocResetEverything)
else
root_menu:addOption("Reset TOC for " .. clicked_player:getUsername(), _, TryToToResetEverythingOtherPlayer,
clicked_player, local_player)
end
context:addSubMenu(root_option, root_menu)
end
-- TocContextMenus.FillCutAndOperateMenus(local_player, clicked_player, worldObjects,
-- cut_menu, operate_menu)
--TocContextMenus.FillCheatMenu(context, cheat_menu)
break
end
end
end
end
end
end
end
end
TocContextMenus.CreateOperateWithOvenMenu = function(player, context, worldObjects, test)
local player_obj = getSpecificPlayer(player)
-- TODO Let the player move towards the oven
local part_data = player_obj:getModData().TOC.Limbs
local is_main_menu_already_created = false
for _, 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
-- ipairs here to keep the order
for _, v_bodypart in ipairs(GetBodyParts()) do
if part_data[v_bodypart].is_cut and part_data[v_bodypart].is_amputation_shown and
not part_data[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)
is_main_menu_already_created = true
end
subMenu:addOption(getText('UI_ContextMenu_' .. v_bodypart), worldObjects, TocOperateLocal,
getSpecificPlayer(player), v_bodypart,true)
end
end
end
break -- stop searching for stoves
end
end
end
TocContextMenus.CreateNewMenu = function(name, context, root_menu)
local new_option = root_menu:addOption(name)
local new_menu = context:getNew(context)
context:addSubMenu(new_option, new_menu)
return new_menu
end
TocContextMenus.CreateCheatMenu = function(context, root_menu, local_player, clicked_player)
if local_player:getAccessLevel() == "Admin" or isDebugEnabled() then
local cheat_menu = TocContextMenus.CreateNewMenu("Cheat", context, root_menu)
if clicked_player == local_player then
cheat_menu:addOption("Reset TOC for me", _, TocResetEverything)
else
cheat_menu:addOption("Reset TOC for " .. clicked_player:getUsername(), _, TryToToResetEverythingOtherPlayer,
clicked_player, local_player)
end
return cheat_menu
end
end
TocContextMenus.FillCheatMenus = function(context, cheat_menu)
if cheat_menu then
local cheat_cut_and_fix_menu = TocContextMenus.CreateNewMenu("Cut and Fix", context, cheat_menu)
end
end
Events.OnFillWorldObjectContextMenu.Add(TocContextMenus.CreateOperateWithOvenMenu) -- this is probably too much
Events.OnFillWorldObjectContextMenu.Add(TocContextMenus.CreateMenus)