chore: stuff to move around for 42.13

This commit is contained in:
ZioPao
2026-01-15 22:37:13 +01:00
parent 457f89b064
commit 1fb3899a5a
7 changed files with 46 additions and 27 deletions

View File

@@ -1,3 +1,5 @@
-- TODO Should be server side in 42.13
local StaticData = require("TOC/StaticData")
local CommonMethods = require("TOC/CommonMethods")
---------------------------

View File

@@ -24,9 +24,7 @@ local CutLimbAction = ISBaseTimedAction:derive("CutLimbAction")
---@param bandageItem InventoryItem?
---@return CutLimbAction
function CutLimbAction:new(surgeon, patient, limbName, item, stitchesItem, bandageItem)
local o = {}
setmetatable(o, self)
self.__index = self
local o = ISBaseTimedAction.new(self, surgeon)
-- We need to follow ISBaseTimedAction. self.character is gonna be the surgeon
o.character = surgeon
@@ -43,12 +41,21 @@ function CutLimbAction:new(surgeon, patient, limbName, item, stitchesItem, banda
o.stopOnWalk = true
o.stopOnRun = true
o.maxTime = 1000 - (surgeon:getPerkLevel(Perks.Doctor) * 50)
if o.character:isTimedActionInstant() then o.maxTime = 1 end
o.maxTime = o:getDuration()
return o
end
function CutLimbAction:getDuration()
if self.character:isTimedActionInstant() then
return 1
else
local baseTime = 1000
local perkLevel = self.character:getPerkLevel(Perks.Doctor)
return baseTime - (perkLevel * 50)
end
end
function CutLimbAction:isValid()
return not ISHealthPanel.DidPatientMove(self.character,self.patient, self.patientX, self.patientY)
end
@@ -89,6 +96,16 @@ function CutLimbAction:start()
end
-- function CutLimbAction:serverStart()
-- emulateAnimEvent(self.netAction, 200, "")
-- end
-- function CutLimbAction:animEvent(event, parameter)
-- end
function CutLimbAction:waitToStart()
if self.character == self.patient then
return false
@@ -117,22 +134,30 @@ function CutLimbAction:stop()
end
function CutLimbAction:perform()
-- Stop the sound
self:stopSound()
if self.patient == self.character then
TOC_DEBUG.print("patient and surgeon are the same, executing on the client")
local handler = AmputationHandler:new(self.limbName)
handler:execute(true)
else
TOC_DEBUG.print("patient and surgeon not the same, sending relay to server")
-- Other player
---@type relayExecuteAmputationActionParams
local params = {patientNum = self.patient:getOnlineID(), limbName = self.limbName}
sendClientCommand(CommandsData.modules.TOC_RELAY, CommandsData.server.Relay.RelayExecuteAmputationAction, params )
end
ISBaseTimedAction.perform(self)
end
function CutLimbAction:complete()
-- TODO AmputationHandler runs client side, by doing this this would run on the server. AM I missing something?
local handler = AmputationHandler:new(self.limbName, self.character)
handler:execute(true)
end
-- function CutLimbAction:perform()
-- -- Stop the sound
-- if self.patient == self.character then
-- TOC_DEBUG.print("patient and surgeon are the same, executing on the client")
-- local handler = AmputationHandler:new(self.limbName)
-- handler:execute(true)
-- else
-- TOC_DEBUG.print("patient and surgeon not the same, sending relay to server")
-- -- Other player
-- ---@type relayExecuteAmputationActionParams
-- local params = {patientNum = self.patient:getOnlineID(), limbName = self.limbName}
-- sendClientCommand(CommandsData.modules.TOC_RELAY, CommandsData.server.Relay.RelayExecuteAmputationAction, params )
-- end
-- end
return CutLimbAction

View File

@@ -1,171 +0,0 @@
-- Made by Vyshnia
-- Workshop ID: 2875394066
-- Mod ID: LuaTimers
local os_time = os.time
local table_insert = table.insert
local table_remove = table.remove
local assert = assert
local type = type
local pairs = pairs
timer = {
Timers = {},
SimpleTimers = {}
}
function timer:Simple(delay, func)
assert(type(delay) == "number", "Delay of timer should be a number type")
assert(type(func) == "function", "Func of timer should be a function type (lol)")
table_insert(self.SimpleTimers, {
EndTime = os_time() + delay,
Func = func
})
end
function timer:Create(name, delay, repetitions, func)
assert(type(name) == "string", "ID of timer should be a string type")
assert(type(delay) == "number", "Delay of timer should be a number type")
assert(type(repetitions) == "number", "Repetitions of timer should be a number type")
assert(type(func) == "function", "Func of timer should be a function type (lol)")
self.Timers[name] = {
Delay = delay,
StartRepetitions = repetitions,
Repetitions = repetitions,
Infinity = repetitions == 0,
LastFuncTime = os_time(),
Func = func,
Paused = false,
}
end
local function timerUpdate()
local cur_time = os_time()
for k, v in pairs(timer.Timers) do
if not v.Paused then
if cur_time >= v.LastFuncTime + v.Delay then
v.Func()
v.LastFuncTime = cur_time
if not v.Infinity then
v.Repetitions = v.Repetitions - 1
if v.Repetitions <= 0 then
timer.Timers[k] = nil
end
end
end
end
end
local simple_timers = timer.SimpleTimers
for i = #simple_timers, 1, -1 do
local t = simple_timers[i]
if t.EndTime <= cur_time then
t.Func()
table_remove(simple_timers, i)
end
end
end
Events.OnTickEvenPaused.Add(timerUpdate)
function timer:Remove(name)
local t = self.Timers[name]
if not t then return false end
self.Timers[name] = nil
return true
end
function timer:Exists(name)
return self.Timers[name] and true or false
end
function timer:Start(name)
local t = self.Timers[name]
if not t then return false end
t.Repetitions = t.StartRepetitions
t.LastFuncTime = os_time()
t.Paused = false
t.PausedTime = nil
return true
end
function timer:Pause(name)
local t = self.Timers[name]
if not t then return false end
if t.Paused then return false end
t.Paused = true
t.PausedTime = os_time()
return true
end
function timer:UnPause(name)
local t = self.Timers[name]
if not t then return false end
if not t.Paused then return false end
t.Paused = false
return true
end
timer.Resume = timer.UnPause
function timer:Toggle(name)
local t = self.Timers[name]
if not t then return false end
t.Paused = not t.Paused
return true
end
function timer:TimeLeft(name)
local t = self.Timers[name]
if not t then return end
if t.Paused then
return (t.Repetitions - 1) * t.Delay + (t.LastFuncTime + t.Delay - t.PausedTime)
else
return (t.Repetitions - 1) * t.Delay + (t.LastFuncTime + t.Delay - os_time())
end
end
function timer:NextTimeLeft(name)
local t = self.Timers[name]
if not t then return end
if t.Paused then
return t.LastFuncTime + t.Delay - t.PausedTime
else
return t.LastFuncTime + t.Delay - os_time()
end
end
function timer:RepsLeft(name)
local t = self.Timers[name]
return t and t.Repetitions
end