Fixes to CutLimbHandler

This commit is contained in:
ZioPao
2023-11-13 23:46:35 +01:00
parent 4fb19ae5a6
commit 56da8583b0
9 changed files with 109 additions and 38 deletions

View File

@@ -16,13 +16,13 @@ local function InitAmputationHandler(limbName, surgeonNum)
return handler return handler
end end
---comment ---Receive the damage from another player during the amputation
---@param args receiveDamageDuringAmputationParams ---@param args receiveDamageDuringAmputationParams
function ClientRelayCommands.ReceiveDamageDuringAmputation(args) function ClientRelayCommands.ReceiveDamageDuringAmputation(args)
local handler = InitAmputationHandler(args.limbName, args.surgeonNum) AmputationHandler.ApplyDamageDuringAmputation(getPlayer(), args.limbName)
handler:damageDuringAmputation()
end end
---Creates a new handler and execute the amputation function on this client
---@param args receiveExecuteAmputationActionParams ---@param args receiveExecuteAmputationActionParams
function ClientRelayCommands.ReceiveExecuteAmputationAction(args) function ClientRelayCommands.ReceiveExecuteAmputationAction(args)
local handler = InitAmputationHandler(args.limbName, args.surgeonNum) local handler = InitAmputationHandler(args.limbName, args.surgeonNum)
@@ -32,6 +32,7 @@ end
local function OnServerRelayCommand(module, command, args) local function OnServerRelayCommand(module, command, args)
if module == CommandsData.modules.TOC_RELAY and ClientRelayCommands[command] then if module == CommandsData.modules.TOC_RELAY and ClientRelayCommands[command] then
TOC_DEBUG.print("Received Server Relay command - " .. tostring(command))
ClientRelayCommands[command](args) ClientRelayCommands[command](args)
end end
end end

View File

@@ -40,8 +40,25 @@ function AmputationHandler:new(limbName, surgeonPl)
end end
--* Static methods *--
---comment
---@param player IsoPlayer
---@param limbName string
function AmputationHandler.ApplyDamageDuringAmputation(player, limbName)
local bodyDamage = player:getBodyDamage()
local bodyPartType = BodyPartType[limbName]
local bodyDamagePart = bodyDamage:getBodyPart(bodyPartType)
TOC_DEBUG.print("damage patient - " .. tostring(bodyPartType))
bodyDamagePart:setBleeding(true)
bodyDamagePart:setCut(true)
bodyDamagePart:setBleedingTime(ZombRand(10, 20))
end
--* Main methods *-- --* Main methods *--
---Damage the player part during the amputation process ---Damage the player part during the amputation process
function AmputationHandler:damageDuringAmputation() function AmputationHandler:damageDuringAmputation()
local bodyDamage = self.patientPl:getBodyDamage() local bodyDamage = self.patientPl:getBodyDamage()

View File

