Merge branch 'global-mod-data'
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -42,6 +42,7 @@
|
||||
"ISInventoryPaneContextMenu",
|
||||
"ISDropItemAction",
|
||||
"BloodBodyPartType",
|
||||
"ISInventoryPane"
|
||||
"ISInventoryPane",
|
||||
"ModData"
|
||||
]
|
||||
}
|
||||
@@ -6,21 +6,27 @@ end
|
||||
|
||||
-----------------------------------------
|
||||
-- MP HANDLING CHECKS
|
||||
function CheckIfCanBeCut(part_name)
|
||||
function CheckIfCanBeCut(part_name, limbs_data)
|
||||
|
||||
local toc_data = getPlayer():getModData().TOC
|
||||
local check = (not toc_data.Limbs[part_name].is_cut) and
|
||||
(not CheckIfProsthesisAlreadyInstalled(toc_data.Limbs, part_name))
|
||||
if limbs_data == nil then
|
||||
limbs_data = getPlayer():getModData().TOC.Limbs
|
||||
|
||||
end
|
||||
local check = (not limbs_data[part_name].is_cut) and
|
||||
(not CheckIfProsthesisAlreadyInstalled(limbs_data, part_name))
|
||||
|
||||
return check
|
||||
|
||||
end
|
||||
|
||||
function CheckIfCanBeOperated(part_name)
|
||||
function CheckIfCanBeOperated(part_name, limbs_data)
|
||||
|
||||
local part_data = getPlayer():getModData().TOC.Limbs
|
||||
if limbs_data == nil then
|
||||
limbs_data = getPlayer():getModData().TOC.Limbs
|
||||
end
|
||||
|
||||
return part_data[part_name].is_operated == false and part_data[part_name].is_amputation_shown
|
||||
|
||||
return limbs_data[part_name].is_operated == false and limbs_data[part_name].is_amputation_shown
|
||||
|
||||
end
|
||||
|
||||
@@ -48,17 +54,17 @@ end
|
||||
|
||||
|
||||
|
||||
function CheckIfProsthesisAlreadyInstalled(part_data, part_name)
|
||||
function CheckIfProsthesisAlreadyInstalled(limbs_data, part_name)
|
||||
|
||||
local r = "Right"
|
||||
local l = "Left"
|
||||
|
||||
|
||||
if string.find(part_name, r) then
|
||||
return (part_data[r .. "_Hand"].is_prosthesis_equipped or part_data[r .. "_LowerArm"].is_prosthesis_equipped)
|
||||
return (limbs_data[r .. "_Hand"].is_prosthesis_equipped or limbs_data[r .. "_LowerArm"].is_prosthesis_equipped)
|
||||
|
||||
elseif string.find(part_name, l) then
|
||||
return (part_data[l .. "_Hand"].is_prosthesis_equipped or part_data[l .. "_LowerArm"].is_prosthesis_equipped)
|
||||
return (limbs_data[l .. "_Hand"].is_prosthesis_equipped or limbs_data[l .. "_LowerArm"].is_prosthesis_equipped)
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -229,3 +229,30 @@ local function OnTocServerCommand(module, command, args)
|
||||
end
|
||||
|
||||
Events.OnServerCommand.Add(OnTocServerCommand)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
---------------------------------- TEST -----------------------------
|
||||
|
||||
|
||||
function TOC_OnReceiveGlobalModData(key, modData)
|
||||
if modData then
|
||||
ModData.remove(key)
|
||||
ModData.add(key, modData)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Events.OnReceiveGlobalModData.Add(TOC_OnReceiveGlobalModData)
|
||||
|
||||
function TOC_OnConnected()
|
||||
ModData.request("TOC_PLAYER_DATA")
|
||||
end
|
||||
|
||||
|
||||
Events.OnConnected.Add(TOC_OnConnected)
|
||||
|
||||
|
||||
@@ -102,7 +102,4 @@ function TocMapOldDataToNew(mod_data)
|
||||
|
||||
|
||||
end
|
||||
getPlayer():transmitModData()
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -101,14 +101,6 @@ TocContextMenus.CreateOperateWithOvenMenu = function(player, context, worldObjec
|
||||
end
|
||||
|
||||
|
||||
TocContextMenus.DoCut = function(_, patient, surgeon, part_name)
|
||||
|
||||
if TocGetSawInInventory(surgeon) then
|
||||
ISTimedActionQueue.add(ISCutLimb:new(patient, surgeon, part_name));
|
||||
else
|
||||
surgeon:Say("I don't have a saw on me")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -124,39 +116,38 @@ end
|
||||
|
||||
|
||||
TocContextMenus.FillCutAndOperateMenus = function(local_player, clicked_player, world_objects, cut_menu, operate_menu)
|
||||
|
||||
local local_part_data = local_player:getModData().TOC.Limbs
|
||||
|
||||
for _, v in ipairs(GetBodyParts()) do
|
||||
|
||||
|
||||
if local_player == clicked_player then -- Local player
|
||||
if CheckIfCanBeCut(v) then
|
||||
if CheckIfCanBeCut(v) and TocGetSawInInventory(local_player) ~= nil then
|
||||
|
||||
cut_menu:addOption(getText('UI_ContextMenu_' .. v), _, TryTocAction, v, "Cut", local_player, local_player)
|
||||
|
||||
elseif CheckIfCanBeOperated(v) then
|
||||
elseif CheckIfCanBeOperated(v) and TocGetKitInInventory(local_player) ~= nil then
|
||||
operate_menu:addOption(getText('UI_ContextMenu_' .. v), _, TryTocAction, v, "Operate", local_player,
|
||||
local_player)
|
||||
end
|
||||
|
||||
else -- Another player
|
||||
-- TODO add way to prevent cutting already cut parts of another player
|
||||
cut_menu:addOption(getText('UI_ContextMenu_' .. v), world_objects, TryTocAction, v, "Cut", local_player,
|
||||
clicked_player)
|
||||
operate_menu:addOption(getText('UI_ContextMenu_' .. v), world_objects, TryTocAction, v, "Operate",
|
||||
local_player, clicked_player)
|
||||
|
||||
if ModData.get("TOC_PLAYER_DATA")[clicked_player:getUsername()] ~= nil then
|
||||
local anotherPlayerData = ModData.get("TOC_PLAYER_DATA")[clicked_player:getUsername()]
|
||||
|
||||
if CheckIfCanBeCut(v, anotherPlayerData[1]) and TocGetSawInInventory(local_player) then
|
||||
cut_menu:addOption(getText('UI_ContextMenu_' .. v), world_objects, TryTocAction, v, "Cut", local_player,
|
||||
clicked_player)
|
||||
elseif CheckIfCanBeOperated(v, anotherPlayerData[1]) and TocGetKitInInventory(local_player) ~= nil then
|
||||
operate_menu:addOption(getText('UI_ContextMenu_' .. v), world_objects, TryTocAction, v, "Operate",
|
||||
local_player, clicked_player)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
TocContextMenus.CreateCheatMenu = function(context, root_menu, local_player, clicked_player)
|
||||
if local_player:getAccessLevel() == "Admin" then
|
||||
if local_player:getAccessLevel() == "Admin" or isDebugEnabled() then
|
||||
|
||||
local cheat_menu = TocContextMenus.CreateNewMenu("Cheat", context, root_menu)
|
||||
|
||||
|
||||
@@ -1,23 +1,37 @@
|
||||
function TocResetEverything()
|
||||
|
||||
-- This has to be run on the local player to be sure that we're correctly reassigning everything
|
||||
local player = getPlayer()
|
||||
local player_inventory = player:getInventory()
|
||||
local mod_data = player:getModData()
|
||||
mod_data.TOC = nil
|
||||
TheOnlyCure.InitTheOnlyCure(_, player)
|
||||
|
||||
-- Destroy the amputation model
|
||||
-- Destroy the amputation or prosthesis item
|
||||
for _, v in ipairs(GetBodyParts()) do
|
||||
local cloth = player:getInventory():FindAndReturn(TocFindAmputatedClothingFromPartName(v))
|
||||
--local amputated_clothing = player:getInventory():FindAndReturn(TocFindAmputatedClothingFromPartName(v))
|
||||
-- TODO make it better
|
||||
local amputation_item_name = TocFindAmputationOrProsthesisName(v, player, "Amputation")
|
||||
local prosthesis_item_name = TocFindAmputationOrProsthesisName(v, player, "Prosthesis")
|
||||
|
||||
if cloth ~= nil then
|
||||
print("Resetting " .. cloth:getName())
|
||||
player:removeWornItem(cloth)
|
||||
player:getInventory():Remove(cloth)
|
||||
if amputation_item_name ~= nil then
|
||||
local amputation_item = player_inventory:FindAndReturn(amputation_item_name)
|
||||
if amputation_item ~= nil then
|
||||
print("Resetting " .. amputation_item:getName())
|
||||
player:removeWornItem(amputation_item)
|
||||
player:getInventory():Remove(amputation_item)
|
||||
end
|
||||
amputation_item = nil -- reset it
|
||||
end
|
||||
cloth = nil -- reset it
|
||||
if prosthesis_item_name ~= nil then
|
||||
local prosthesis_item = player_inventory:FindAndReturn(prosthesis_item_name)
|
||||
if prosthesis_item ~= nil then
|
||||
print("Resetting " .. prosthesis_item:getName())
|
||||
player:removeWornItem(prosthesis_item)
|
||||
player:getInventory():Remove(prosthesis_item)
|
||||
end
|
||||
prosthesis_item = nil -- reset it
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
player:transmitModData()
|
||||
|
||||
end
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
-- CutLimb
|
||||
-- TODO if TheONlyCure. triggers an errors
|
||||
function TocCheckIfStillInfected(part_data)
|
||||
if part_data == nil then
|
||||
function TocCheckIfStillInfected(limbs_data)
|
||||
if limbs_data == nil then
|
||||
return
|
||||
end
|
||||
-- Check ALL body part types to check if the player is still gonna die
|
||||
@@ -9,26 +8,26 @@ function TocCheckIfStillInfected(part_data)
|
||||
|
||||
|
||||
for _, v in ipairs(GetBodyParts()) do
|
||||
if part_data[v].is_infected then
|
||||
if limbs_data[v].is_infected then
|
||||
check = true
|
||||
end
|
||||
end
|
||||
|
||||
if part_data.is_other_bodypart_infected then
|
||||
if limbs_data.is_other_bodypart_infected then
|
||||
check = true
|
||||
end
|
||||
|
||||
return check
|
||||
end
|
||||
|
||||
function TocCureInfection(body_damage, part_data, part_name)
|
||||
function TocCureInfection(body_damage, limbs_data, part_name)
|
||||
|
||||
local body_part_type = body_damage:getBodyPart(TocGetBodyPartTypeFromPartName(part_name))
|
||||
|
||||
-- Check if we can heal the infection
|
||||
local is_other_bodypart_infected = getPlayer():getModData().TOC.Limbs.is_other_bodypart_infected
|
||||
|
||||
if not is_other_bodypart_infected and not TheOnlyCure.CheckIfOtherLimbsAreInfected(part_data, part_name) then
|
||||
if not is_other_bodypart_infected and not TheOnlyCure.CheckIfOtherLimbsAreInfected(limbs_data, part_name) then
|
||||
body_damage:setInfected(false)
|
||||
body_part_type:SetInfected(false)
|
||||
body_damage:setInfectionMortalityDuration(-1)
|
||||
@@ -91,14 +90,14 @@ function TocGetSawInInventory(surgeon)
|
||||
end
|
||||
|
||||
-- OperateLimb
|
||||
function SetBodyPartsStatusAfterOperation(player, part_data, part_name, use_oven)
|
||||
function SetBodyPartsStatusAfterOperation(player, limbs_data, part_name, use_oven)
|
||||
--for _, v in ipairs(GetBodyParts()) do
|
||||
|
||||
|
||||
local body_part_type = player:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromPartName(part_name))
|
||||
FixSingleBodyPartType(body_part_type, use_oven)
|
||||
|
||||
for _, v in ipairs(part_data[part_name].depends_on) do
|
||||
for _, v in ipairs(limbs_data[part_name].depends_on) do
|
||||
local depended_body_part_type = player:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromPartName(v))
|
||||
FixSingleBodyPartType(depended_body_part_type, use_oven)
|
||||
|
||||
@@ -125,7 +124,7 @@ end
|
||||
|
||||
-- Unequip Prosthesis
|
||||
|
||||
local function PartNameToBodyLocation(name)
|
||||
local function PartNameToBodyLocationProsthesis(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
|
||||
@@ -135,15 +134,25 @@ local function PartNameToBodyLocation(name)
|
||||
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 function PartNameToBodyLocationAmputation(name)
|
||||
-- This is still correct but naming sucks
|
||||
if name == "Right_Hand" then return "ArmRight" end
|
||||
if name == "Right_LowerArm" then return "ArmRight" end
|
||||
if name == "Right_UpperArm" then return "ArmRight" end
|
||||
if name == "Left_Hand" then return "ArmLeft" end
|
||||
if name == "Left_LowerArm" then return "ArmLeft" end
|
||||
if name == "Left_UpperArm" then return "ArmLeft" end
|
||||
end
|
||||
|
||||
function TocFindItemInProstBodyLocation(part_name, patient)
|
||||
-- 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
|
||||
if item:getBodyLocation() == PartNameToBodyLocationProsthesis(part_name) then
|
||||
return item
|
||||
end
|
||||
end
|
||||
@@ -151,6 +160,34 @@ function TocFindItemInProstBodyLocation(part_name, patient)
|
||||
end
|
||||
|
||||
|
||||
-- Debug cheat
|
||||
function TocFindAmputationOrProsthesisName(part_name, player, choice)
|
||||
local worn_items = player:getWornItems()
|
||||
for i = 1, worn_items:size() - 1 do
|
||||
local item = worn_items:get(i):getItem()
|
||||
|
||||
if choice == "Amputation" then
|
||||
|
||||
if item:getBodyLocation() == PartNameToBodyLocationAmputation(part_name) then
|
||||
return item:getFullType()
|
||||
|
||||
end
|
||||
|
||||
|
||||
elseif choice == "Prosthesis" then
|
||||
|
||||
if item:getBodyLocation() == PartNameToBodyLocationProsthesis(part_name) then
|
||||
return item:getFullType()
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------
|
||||
-- Override helper
|
||||
@@ -169,37 +206,6 @@ function CheckIfItemIsAmputatedLimb(item)
|
||||
|
||||
end
|
||||
|
||||
-- function CheckIfItemIsAmputatedLimb(item)
|
||||
|
||||
|
||||
-- local item_full_type = item:getFullType()
|
||||
|
||||
-- local sides = {"Left", "Right"}
|
||||
-- local limbs_to_check = {"Hand", "LowerArm", "UpperArm"}
|
||||
|
||||
-- local is_amputated_limb = false
|
||||
|
||||
-- for _, part in ipairs(limbs_to_check) do
|
||||
-- for _, side in ipairs(sides) do
|
||||
|
||||
-- local part_name = side .. "_" .. part
|
||||
|
||||
-- local check_name = "TOC.Amputation_" .. part_name
|
||||
-- print(check_name)
|
||||
-- if item_full_type == check_name then
|
||||
-- is_amputated_limb = true
|
||||
-- break
|
||||
-- end
|
||||
|
||||
-- end
|
||||
|
||||
-- end
|
||||
|
||||
|
||||
-- return is_amputated_limb
|
||||
|
||||
-- end
|
||||
|
||||
function CheckIfItemIsProsthesis(item)
|
||||
|
||||
-- TODO find a cleaner way
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
function TocCutLocal(_, player, part_name)
|
||||
if TocGetSawInInventory(player) ~= nil then
|
||||
ISTimedActionQueue.add(ISCutLimb:new(player, player, part_name));
|
||||
ISTimedActionQueue.add(ISCutLimb:new(player, player, part_name))
|
||||
else
|
||||
player:Say("I don't have a saw on me")
|
||||
end
|
||||
|
||||
@@ -31,10 +31,11 @@ end
|
||||
|
||||
------------------------------
|
||||
-- UI Visible stuff functions
|
||||
local function GetImageName(part_name, toc_data)
|
||||
local part_data = toc_data.Limbs[part_name]
|
||||
local function GetImageName(part_name, limbs_data)
|
||||
local name = ""
|
||||
|
||||
local part_data = limbs_data[part_name]
|
||||
|
||||
if part_data.is_cut and part_data.is_cicatrized and part_data.is_prosthesis_equipped then -- Cut and equip
|
||||
if part_name == "Right_Hand" or part_name == "Left_Hand" then
|
||||
name = "media/ui/TOC/" .. part_name .. "/Hook.png"
|
||||
@@ -59,9 +60,9 @@ local function GetImageName(part_name, toc_data)
|
||||
end
|
||||
|
||||
-- If foreaerm equip, change hand
|
||||
if part_name == "Right_Hand" and toc_data.Limbs["Right_LowerArm"].is_prosthesis_equipped then
|
||||
if part_name == "Right_Hand" and limbs_data["Right_LowerArm"].is_prosthesis_equipped then
|
||||
name = "media/ui/TOC/" .. part_name .. "/Hook.png"
|
||||
elseif part_name == "Left_Hand" and toc_data.Limbs["Left_LowerArm"].is_prosthesis_equipped then
|
||||
elseif part_name == "Left_Hand" and limbs_data["Left_LowerArm"].is_prosthesis_equipped then
|
||||
name = "media/ui/TOC/" .. part_name .. "/Hook.png"
|
||||
end
|
||||
return name
|
||||
@@ -137,7 +138,7 @@ local function OnClickTocMainUI(button, args)
|
||||
|
||||
desc_ui:open()
|
||||
desc_ui:setPositionPixel(main_ui:getRight(), main_ui:getY())
|
||||
SetupTocDescUI(main_ui.surgeon, main_ui.patient, args.toc_data, args.part_name) -- surgeon is generic.
|
||||
SetupTocDescUI(main_ui.surgeon, main_ui.patient, args.limbs_data, args.part_name) -- surgeon is generic.
|
||||
|
||||
end
|
||||
|
||||
@@ -351,42 +352,43 @@ end
|
||||
-----------------------------------------
|
||||
-- Setup stuff with variables and shit
|
||||
|
||||
function SetupTocMainUI(surgeon, patient, toc_data)
|
||||
function SetupTocMainUI(surgeon, patient, limbs_data)
|
||||
|
||||
-- TODO add a ontick to update it regularly
|
||||
|
||||
main_ui.surgeon = surgeon -- we shouldn't need an arg for this
|
||||
main_ui.patient = patient
|
||||
|
||||
if toc_data then
|
||||
main_ui["b11"]:addArg("toc_data", toc_data)
|
||||
main_ui["b12"]:addArg("toc_data", toc_data)
|
||||
main_ui["b21"]:addArg("toc_data", toc_data)
|
||||
main_ui["b22"]:addArg("toc_data", toc_data)
|
||||
main_ui["b31"]:addArg("toc_data", toc_data)
|
||||
main_ui["b32"]:addArg("toc_data", toc_data)
|
||||
if limbs_data then
|
||||
main_ui["b11"]:addArg("limbs_data", limbs_data)
|
||||
main_ui["b12"]:addArg("limbs_data", limbs_data)
|
||||
main_ui["b21"]:addArg("limbs_data", limbs_data)
|
||||
main_ui["b22"]:addArg("limbs_data", limbs_data)
|
||||
main_ui["b31"]:addArg("limbs_data", limbs_data)
|
||||
main_ui["b32"]:addArg("limbs_data", limbs_data)
|
||||
|
||||
main_ui["b11"]:setPath(GetImageName("Right_UpperArm", toc_data))
|
||||
main_ui["b12"]:setPath(GetImageName("Left_UpperArm", toc_data))
|
||||
main_ui["b11"]:setPath(GetImageName("Right_UpperArm", limbs_data))
|
||||
main_ui["b12"]:setPath(GetImageName("Left_UpperArm", limbs_data))
|
||||
|
||||
main_ui["b21"]:setPath(GetImageName("Right_LowerArm", toc_data))
|
||||
main_ui["b22"]:setPath(GetImageName("Left_LowerArm", toc_data))
|
||||
main_ui["b21"]:setPath(GetImageName("Right_LowerArm", limbs_data))
|
||||
main_ui["b22"]:setPath(GetImageName("Left_LowerArm", limbs_data))
|
||||
|
||||
main_ui["b31"]:setPath(GetImageName("Right_Hand", toc_data))
|
||||
main_ui["b32"]:setPath(GetImageName("Left_Hand", toc_data))
|
||||
main_ui["b31"]:setPath(GetImageName("Right_Hand", limbs_data))
|
||||
main_ui["b32"]:setPath(GetImageName("Left_Hand", limbs_data))
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
function SetupTocDescUI(surgeon, patient, toc_data, part_name)
|
||||
local part_data = toc_data.Limbs[part_name]
|
||||
function SetupTocDescUI(surgeon, patient, limbs_data, part_name)
|
||||
desc_ui["textTitle"]:setText(getText("UI_ContextMenu_" .. part_name))
|
||||
desc_ui.part_name = part_name
|
||||
desc_ui.surgeon = surgeon
|
||||
desc_ui.patient = patient
|
||||
|
||||
local part_data = limbs_data[part_name]
|
||||
|
||||
if IsProsthesisInstalled(part_data) then
|
||||
-- Limb cut with prosthesis
|
||||
desc_ui["status"]:setText("Prosthesis equipped")
|
||||
@@ -449,16 +451,16 @@ function SetupTocDescUI(surgeon, patient, toc_data, part_name)
|
||||
desc_ui["status"]:setText("Nothing here")
|
||||
desc_ui["status"]:setColor(1, 1, 1, 1)
|
||||
desc_ui["b1"]:setVisible(false)
|
||||
elseif CheckIfCanBeCut(part_name) then
|
||||
elseif CheckIfCanBeCut(part_name, limbs_data) then
|
||||
-- Everything else
|
||||
-- TODO add check for cuts and scratches
|
||||
desc_ui["status"]:setText("Not cut")
|
||||
desc_ui["status"]:setColor(1, 1, 1, 1)
|
||||
if TocGetSawInInventory(surgeon) and not CheckIfProsthesisAlreadyInstalled(toc_data.Limbs, part_name) then
|
||||
if TocGetSawInInventory(surgeon) and not CheckIfProsthesisAlreadyInstalled(limbs_data, part_name) then
|
||||
desc_ui["b1"]:setVisible(true)
|
||||
desc_ui["b1"]:setText("Cut")
|
||||
desc_ui["b1"]:addArg("option", "Cut")
|
||||
elseif TocGetSawInInventory(surgeon) and CheckIfProsthesisAlreadyInstalled(toc_data.Limbs, part_name) then
|
||||
elseif TocGetSawInInventory(surgeon) and CheckIfProsthesisAlreadyInstalled(limbs_data, part_name) then
|
||||
desc_ui["b1"]:setVisible(true)
|
||||
desc_ui["b1"]:setText("Remove prosthesis before")
|
||||
desc_ui["b1"]:addArg("option", "Nothing")
|
||||
@@ -547,20 +549,30 @@ function ISNewHealthPanel.onClick_TOC(button)
|
||||
|
||||
if surgeon then
|
||||
if surgeon == patient then
|
||||
SetupTocMainUI(surgeon, surgeon, surgeon:getModData().TOC)
|
||||
SetupTocMainUI(surgeon, surgeon, surgeon:getModData().TOC.Limbs)
|
||||
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() })
|
||||
print("TOC: Checking part_data for " .. patient:getUsername())
|
||||
if ModData.get("TOC_PLAYER_DATA")[patient:getUsername()] ~= nil then
|
||||
local other_player_part_data = ModData.get("TOC_PLAYER_DATA")[patient:getUsername()]
|
||||
|
||||
TocTempTable.TempPatient = patient
|
||||
TocTempTable.TempSurgeon = surgeon
|
||||
SetupTocMainUI(surgeon, patient, other_player_part_data[1])
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
--sendClientCommand(surgeon, "TOC", "GetPlayerData", { surgeon:getOnlineID(), patient:getOnlineID() })
|
||||
|
||||
--TocTempTable.TempPatient = patient
|
||||
--TocTempTable.TempSurgeon = surgeon
|
||||
|
||||
-- Wait for ack
|
||||
Events.OnTick.Add(TocWaitForOnlinePlayerData)
|
||||
--Events.OnTick.Add(TocWaitForOnlinePlayerData)
|
||||
end
|
||||
else
|
||||
-- This is when surgeon doesnt exist for some reason.
|
||||
SetupTocMainUI(patient, patient, patient:getModData().TOC)
|
||||
SetupTocMainUI(patient, patient, patient:getModData().TOC.Limbs)
|
||||
end
|
||||
|
||||
main_ui:toggle()
|
||||
@@ -587,12 +599,11 @@ end
|
||||
function ISHealthPanel:createChildren()
|
||||
ISHealthPanel_createChildren(self)
|
||||
|
||||
self.fitness:setWidth(self.fitness:getWidth() / 1.5)
|
||||
--self.fitness:setWidth(self.fitness:getWidth() / 1.5)
|
||||
|
||||
--TODO make it bigger
|
||||
self.TOCButton = ISButton:new(self.fitness:getRight(), self.healthPanel.y, 20, 20, "", self,
|
||||
self.TOCButton = ISButton:new(self.fitness:getRight() + 25, self.healthPanel.y, 70, 20, "The Only Cure", self,
|
||||
ISNewHealthPanel.onClick_TOC)
|
||||
self.TOCButton:setImage(getTexture("media/ui/TOC/iconForMenu.png"))
|
||||
--self.TOCButton:setImage(getTexture("media/ui/TOC/iconForMenu.png"))
|
||||
self.TOCButton.anchorTop = false
|
||||
self.TOCButton.anchorBottom = true
|
||||
self.TOCButton:initialise()
|
||||
|
||||
@@ -26,7 +26,6 @@ function TheOnlyCure.CheckIfPlayerIsInfected(player, toc_data)
|
||||
if body_damage:getBodyPart(v):bitten() and part_data ~= nil then
|
||||
if part_data.is_cut == false then
|
||||
part_data.is_infected = true
|
||||
player:transmitModData()
|
||||
end
|
||||
|
||||
end
|
||||
@@ -35,7 +34,6 @@ function TheOnlyCure.CheckIfPlayerIsInfected(player, toc_data)
|
||||
for _, v in ipairs(GetOtherBodyPartTypes()) do
|
||||
if body_damage:getBodyPart(v):bitten() then
|
||||
toc_data.Limbs.is_other_bodypart_infected = true -- Even one is enough, stop cycling if we find it
|
||||
player:transmitModData()
|
||||
break
|
||||
end
|
||||
end
|
||||
@@ -55,7 +53,6 @@ function TheOnlyCure.UpdatePlayerHealth(player, part_data)
|
||||
end
|
||||
end
|
||||
|
||||
player:transmitModData()
|
||||
|
||||
|
||||
end
|
||||
@@ -128,14 +125,14 @@ function TheOnlyCure.SetHealthStatusForBodyPart(part_data, part_name, player)
|
||||
end
|
||||
|
||||
--Helper function for UpdatePlayerHealth
|
||||
function TheOnlyCure.CheckIfOtherLimbsAreInfected(part_data, part_name)
|
||||
function TheOnlyCure.CheckIfOtherLimbsAreInfected(limbs_data, part_name)
|
||||
|
||||
|
||||
local body_parts = GetBodyParts()
|
||||
body_parts[part_name] = nil
|
||||
|
||||
for _, v in pairs(body_parts) do
|
||||
if part_data[v].is_infected then
|
||||
if limbs_data[v].is_infected then
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -159,6 +156,15 @@ function TheOnlyCure.UpdateEveryOneMinute()
|
||||
TheOnlyCure.UpdatePlayerHealth(player, toc_data.Limbs)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- Updates toc data in a global way, basically player:transmitModData but it works
|
||||
-- Sends only Limbs since the other stuff is mostly static
|
||||
if toc_data ~= nil then
|
||||
sendClientCommand(player, 'TOC', 'ChangePlayerState', { toc_data.Limbs } )
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
function TheOnlyCure.UpdateEveryTenMinutes()
|
||||
@@ -183,8 +189,6 @@ function TheOnlyCure.UpdateEveryTenMinutes()
|
||||
for _, part_name in pairs(GetBodyParts()) do
|
||||
if part_data[part_name].is_cut and not part_data[part_name].is_cicatrized then
|
||||
part_data[part_name].cicatrization_time = part_data[part_name].cicatrization_time - 1 -- TODO Make it more "dynamic"
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -228,7 +228,7 @@ function TheOnlyCure.CutLimb(part_name, surgeon_factor, bandage_table, painkille
|
||||
|
||||
local player = getPlayer()
|
||||
local toc_data = player:getModData().TOC
|
||||
local part_data = toc_data.Limbs
|
||||
local limbs_data = toc_data.Limbs
|
||||
|
||||
local body_part = player:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromPartName(part_name))
|
||||
local stats = player:getStats()
|
||||
@@ -261,21 +261,21 @@ function TheOnlyCure.CutLimb(part_name, surgeon_factor, bandage_table, painkille
|
||||
-- Use a tourniquet if available
|
||||
-- TODO add tourniquet
|
||||
|
||||
if part_data[part_name].is_cut == false then
|
||||
part_data[part_name].is_cut = true
|
||||
part_data[part_name].is_amputation_shown = true
|
||||
part_data[part_name].cicatrization_time = part_data[part_name].cicatrization_base_time - surgeon_factor * 50
|
||||
if limbs_data[part_name].is_cut == false then
|
||||
limbs_data[part_name].is_cut = true
|
||||
limbs_data[part_name].is_amputation_shown = true
|
||||
limbs_data[part_name].cicatrization_time = limbs_data[part_name].cicatrization_base_time - surgeon_factor * 50
|
||||
|
||||
-- Heal the infection here
|
||||
local body_damage = player:getBodyDamage()
|
||||
if part_data[part_name].is_infected and body_damage:getInfectionLevel() < 20 then
|
||||
part_data[part_name].is_infected = false
|
||||
if limbs_data[part_name].is_infected and body_damage:getInfectionLevel() < 20 then
|
||||
limbs_data[part_name].is_infected = false
|
||||
body_part:SetBitten(false)
|
||||
body_part:setBiteTime(0)
|
||||
|
||||
-- Second check, let's see if there is any other infected limb.
|
||||
if TocCheckIfStillInfected(part_data) == false then
|
||||
TocCureInfection(body_damage, part_data, part_name)
|
||||
if TocCheckIfStillInfected(limbs_data) == false then
|
||||
TocCureInfection(body_damage, limbs_data, part_name)
|
||||
getPlayer():Say("I'm gonna be fine...")
|
||||
else
|
||||
getPlayer():Say("I'm still gonna die...")
|
||||
@@ -283,14 +283,13 @@ function TheOnlyCure.CutLimb(part_name, surgeon_factor, bandage_table, painkille
|
||||
end
|
||||
|
||||
-- Cut the depended part
|
||||
for _, depended_v in pairs(part_data[part_name].depends_on) do
|
||||
part_data[depended_v].is_cut = true
|
||||
part_data[depended_v].is_amputation_shown = false
|
||||
part_data[depended_v].cicatrization_time = part_data[part_name].cicatrization_base_time - surgeon_factor * 50
|
||||
for _, depended_v in pairs(limbs_data[part_name].depends_on) do
|
||||
limbs_data[depended_v].is_cut = true
|
||||
limbs_data[depended_v].is_amputation_shown = false
|
||||
limbs_data[depended_v].cicatrization_time = limbs_data[part_name].cicatrization_base_time -
|
||||
surgeon_factor * 50
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- Check for older amputation models and deletes them from player's inventory
|
||||
local side = string.match(part_name, '(%w+)_')
|
||||
TocDeleteOtherAmputatedLimbs(side)
|
||||
@@ -303,9 +302,6 @@ function TheOnlyCure.CutLimb(part_name, surgeon_factor, bandage_table, painkille
|
||||
|
||||
-- Set blood on the amputated limb
|
||||
TocSetBloodOnAmputation(getPlayer(), body_part)
|
||||
|
||||
player:transmitModData()
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -316,7 +312,7 @@ end
|
||||
function TheOnlyCure.OperateLimb(part_name, surgeon_factor, use_oven)
|
||||
|
||||
local player = getPlayer()
|
||||
local part_data = player:getModData().TOC.Limbs
|
||||
local limbs_data = player:getModData().TOC.Limbs
|
||||
|
||||
if use_oven then
|
||||
local stats = player:getStats()
|
||||
@@ -324,21 +320,21 @@ function TheOnlyCure.OperateLimb(part_name, surgeon_factor, use_oven)
|
||||
stats:setStress(100)
|
||||
end
|
||||
|
||||
if part_data[part_name].is_operated == false and part_data[part_name].is_cut == true then
|
||||
part_data[part_name].is_operated = true
|
||||
part_data[part_name].cicatrization_time = part_data[part_name].cicatrization_time - (surgeon_factor * 200)
|
||||
if use_oven then part_data[part_name].is_cauterized = true end
|
||||
for _, depended_v in pairs(part_data[part_name].depends_on) do
|
||||
part_data[depended_v].is_operated = true
|
||||
part_data[depended_v].cicatrization_time = part_data[depended_v].cicatrization_time - (surgeon_factor * 200)
|
||||
if use_oven then part_data[depended_v].is_cauterized = true end -- TODO does this make sense?
|
||||
if limbs_data[part_name].is_operated == false and limbs_data[part_name].is_cut == true then
|
||||
limbs_data[part_name].is_operated = true
|
||||
limbs_data[part_name].cicatrization_time = limbs_data[part_name].cicatrization_time - (surgeon_factor * 200)
|
||||
if use_oven then limbs_data[part_name].is_cauterized = true end
|
||||
for _, depended_v in pairs(limbs_data[part_name].depends_on) do
|
||||
limbs_data[depended_v].is_operated = true
|
||||
limbs_data[depended_v].cicatrization_time = limbs_data[depended_v].cicatrization_time -
|
||||
(surgeon_factor * 200)
|
||||
if use_oven then limbs_data[depended_v].is_cauterized = true end -- TODO does this make sense?
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
SetBodyPartsStatusAfterOperation(player, part_data, part_name, use_oven)
|
||||
player:transmitModData()
|
||||
SetBodyPartsStatusAfterOperation(player, limbs_data, part_name, use_oven)
|
||||
end
|
||||
|
||||
function TheOnlyCure.EquipProsthesis(part_name, prosthesis_base_name)
|
||||
@@ -382,11 +378,8 @@ function TheOnlyCure.UnequipProsthesis(part_name, equipped_prosthesis)
|
||||
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()
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -411,18 +404,17 @@ function TryTocAction(_, part_name, action, surgeon, patient)
|
||||
TocUnequipProsthesisLocal(_, surgeon, part_name)
|
||||
end
|
||||
else
|
||||
|
||||
local ui = GetConfirmUIMP()
|
||||
if not ui then
|
||||
CreateTocConfirmUIMP()
|
||||
ui = GetConfirmUIMP()
|
||||
end
|
||||
|
||||
|
||||
if patient == nil then
|
||||
patient = surgeon
|
||||
end
|
||||
|
||||
|
||||
if action == "Cut" then
|
||||
AskCanCutLimb(patient, part_name)
|
||||
elseif action == "Operate" then
|
||||
@@ -432,11 +424,11 @@ function TryTocAction(_, part_name, action, surgeon, patient)
|
||||
elseif action == "Unequip" then
|
||||
AskCanUnequipProsthesis(patient, part_name)
|
||||
end
|
||||
|
||||
ui.actionAct = action
|
||||
ui.partNameAct = part_name
|
||||
ui.patient = patient
|
||||
|
||||
|
||||
SendCommandToConfirmUIMP("Wait server")
|
||||
|
||||
end
|
||||
|
||||
@@ -58,7 +58,6 @@ function ISInstallProsthesis:perform()
|
||||
TheOnlyCure.EquipProsthesis(self.part_name, prosthesis_base_name)
|
||||
|
||||
end
|
||||
self.character:transmitModData()
|
||||
|
||||
-- needed to remove from queue / start next.
|
||||
ISBaseTimedAction.perform(self)
|
||||
|
||||
@@ -57,7 +57,6 @@ function ISUninstallProsthesis:perform()
|
||||
else
|
||||
TheOnlyCure.UnequipProsthesis(self.part_name, self.item)
|
||||
end
|
||||
self.character:transmitModData()
|
||||
|
||||
|
||||
ISBaseTimedAction.perform(self)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
--- A rly big thx to Fenris_Wolf and Chuck to help me with that. Love you guy
|
||||
--if isClient() then return end
|
||||
|
||||
|
||||
---Server side
|
||||
local Commands = {}
|
||||
local TOC_Commands = {}
|
||||
|
||||
|
||||
--TODO how does this work
|
||||
Commands["SendServer"] = function(player, arg)
|
||||
TOC_Commands["SendServer"] = function(player, arg)
|
||||
local otherPlayer = getPlayerByOnlineID(arg["To"])
|
||||
print("The Only Cure Command: ", arg['command'])
|
||||
sendServerCommand(otherPlayer, "TOC", arg["command"], arg)
|
||||
@@ -14,14 +14,14 @@ end
|
||||
|
||||
|
||||
-- To make the UI Work
|
||||
Commands["GetPlayerData"] = function(_, arg)
|
||||
TOC_Commands["GetPlayerData"] = function(_, arg)
|
||||
local surgeon_id = arg[1]
|
||||
local patient_id = arg[2]
|
||||
local patient = getPlayerByOnlineID(arg[2])
|
||||
sendServerCommand(patient, "TOC", "GivePlayerData", { surgeon_id, patient_id })
|
||||
end
|
||||
|
||||
Commands["SendPlayerData"] = function(_, arg)
|
||||
TOC_Commands["SendPlayerData"] = function(_, arg)
|
||||
local surgeon = getPlayerByOnlineID(arg[1])
|
||||
local surgeon_id = arg[1]
|
||||
local toc_data = arg[2]
|
||||
@@ -31,7 +31,7 @@ end
|
||||
|
||||
|
||||
-- CHEATING STUFF
|
||||
Commands["AskToResetEverything"] = function(_, arg)
|
||||
TOC_Commands["AskToResetEverything"] = function(_, arg)
|
||||
local clicked_player = getPlayerByOnlineID(arg[1])
|
||||
local clicked_player_id = arg[1]
|
||||
|
||||
@@ -40,15 +40,25 @@ Commands["AskToResetEverything"] = function(_, arg)
|
||||
|
||||
end
|
||||
|
||||
local function OnTocClientCommand(module, command, player, args)
|
||||
if module == 'TOC' then
|
||||
print("OnTocClientCommand " .. command)
|
||||
if Commands[command] then
|
||||
args = args or {}
|
||||
Commands[command](_, args)
|
||||
end
|
||||
end
|
||||
------ Global Mod Data -----------
|
||||
|
||||
function TOC_OnInitGlobalModData()
|
||||
ModData.getOrCreate("TOC_PLAYER_DATA")
|
||||
end
|
||||
|
||||
Events.OnClientCommand.Add(OnTocClientCommand)
|
||||
Events.OnInitGlobalModData.Add(TOC_OnInitGlobalModData)
|
||||
|
||||
TOC_Commands.OnClientCommand = function(module, command, playerObj, args)
|
||||
if module == 'TOC' and TOC_Commands[command] then
|
||||
TOC_Commands[command](playerObj, args)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Events.OnClientCommand.Add(TOC_Commands.OnClientCommand)
|
||||
|
||||
|
||||
TOC_Commands.ChangePlayerState = function(playerObj, args)
|
||||
ModData.get("TOC_PLAYER_DATA")[playerObj:getUsername()] = args
|
||||
ModData.transmit("TOC_PLAYER_DATA")
|
||||
end
|
||||
Reference in New Issue
Block a user