Reworked some stuff for MP
This commit is contained in:
@@ -76,7 +76,10 @@ function AmputationHandler:execute(damagePlayer)
|
||||
|
||||
|
||||
-- Set the data in modData
|
||||
ModDataHandler.GetInstance():setCutLimb(self.limbName, false, false, false, surgeonFactor)
|
||||
-- TODO This could be run on another player!
|
||||
local modDataHandler = ModDataHandler.GetInstance()
|
||||
modDataHandler:setCutLimb(self.limbName, false, false, false, surgeonFactor)
|
||||
modDataHandler:apply()
|
||||
|
||||
-- Give the player the correct amputation item
|
||||
ItemsHandler.DeleteOldAmputationItem(self.patient, self.limbName)
|
||||
@@ -86,7 +89,7 @@ function AmputationHandler:execute(damagePlayer)
|
||||
PlayerHandler.AddLocalAmputatedLimb(self.limbName)
|
||||
|
||||
-- Set the highest amputation and caches them.
|
||||
ISHealthPanel.GetHighestAmputation()
|
||||
--ISHealthPanel.GetHighestAmputation()
|
||||
end
|
||||
|
||||
---Deletes the instance
|
||||
@@ -98,7 +101,7 @@ end
|
||||
function AmputationHandler.UpdateCicatrization()
|
||||
if ModDataHandler.GetInstance():getIsAnyLimbCut() == false then return end
|
||||
|
||||
|
||||
-- TODO Update cicatrization
|
||||
end
|
||||
|
||||
return AmputationHandler
|
||||
@@ -109,7 +109,7 @@ function ISInventoryPane:refreshContainer()
|
||||
for i=1, #self.itemslist do
|
||||
local cItem = self.itemslist[i]
|
||||
if cItem and cItem.cat == "Amputation" then
|
||||
TOC_DEBUG.print("current item is an amputation, removing it from the list")
|
||||
TOC_DEBUG.print("Refreshing container - current item is an amputation, removing it from the list of the container")
|
||||
table.remove(self.itemslist, i)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,35 +1,67 @@
|
||||
local CommandsData = require("TOC/CommandsData")
|
||||
local StaticData = require("TOC/StaticData")
|
||||
|
||||
----------------
|
||||
|
||||
--- Handle all mod data related stuff
|
||||
---@class ModDataHandler
|
||||
---@field playerObj IsoPlayer
|
||||
---@field username string
|
||||
---@field tocData tocModData
|
||||
local ModDataHandler = {}
|
||||
ModDataHandler.instances = {}
|
||||
|
||||
|
||||
function ModDataHandler.AddExternalTocData(username, tocData)
|
||||
|
||||
end
|
||||
|
||||
-- Instead of requiring a player, to make it compatible in a MP env, we should require the table containing the modData for the init
|
||||
|
||||
---@param username string
|
||||
---@param tocData tocModData
|
||||
---@param isResetForced boolean?
|
||||
---@return ModDataHandler
|
||||
function ModDataHandler:new(username, tocData)
|
||||
function ModDataHandler:new(username, isResetForced)
|
||||
local o = {}
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
-- Instead of requiring a player, to make it compatible in a MP env, we should require the table containing the modData for the init
|
||||
o.username = username
|
||||
local key = CommandsData.GetKey(username)
|
||||
|
||||
ModData.request(key)
|
||||
o.tocData = ModData.get(key)
|
||||
|
||||
if isResetForced or o.tocData == nil or o.tocData.Hand_L == nil or o.tocData.Hand_L.isCut == nil then
|
||||
TOC_DEBUG.print("tocData in ModDataHandler for " .. username .. " is nil, creating it now")
|
||||
self:setup(key)
|
||||
end
|
||||
|
||||
o.tocData = tocData
|
||||
ModDataHandler.instances[username] = o
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
---Setup a new toc mod data data class
|
||||
---@param key string
|
||||
function ModDataHandler:setup(key)
|
||||
|
||||
---@type tocModData
|
||||
self.tocData = {
|
||||
-- Generic stuff that does not belong anywhere else
|
||||
isIgnoredPartInfected = false,
|
||||
isAnyLimbCut = false
|
||||
}
|
||||
|
||||
---@type partData
|
||||
local defaultParams = {isCut = false, isInfected = false, isOperated = false, isCicatrized = false, isCauterized = false, isVisible = false}
|
||||
|
||||
-- Initialize limbs
|
||||
for i=1, #StaticData.LIMBS_STRINGS do
|
||||
local limbName = StaticData.LIMBS_STRINGS[i]
|
||||
self.tocData[limbName] = {}
|
||||
self:setLimbParams(StaticData.LIMBS_STRINGS[i], defaultParams, 0)
|
||||
end
|
||||
|
||||
-- Add it to global mod data
|
||||
ModData.add(key, self.tocData)
|
||||
|
||||
-- Transmit it to the server
|
||||
ModData.transmit(key)
|
||||
end
|
||||
|
||||
|
||||
-----------------
|
||||
@@ -137,17 +169,23 @@ function ModDataHandler:setLimbParams(limbName, ampStatus, cicatrizationTime)
|
||||
end
|
||||
|
||||
|
||||
--* Global Mod Data Apply *--
|
||||
|
||||
function ModDataHandler:apply()
|
||||
ModData.transmit(CommandsData.GetKey(self.username))
|
||||
end
|
||||
|
||||
---@param username string?
|
||||
---@return ModDataHandler?
|
||||
---@return ModDataHandler
|
||||
function ModDataHandler.GetInstance(username)
|
||||
if username == nil then
|
||||
username = getPlayer():getUsername()
|
||||
end
|
||||
|
||||
if username == nil then username = getPlayer():getUsername() end
|
||||
|
||||
if ModDataHandler.instances[username] ~= nil then
|
||||
return ModDataHandler.instances[username]
|
||||
if ModDataHandler.instances[username] == nil then
|
||||
return ModDataHandler:new(username)
|
||||
else
|
||||
return nil -- TODO This isn't exactly good
|
||||
--return ModDataHandler:new(getPlayer())
|
||||
return ModDataHandler.instances[username]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -15,61 +15,36 @@ local StaticData = require("TOC/StaticData")
|
||||
---@field playerObj IsoPlayer
|
||||
local PlayerHandler = {}
|
||||
|
||||
PlayerHandler.amputatedLimbs = {}
|
||||
|
||||
|
||||
---Setup the Player Handler and modData
|
||||
---@param _ nil
|
||||
---@param playerObj IsoPlayer
|
||||
---@param isForced boolean?
|
||||
function PlayerHandler.InitializePlayer(_, playerObj, isForced)
|
||||
PlayerHandler.SetupModData(playerObj, isForced)
|
||||
PlayerHandler.playerObj = playerObj
|
||||
function PlayerHandler.InitializePlayer(playerObj, isForced)
|
||||
|
||||
local username = playerObj:getUsername()
|
||||
TOC_DEBUG.print("initializing " .. username)
|
||||
local modDataHandler = ModDataHandler:new(username, isForced)
|
||||
PlayerHandler.playerObj = playerObj
|
||||
-- Calculate amputated limbs at startup
|
||||
PlayerHandler.amputatedLimbs = {}
|
||||
PlayerHandler.amputatedLimbs[username] = {}
|
||||
|
||||
for i=1, #StaticData.LIMBS_STRINGS do
|
||||
local limbName = StaticData.LIMBS_STRINGS[i]
|
||||
if ModDataHandler.GetInstance():getIsCut(limbName) then
|
||||
PlayerHandler.AddLocalAmputatedLimb(limbName)
|
||||
if modDataHandler:getIsCut(limbName) then
|
||||
PlayerHandler.AddLocalAmputatedLimb(username, limbName)
|
||||
end
|
||||
end
|
||||
|
||||
-- Since isForced is used to reset an existing player data, we're gonna clean their ISHealthPanel table too
|
||||
if isForced then
|
||||
ISHealthPanel.highestAmputations = {}
|
||||
--ISHealthPanel.highestAmputations = {}
|
||||
local ItemsHandler = require("TOC/Handlers/ItemsHandler")
|
||||
ItemsHandler.DeleteAllOldAmputationItems(playerObj)
|
||||
end
|
||||
end
|
||||
|
||||
---Setup TOC mod data to a local client
|
||||
---@param playerObj IsoPlayer
|
||||
---@param isForced boolean?
|
||||
function PlayerHandler.SetupModData(playerObj, isForced)
|
||||
local tocData = playerObj:getModData()[StaticData.MOD_NAME]
|
||||
if isForced or tocData == nil or tocData.Hand_L == nil or tocData.Hand_L.isCut == nil then
|
||||
local modData = playerObj:getModData()
|
||||
modData[StaticData.MOD_NAME] = {
|
||||
-- Generic stuff that does not belong anywhere else
|
||||
isIgnoredPartInfected = false,
|
||||
isAnyLimbCut = false
|
||||
}
|
||||
|
||||
---@type partData
|
||||
local defaultParams = {isCut = false, isInfected = false, isOperated = false, isCicatrized = false, isCauterized = false, isVisible = false}
|
||||
|
||||
-- We're gonna make a instance of ModDataHandler to setup this player
|
||||
local plUsername = playerObj:getUsername()
|
||||
local dataHandler = ModDataHandler:new(plUsername, modData[StaticData.MOD_NAME])
|
||||
|
||||
-- Initialize limbs
|
||||
for i=1, #StaticData.LIMBS_STRINGS do
|
||||
local limbName = StaticData.LIMBS_STRINGS[i]
|
||||
modData[StaticData.MOD_NAME][limbName] = {}
|
||||
dataHandler:setLimbParams(StaticData.LIMBS_STRINGS[i], defaultParams, 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Handles the traits
|
||||
---@param playerObj IsoPlayer
|
||||
function PlayerHandler.ManageTraits(playerObj)
|
||||
@@ -87,9 +62,9 @@ end
|
||||
|
||||
---Cache the currently amputated limbs
|
||||
---@param limbName string
|
||||
function PlayerHandler.AddLocalAmputatedLimb(limbName)
|
||||
TOC_DEBUG.print("added " .. limbName .. " to known amputated limbs")
|
||||
table.insert(PlayerHandler.amputatedLimbs, limbName) -- TODO This should be player specific, not generic
|
||||
function PlayerHandler.AddLocalAmputatedLimb(username, limbName)
|
||||
TOC_DEBUG.print("added " .. limbName .. " to known amputated limbs for " .. username)
|
||||
table.insert(PlayerHandler.amputatedLimbs[username], limbName) -- TODO This should be player specific, not generic
|
||||
end
|
||||
|
||||
--* Getters *--
|
||||
@@ -108,16 +83,18 @@ function PlayerHandler.CheckInfection(character)
|
||||
-- This fucking event barely works. Bleeding seems to be the only thing that triggers it
|
||||
if character ~= getPlayer() then return end
|
||||
local bd = character:getBodyDamage()
|
||||
local modDataHandler = ModDataHandler.GetInstance()
|
||||
|
||||
for i=1, #StaticData.LIMBS_STRINGS do
|
||||
local limbName = StaticData.LIMBS_STRINGS[i]
|
||||
local bptEnum = StaticData.BODYPARTSTYPES_ENUM[limbName]
|
||||
local bodyPart = bd:getBodyPart(bptEnum)
|
||||
|
||||
if bodyPart:bitten() or bodyPart:IsInfected() then
|
||||
if ModDataHandler.GetInstance():getIsCut(limbName) then
|
||||
if modDataHandler:getIsCut(limbName) then
|
||||
bodyPart:SetBitten(false)
|
||||
else
|
||||
ModDataHandler.GetInstance():setIsInfected(limbName, true)
|
||||
modDataHandler:setIsInfected(limbName, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user