@@ -7,14 +7,16 @@ local CommandsData = require("TOC/CommandsData")
---@field patient IsoPlayer ---@field patient IsoPlayer
---@field character IsoPlayer ---@field character IsoPlayer
---@field limbName string ---@field limbName string
---@field item InventoryItem
local CutLimbAction = ISBaseTimedAction:derive("CutLimbAction") local CutLimbAction = ISBaseTimedAction:derive("CutLimbAction")
---Starts CutLimbAction ---Starts CutLimbAction
---@param patient IsoPlayer ---@param patient IsoPlayer
---@param surgeon IsoPlayer ---@param surgeon IsoPlayer
---@param limbName string ---@param limbName string
---@param item InventoryItem
---@return CutLimbAction ---@return CutLimbAction
function CutLimbAction:new(surgeon, patient, limbName) function CutLimbAction:new(surgeon, patient, limbName, item)
local o = {} local o = {}
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
@@ -23,6 +25,7 @@ function CutLimbAction:new(surgeon, patient, limbName)
o.character = surgeon o.character = surgeon
o.patient = patient o.patient = patient
o.limbName = limbName o.limbName = limbName
o.item = item
o.stopOnWalk = true o.stopOnWalk = true
o.stopOnRun = true o.stopOnRun = true
@@ -41,22 +44,45 @@ end
function CutLimbAction:start() function CutLimbAction:start()
if self.patient == self.character then if self.patient == self.character then
-- Self -- Self
self.handler = AmputationHandler:new(self.limbName) AmputationHandler.ApplyDamageDuringAmputation(self.patient, self.limbName)
self.handler:damageDuringAmputation()
else else
-- Other player -- Another player
----@type relayDamageDuringAmputationParams ---@type relayDamageDuringAmputationParams
local params = {patientNum = self.patient:getOnlineID(), limbName = self.limbName} local params = {patientNum = self.patient:getOnlineID(), limbName = self.limbName}
sendClientCommand(CommandsData.modules.TOC_RELAY, CommandsData.server.Relay.RelayDamageDuringAmputation, params ) sendClientCommand(CommandsData.modules.TOC_RELAY, CommandsData.server.Relay.RelayDamageDuringAmputation, params )
end end
-- Setup cosmetic stuff
self:setActionAnim("SawLog")
self:setOverrideHandModels(self.item:getStaticModel())
-- if self.character:getPrimaryHandItem() then
-- ISTimedActionQueue.add(ISUnequipAction:new(self.character, self.character:getPrimaryHandItem(), 2))
-- end
-- if self.character:getSecondaryHandItem() and self.character:getSecondaryHandItem() ~= self.character:getPrimaryHandItem() then
-- ISTimedActionQueue.add(ISUnequipAction:new(self.character, self.surgeon:getSecondaryHandItem(), 2))
-- end
-- if sawItem then
-- self:setOverrideHandModels(sawItem:getStaticModel(), nil)
-- end
end
function CutLimbAction:waitToStart()
if self.character == self.patient then
return false
end
self.character:faceThisObject(self.patient)
return self.character:shouldBeTurning()
end end
function CutLimbAction:perform() function CutLimbAction:perform()
if self.patient == self.character then if self.patient == self.character then
TOC_DEBUG.print("patient and surgeon are the same, executing on the client") TOC_DEBUG.print("patient and surgeon are the same, executing on the client")
self.handler:execute(true) local handler = AmputationHandler:new(self.limbName)
handler:execute(true)
else else
TOC_DEBUG.print("patient and surgeon not the same, sending relay to server") TOC_DEBUG.print("patient and surgeon not the same, sending relay to server")
-- Other player -- Other player

View File

