Too much stuff to fix.

This commit is contained in:
ZioPao
2024-03-29 18:46:44 +01:00
parent 883a84412b
commit d73b1a3f43
13 changed files with 120 additions and 28 deletions

View File

@@ -30,6 +30,14 @@ function ClientRelayCommands.ReceiveExecuteAmputationAction(args)
end
--* APPLY RELAY *--
function ClientRelayCommands.ReceiveApplyFromServer()
TOC_DEBUG.print("Received forced re-apply from server")
local key = CommandsData.GetKey(getPlayer():getUsername())
ModData.request(key)
end
--* TRIGGERED BY ADMINS *--

View File

@@ -78,8 +78,8 @@ function DataController:setup(key)
end
-- Initialize prostheses stuff
for i=1, #StaticData.PROSTHESES_GROUPS_STR do
local group = StaticData.PROSTHESES_GROUPS_STR[i]
for i=1, #StaticData.AMP_GROUPS_STR do
local group = StaticData.AMP_GROUPS_STR[i]
self.tocData.prostheses[group] = {
isProstEquipped = false,
prostFactor = 0,
@@ -103,7 +103,7 @@ end
function DataController:loadLocalData(key)
self.tocData = ModData.get(key)
TOC_DEBUG.printTable(self.tocData)
--TOC_DEBUG.printTable(self.tocData)
if self.tocData and self.tocData.limbs then
TOC_DEBUG.print("Found and loaded local data")
@@ -345,13 +345,19 @@ end
--* Global Mod Data Handling *--
function DataController:apply()
TOC_DEBUG.print("Applying data for " .. self.username)
ModData.transmit(CommandsData.GetKey(self.username))
-- if getPlayer():getUsername() ~= self.username then
-- sendClientCommand(CommandsData.modules.TOC_RELAY, CommandsData.server.Relay.RelayApplyFromOtherClient, {patientUsername = self.username} )
-- -- force request from the server for that other client...
-- end
end
---Online only, Global Mod Data doesn't trigger this in SP
---@param key any
---@param data any
---@param key string
---@param data tocModDataType
function DataController.ReceiveData(key, data)
-- During startup the game can return Bob as the player username, adding a useless ModData table
if key == "TOC_Bob" then return end
@@ -370,25 +376,47 @@ function DataController.ReceiveData(key, data)
-- so for now, I'm gonna assume that the local data (for the local client) is the
-- most recent (and correct) one instead of trying to fetch it from the server every single time
if username == getPlayer():getUsername() and not handler.isResetForced then
handler:loadLocalData(key)
elseif handler.isResetForced or data == nil then
TOC_DEBUG.print("Data is nil or empty!?")
TOC_DEBUG.printTable(data)
-- TODO Add update from server scenario
if handler.isResetForced then
handler:setup(key)
elseif data and data.limbs then
elseif data then
if data.isUpdateFromServer then
TOC_DEBUG.print("Update from the server")
end
handler:applyOnlineData(data)
elseif username == getPlayer():getUsername() then
handler:loadLocalData(key)
end
handler:setIsResetForced(false)
handler:setIsDataReady(true)
-- Event, triggers caching
triggerEvent("OnReceivedTocData", handler.username)
-- if username == getPlayer():getUsername() and not handler.isResetForced then
-- handler:loadLocalData(key)
-- elseif handler.isResetForced or data == nil then
-- TOC_DEBUG.print("Data is nil or empty!?")
-- TOC_DEBUG.printTable(data)
-- handler:setup(key)
-- elseif data and data.limbs then
-- handler:applyOnlineData(data)
-- end
-- handler:setIsResetForced(false)
-- handler:setIsDataReady(true)
-- -- Event, triggers caching
-- triggerEvent("OnReceivedTocData", handler.username)
-- Transmit it back to the server
ModData.transmit(key)
TOC_DEBUG.print("Transmitting data after receiving it for: " .. handler.username)
--ModData.transmit(key)
--TOC_DEBUG.print("Transmitting data after receiving it for: " .. handler.username)
end

View File

@@ -22,7 +22,11 @@ end
---Will calculate all the values that we need
function CachedDataHandler.CalculateCacheableValues(username)
CachedDataHandler.CalculateHighestAmputatedLimbs(username)
CachedDataHandler.CalculateBothHandsFeasibility()
-- FIX This should be run ONLY on the actual client, never on other clients. Just a placeholder fix for now
if getPlayer():getUsername() == username then
CachedDataHandler.CalculateBothHandsFeasibility()
end
end

View File

@@ -25,8 +25,10 @@ function CleanWoundAction:new(doctor, otherPlayer, bandage, bodyPart)
o.bandage = bandage
o.stopOnWalk = true
o.stopOnRun = true
o.bandagedPlayerX = otherPlayer:getX()
o.bandagedPlayerY = otherPlayer:getY()
o.maxTime = 250 - (o.doctorLevel * 6)
if doctor:isTimedActionInstant() then
o.maxTime = 1
@@ -79,8 +81,8 @@ function CleanWoundAction:stop()
end
function CleanWoundAction:perform()
-- needed to remove from queue / start next.
ISBaseTimedAction.perform(self)
TOC_DEBUG.print("CleanWound for " .. self.otherPlayer:getUsername())
if self.character:HasTrait("Hemophobic") then
self.character:getStats():setPanic(self.character:getStats():getPanic() + 15)
@@ -113,6 +115,9 @@ function CleanWoundAction:perform()
visual:setBlood(bbptEnum, 0)
ISHealthPanel.setBodyPartActionForPlayer(self.otherPlayer, self.bodyPart, nil, nil, nil)
-- needed to remove from queue / start next.
ISBaseTimedAction.perform(self)
end
return CleanWoundAction

View File

@@ -7,6 +7,8 @@ local CommandsData = require("TOC/CommandsData")
---@class CutLimbAction : ISBaseTimedAction
---@field patient IsoPlayer
---@field character IsoPlayer
---@field patientX number
---@field patientY number
---@field limbName string
---@field item InventoryItem
---@field stitchesItem InventoryItem?
@@ -32,6 +34,9 @@ function CutLimbAction:new(surgeon, patient, limbName, item, stitchesItem, banda
o.limbName = limbName
o.item = item
o.patientX = patient:getX()
o.patientY = patient:getY()
o.stitchesItem = stitchesItem or nil
o.bandageItem = bandageItem or nil
@@ -45,7 +50,7 @@ function CutLimbAction:new(surgeon, patient, limbName, item, stitchesItem, banda
end
function CutLimbAction:isValid()
return not ISHealthPanel.DidPatientMove(self.patient, self.character, self.patient:getX(), self.patient:getY())
return not ISHealthPanel.DidPatientMove(self.character,self.patient, self.patientX, self.patientY)
end
function CutLimbAction:start()

View File

@@ -133,13 +133,15 @@ function ISHealthPanel:update()
og_ISHealthPanel_update(self)
-- TODO Listen for changes on other player side instead of looping this
-- FIX Re-enable it, just for test
if self.character then
local locPlUsername = getPlayer():getUsername()
local remPlUsername = self.character:getUsername()
if locPlUsername ~= remPlUsername and self:isReallyVisible() then
-- Request update for TOC DATA?
-- Request update for TOC DATA
local key = CommandsData.GetKey(remPlUsername)
ModData.request(key)
--ModData.request(key)
end
end
end

View File

@@ -208,7 +208,8 @@ end
function CutLimbInteractionHandler:addToMenu(context)
--TOC_DEBUG.print("CutLimbInteractionHandler addToMenu")
local types = self:getAllItemTypes(self.items.ITEMS)
if #types > 0 and StaticData.BODYLOCS_IND_BPT[self.limbName] and not DataController.GetInstance():getIsCut(self.limbName) then
local patientUsername = self:getPatient():getUsername()
if #types > 0 and StaticData.BODYLOCS_IND_BPT[self.limbName] and not DataController.GetInstance(patientUsername):getIsCut(self.limbName) then
TOC_DEBUG.print("addToMenu, types > 0")
for i=1, #types do
context:addOption(getText("ContextMenu_Amputate"), self, self.onMenuOptionSelected, types[i])
@@ -230,7 +231,8 @@ end
function CutLimbInteractionHandler:isValid()
--TOC_DEBUG.print("CutLimbInteractionHandler isValid")
self:checkItems()
return not DataController.GetInstance():getIsCut(self.limbName)
local patientUsername = self:getPatient():getUsername()
return not DataController.GetInstance(patientUsername):getIsCut(self.limbName)
end
function CutLimbInteractionHandler:perform(previousAction, itemType)

View File

@@ -126,10 +126,12 @@ function BaseHandler:toPlayerInventory(item, previousAction)
return previousAction
end
---@return IsoPlayer
function BaseHandler:getDoctor()
return self.panel.otherPlayer or self.panel.character
end
---@return IsoPlayer
function BaseHandler:getPatient()
return self.panel.character
end

View File

@@ -35,6 +35,7 @@ end
function WoundCleaningInteractionHandler:addToMenu(context)
--TOC_DEBUG.print("WoundCleaningInteraction addToMenu")
local types = self:getAllItemTypes(self.items.ITEMS)
if #types > 0 and self:isValid() then
TOC_DEBUG.print("WoundCleaningInteraction inside addToMenu")