Reworked some stuff for MP

This commit is contained in:
ZioPao
2023-11-12 22:20:46 +01:00
parent f973b774a2
commit 4887699892
13 changed files with 209 additions and 91 deletions

View File

@@ -2,6 +2,7 @@ local PlayerHandler = require("TOC/Handlers/PlayerHandler")
local StaticData = require("TOC/StaticData")
local CommonMethods = require("TOC/CommonMethods")
local ModDataHandler = require("TOC/Handlers/ModDataHandler")
local CommandsData = require("TOC/CommandsData")
---@diagnostic disable: duplicate-set-field
local CutLimbHandler = require("TOC/UI/CutLimbInteractions")
@@ -44,23 +45,35 @@ end
--* Modification to handle visible amputation on the health menu *--
function ISHealthPanel:setHighestAmputation()
--TOC_DEBUG.print("setHighestAmputation")
if PlayerHandler.amputatedLimbs == nil or PlayerHandler.amputatedLimbs[self.tocUsername] then
TOC_DEBUG.print("PlayerHandler.amputatedLimbs is still nil or wasn't initialized for that player")
return
end
if self.otherPlayer ~= nil then
self.tocUsername = self.otherPlayer:getUsername()
else
self.tocUsername = self.character:getUsername()
end
ISHealthPanel.highestAmputations[self.tocUsername] = {}
self.highestAmputations[self.tocUsername] = {}
TOC_DEBUG.print("Searching highest amputations for " .. self.tocUsername)
local modDataHandler = ModDataHandler.GetInstance(self.tocUsername)
if modDataHandler == nil then return end -- TODO Test this
if modDataHandler == nil then
TOC_DEBUG.print("ModDataHandler not found for " .. self.tocUsername)
return
end
for i=1, #PlayerHandler.amputatedLimbs do
local limbName = PlayerHandler.amputatedLimbs[i]
local index = CommonMethods.GetSide(limbName)
if modDataHandler:getIsCut(limbName) and modDataHandler:getIsVisible(limbName) then
ISHealthPanel.highestAmputations[index] = limbName
TOC_DEBUG.print("found high amputation " .. limbName)
self.highestAmputations[self.tocUsername][index] = limbName
end
end
end
@@ -73,6 +86,7 @@ function ISHealthPanel:initialise()
self.sexPl = "Male"
end
self.highestAmputations = {}
self:setHighestAmputation()
og_ISHealthPanel_initialise(self)
@@ -87,6 +101,12 @@ function ISHealthPanel:setOtherPlayer(playerObj)
-- Since setOtherPlayer may be run after initialise (or always), we need to recheck it after.
self:setHighestAmputation()
-- TODO Request from server!
-----@type askPlayerDataParams
--local params = {patientNum = playerObj:getOnlineID()}
--sendClientCommand(CommandsData.modules.TOC_SYNC, CommandsData.server.Sync.AskPlayerData, params)
end
@@ -96,20 +116,21 @@ function ISHealthPanel:render()
-- TODO Handle another player health panel
if ISHealthPanel.highestAmputations[self.tocUsername] then
if self.highestAmputations ~= nil and self.highestAmputations[self.tocUsername] ~= nil then
-- Left Texture
if ISHealthPanel.highestAmputations[self.tocUsername]["L"] then
local textureL = StaticData.HEALTH_PANEL_TEXTURES[self.sexPl][ISHealthPanel.highestAmputations["L"]]
if self.highestAmputations[self.tocUsername]["L"] then
local textureL = StaticData.HEALTH_PANEL_TEXTURES[self.sexPl][self.highestAmputations[self.tocUsername]["L"]]
self:drawTexture(textureL, self.healthPanel.x/2 - 2, self.healthPanel.y/2, 1, 1, 0, 0)
end
-- Right Texture
if ISHealthPanel.highestAmputations[self.tocUsername]["R"] then
local textureR = StaticData.HEALTH_PANEL_TEXTURES[self.sexPl][ISHealthPanel.highestAmputations["R"]]
if self.highestAmputations["R"] then
local textureR = StaticData.HEALTH_PANEL_TEXTURES[self.sexPl][self.highestAmputations[self.tocUsername]["R"]]
self:drawTexture(textureR, self.healthPanel.x/2 + 2, self.healthPanel.y/2, 1, 1, 0, 0)
end
else
ISHealthPanel.GetHighestAmputation(self.tocUsername)
self:setHighestAmputation()
--ISHealthPanel.GetHighestAmputation(self.tocUsername)
end
end