@@ -15,14 +15,15 @@ end
---@param limbName string ---@param limbName string
---@param surgeon IsoPlayer ---@param surgeon IsoPlayer
---@param patient IsoPlayer ---@param patient IsoPlayer
local function PerformAction(limbName, surgeon, patient) local function PerformAction(surgeon, patient, limbName, item)
ISTimedActionQueue.add(CutLimbAction:new(surgeon, patient, limbName)) ISTimedActionQueue.add(CutLimbAction:new(surgeon, patient, limbName, item))
end end
---Adds the actions to the inventory context menu ---Adds the actions to the inventory context menu
---@param surgeonNum number ---@param surgeonNum number
---@param context ISContextMenu ---@param context ISContextMenu
local function AddInventoryAmputationOptions(surgeonNum, context) ---@param item InventoryItem
local function AddInventoryAmputationOptions(surgeonNum, context, item)
local surgeonObj = getSpecificPlayer(surgeonNum) local surgeonObj = getSpecificPlayer(surgeonNum)
local option = context:addOption(getText("ContextMenu_Amputate"), nil) local option = context:addOption(getText("ContextMenu_Amputate"), nil)
local subMenu = context:getNew(context) local subMenu = context:getNew(context)
@@ -31,7 +32,7 @@ local function AddInventoryAmputationOptions(surgeonNum, context)
local limbName = StaticData.LIMBS_STRINGS[i] local limbName = StaticData.LIMBS_STRINGS[i]
if not ModDataHandler.GetInstance():getIsCut(limbName) then if not ModDataHandler.GetInstance():getIsCut(limbName) then
local limbTranslatedName = getText("ContextMenu_Limb_" .. limbName) local limbTranslatedName = getText("ContextMenu_Limb_" .. limbName)
subMenu:addOption(limbTranslatedName, limbName, PerformAction, surgeonObj, surgeonObj) -- TODO Should be patient, not surgeon subMenu:addOption(limbTranslatedName, surgeonObj, PerformAction, surgeonObj, limbName, item) -- TODO Should be patient, not surgeon
end end
end end
end end
@@ -43,7 +44,7 @@ end
local function AddInventoryAmputationMenu(player, context, items) local function AddInventoryAmputationMenu(player, context, items)
local item = items[1] -- Selected item local item = items[1] -- Selected item
if CheckIfSaw(item.name) then if CheckIfSaw(item.name) then
AddInventoryAmputationOptions(player, context) AddInventoryAmputationOptions(player, context, item)
end end
end end
@@ -53,6 +54,7 @@ Events.OnFillInventoryObjectContextMenu.Add(AddInventoryAmputationMenu)
------------------------------------- -------------------------------------
---@class CutLimbHandler : BaseHandler ---@class CutLimbHandler : BaseHandler
---@field items table
local CutLimbHandler = BaseHandler:derive("CutLimbHandler") local CutLimbHandler = BaseHandler:derive("CutLimbHandler")
@@ -63,24 +65,24 @@ local CutLimbHandler = BaseHandler:derive("CutLimbHandler")
function CutLimbHandler:new(panel, bodyPart) function CutLimbHandler:new(panel, bodyPart)
local o = BaseHandler.new(self, panel, bodyPart) local o = BaseHandler.new(self, panel, bodyPart)
o.items.ITEMS = {} o.items.ITEMS = {}
TOC_DEBUG.print("init CutLimbHandler")
return o return o
end end
---@param item InventoryItem ---@param item InventoryItem
function CutLimbHandler:checkItem(item) function CutLimbHandler:checkItem(item)
local itemType = item:getType() local itemType = item:getType()
if CheckIfSaw(itemType) then if string.contains(itemType, "Saw") then
self:addItem(self.items.ITEMS, item) self:addItem(self.items.ITEMS, item)
end end
end end
---@param context ISContextMenu ---@param context ISContextMenu
function CutLimbHandler:addToMenu(context) function CutLimbHandler:addToMenu(context)
local types = self:getAllItemTypes(self.items.ITEMS)
--TOC_DEBUG.print("addToMenu running")
local limbName = BodyPartType.ToString(self.bodyPart:getType()) local limbName = BodyPartType.ToString(self.bodyPart:getType())
--TOC_DEBUG.print(limbName) if #types > 0 and StaticData.BODYPARTSTYPES_ENUM[limbName] then
if StaticData.BODYPARTSTYPES_ENUM[limbName] then TOC_DEBUG.print("addToMenu, types > 0")
if not ModDataHandler.GetInstance():getIsCut(limbName) then if not ModDataHandler.GetInstance():getIsCut(limbName) then
context:addOption(getText("ContextMenu_Amputate"), self, self.onMenuOptionSelected) context:addOption(getText("ContextMenu_Amputate"), self, self.onMenuOptionSelected)
end end
@@ -89,7 +91,8 @@ end
function CutLimbHandler:dropItems(items) function CutLimbHandler:dropItems(items)
local types = self:getAllItemTypes(items) local types = self:getAllItemTypes(items)
if #self.items.ITEMS > 0 and #types == 1 then local limbName = BodyPartType.ToString(self.bodyPart:getType())
if #self.items.ITEMS > 0 and #types == 1 and StaticData.BODYPARTSTYPES_ENUM[limbName] then
self:onMenuOptionSelected(types[1]) self:onMenuOptionSelected(types[1])
return true return true
end end
@@ -97,17 +100,17 @@ function CutLimbHandler:dropItems(items)
end end
function CutLimbHandler:isValid(itemType) function CutLimbHandler:isValid(itemType)
return true -- TODO Workaround for now local limbName = BodyPartType.ToString(self.bodyPart:getType())
return (not ModDataHandler.GetInstance():getIsCut(limbName)) and self:getItemOfType(self.items.ITEMS, itemType)
end end
function CutLimbHandler:perform(previousAction, itemType) function CutLimbHandler:perform(previousAction, itemType)
--local item = self:getItemOfType(self.items.ITEMS, itemType) local item = self:getItemOfType(self.items.ITEMS, itemType)
--previousAction = self:toPlayerInventory(item, previousAction) previousAction = self:toPlayerInventory(item, previousAction)
-- TODO This is broken like this!
local limbName = BodyPartType.ToString(self.bodyPart:getType()) local limbName = BodyPartType.ToString(self.bodyPart:getType())
TOC_DEBUG.print("perform CutLimbHandler on " .. limbName) TOC_DEBUG.print("perform CutLimbHandler on " .. limbName)
local action = CutLimbAction:new(self:getDoctor(),self:getPatient(), limbName) local action = CutLimbAction:new(self:getDoctor(),self:getPatient(), limbName, item)
ISTimedActionQueue.add(action) ISTimedActionQueue.addAfter(previousAction, action)
end end
return CutLimbHandler return CutLimbHandler

View File

@@ -17,6 +17,8 @@ ISHealthBodyPartPanel = ISBodyPartPanel:derive("ISHealthBodyPartPanel")
local og_ISHealthPanel_dropItemsOnBodyPart = ISHealthPanel.dropItemsOnBodyPart local og_ISHealthPanel_dropItemsOnBodyPart = ISHealthPanel.dropItemsOnBodyPart
function ISHealthPanel:dropItemsOnBodyPart(bodyPart, items) function ISHealthPanel:dropItemsOnBodyPart(bodyPart, items)
og_ISHealthPanel_dropItemsOnBodyPart(self, bodyPart, items) og_ISHealthPanel_dropItemsOnBodyPart(self, bodyPart, items)
TOC_DEBUG.print("override to dropItemsOnBodyPart running")
local cutLimbHandler = CutLimbHandler:new(self, bodyPart) local cutLimbHandler = CutLimbHandler:new(self, bodyPart)
for _,item in ipairs(items) do for _,item in ipairs(items) do
cutLimbHandler:checkItem(item) cutLimbHandler:checkItem(item)
@@ -35,10 +37,34 @@ function ISHealthPanel:doBodyPartContextMenu(bodyPart, x, y)
-- To not recreate it but reuse the one that has been created in the original method -- To not recreate it but reuse the one that has been created in the original method
local context = getPlayerContextMenu(playerNum) local context = getPlayerContextMenu(playerNum)
local cutLimbHandler = CutLimbHandler:new(self, bodyPart) local cutLimbHandler = CutLimbHandler:new(self, bodyPart)
self:checkItems({cutLimbHandler})
cutLimbHandler:addToMenu(context) cutLimbHandler:addToMenu(context)
end end
--* Modifications to handle visible amputation on the health menu *-- --* Modifications to handle visible amputation on the health menu *--
local og_ISHealthPanel_initialise = ISHealthPanel.initialise local og_ISHealthPanel_initialise = ISHealthPanel.initialise

View File

@@ -11,9 +11,7 @@ function DebugCommands.PrintAllTocData(playerObj, args)
TOC_DEBUG.printTable(ServerDataHandler.modData) TOC_DEBUG.printTable(ServerDataHandler.modData)
end end
---Print ALL TOC data
---comment
---@param playerObj IsoPlayer ---@param playerObj IsoPlayer
---@param args printTocDataParams ---@param args printTocDataParams
function DebugCommands.PrintTocData(playerObj, args) function DebugCommands.PrintTocData(playerObj, args)

View File

@@ -14,6 +14,7 @@ end
---@param key string ---@param key string
---@param table tocModData ---@param table tocModData
function ServerDataHandler.AddTable(key, table) function ServerDataHandler.AddTable(key, table)
TOC_DEBUG.print("Adding table with key: " .. tostring(key))
ModData.add(key, table) -- Add it to the server mod data ModData.add(key, table) -- Add it to the server mod data
ServerDataHandler.modData[key] = table ServerDataHandler.modData[key] = table
end end

View File

@@ -6,19 +6,17 @@ local ServerRelayCommands = {}
-- TODO We can easily make this a lot more simple without having functions -- TODO We can easily make this a lot more simple without having functions
---comment ---Relay DamageDuringAmputation to another client
---@param surgeonPl IsoPlayer
---@param args relayDamageDuringAmputationParams ---@param args relayDamageDuringAmputationParams
function ServerRelayCommands.RelayDamageDuringAmputation(surgeonPl, args) function ServerRelayCommands.RelayDamageDuringAmputation(_, args)
local patientPl = getPlayerByOnlineID(args.patientNum) local patientPl = getPlayerByOnlineID(args.patientNum)
local surgeonNum = surgeonPl:getOnlineID()
---@type receiveDamageDuringAmputationParams ---@type receiveDamageDuringAmputationParams
local params = {surgeonNum = surgeonNum, limbName = args.limbName} local params = {limbName = args.limbName}
sendServerCommand(patientPl, CommandsData.modules.TOC_RELAY, CommandsData.client.Relay.ReceiveDamageDuringAmputation, params) sendServerCommand(patientPl, CommandsData.modules.TOC_RELAY, CommandsData.client.Relay.ReceiveDamageDuringAmputation, params)
end end
---comment ---Relay ExecuteAmputationAction to another client
---@param surgeonPl IsoPlayer ---@param surgeonPl IsoPlayer
---@param args relayExecuteAmputationActionParams ---@param args relayExecuteAmputationActionParams
function ServerRelayCommands.RelayExecuteAmputationAction(surgeonPl, args) function ServerRelayCommands.RelayExecuteAmputationAction(surgeonPl, args)
@@ -36,6 +34,7 @@ end
local function OnClientRelayCommand(module, command, playerObj, args) local function OnClientRelayCommand(module, command, playerObj, args)
if module == CommandsData.modules.TOC_RELAY and ServerRelayCommands[command] then if module == CommandsData.modules.TOC_RELAY and ServerRelayCommands[command] then
TOC_DEBUG.print("Received Client Relay command - " .. tostring(command))
ServerRelayCommands[command](playerObj, args) ServerRelayCommands[command](playerObj, args)
end end
end end

View File

@@ -10,7 +10,7 @@ CommandsData.modules = {
CommandsData.client = { CommandsData.client = {
Relay = { Relay = {
ReceiveDamageDuringAmputation = "ReceiveDamageDuringAmputation", ---@alias receiveDamageDuringAmputationParams {surgeonNum : number, limbName : string} ReceiveDamageDuringAmputation = "ReceiveDamageDuringAmputation", ---@alias receiveDamageDuringAmputationParams { limbName : string}
ReceiveExecuteAmputationAction = "ReceiveExecuteAmputationAction" ---@alias receiveExecuteAmputationActionParams {surgeonNum : number, limbName : string} ReceiveExecuteAmputationAction = "ReceiveExecuteAmputationAction" ---@alias receiveExecuteAmputationActionParams {surgeonNum : number, limbName : string}
} }
} }