More cleaning, fixing up interactions

This commit is contained in:
ZioPao
2024-01-08 22:40:15 +01:00
parent d3722c1171
commit 06e41790ca
9 changed files with 110 additions and 167 deletions

View File

@@ -2,8 +2,8 @@ local StaticData = require("TOC/StaticData")
local DataController = require("TOC/Controllers/DataController")
local CachedDataHandler = require("TOC/Handlers/CachedDataHandler")
local CutLimbHandler = require("TOC/UI/Interactions/CutLimbHandler")
local WoundCleaningHandler = require("TOC/UI/Interactions/WoundCleaningHandler")
local CutLimbInteractionHandler = require("TOC/UI/Interactions/CutLimbInteractionHandler")
local WoundCleaningInteractionHandler = require("TOC/UI/Interactions/WoundCleaningInteractionHandler")
------------------------
@@ -30,11 +30,14 @@ function ISHealthPanel:dropItemsOnBodyPart(bodyPart, items)
og_ISHealthPanel_dropItemsOnBodyPart(self, bodyPart, items)
TOC_DEBUG.print("override to dropItemsOnBodyPart running")
local cutLimbHandler = CutLimbHandler:new(self, bodyPart)
local cutLimbInteraction = CutLimbInteractionHandler:new(self, bodyPart)
local woundCleaningInteraction = WoundCleaningInteractionHandler:new(self, bodyPart, self.character:getUsername())
for _,item in ipairs(items) do
cutLimbHandler:checkItem(item)
cutLimbInteraction:checkItem(item)
woundCleaningInteraction:checkItem(item)
end
if cutLimbHandler:dropItems(items) then
if cutLimbInteraction:dropItems(items) or woundCleaningInteraction:dropItems(items) then
return
end
@@ -48,13 +51,13 @@ function ISHealthPanel:doBodyPartContextMenu(bodyPart, x, y)
-- To not recreate it but reuse the one that has been created in the original method
local context = getPlayerContextMenu(playerNum)
local cutLimbHandler = CutLimbHandler:new(self, bodyPart)
self:checkItems({cutLimbHandler})
cutLimbHandler:addToMenu(context)
local cutLimbInteraction = CutLimbInteractionHandler:new(self, bodyPart)
self:checkItems({cutLimbInteraction})
cutLimbInteraction:addToMenu(context)
local woundCleaningHandler = WoundCleaningHandler:new(self, bodyPart, self.character:getUsername())
self:checkItems({woundCleaningHandler})
woundCleaningHandler:addToMenu(context)
local woundCleaningInteraction = WoundCleaningInteractionHandler:new(self, bodyPart, self.character:getUsername())
self:checkItems({woundCleaningInteraction})
woundCleaningInteraction:addToMenu(context)
end

View File

@@ -142,31 +142,30 @@ Events.OnFillInventoryObjectContextMenu.Add(AddInventoryAmputationMenu)
-------------------------------------
---@class CutLimbHandler : BaseHandler
---@class CutLimbInteractionHandler : BaseHandler
---@field items table
---@field limbName string
---@field itemType string temporary
local CutLimbHandler = BaseHandler:derive("CutLimbHandler")
local CutLimbInteractionHandler = BaseHandler:derive("CutLimbInteractionHandler")
---Creates new CutLimbHandler
---Creates new CutLimbInteractionHandler
---@param panel ISUIElement
---@param bodyPart BodyPart
---@return CutLimbHandler
function CutLimbHandler:new(panel, bodyPart)
---@return CutLimbInteractionHandler
function CutLimbInteractionHandler:new(panel, bodyPart)
local o = BaseHandler.new(self, panel, bodyPart)
o.items.ITEMS = {}
o.limbName = BodyPartType.ToString(bodyPart:getType())
o.itemType = "Saw"
TOC_DEBUG.print("init CutLimbHandler")
--TOC_DEBUG.print("init CutLimbInteractionHandler")
return o
end
---@param item InventoryItem
function CutLimbHandler:checkItem(item)
TOC_DEBUG.print("CutLimbHandler checkItem")
function CutLimbInteractionHandler:checkItem(item)
--TOC_DEBUG.print("CutLimbInteractionHandler checkItem")
local itemType = item:getType()
--TOC_DEBUG.print("checkItem: " .. tostring(itemType))
if CheckIfSaw(itemType) then
TOC_DEBUG.print("added to list -> " .. itemType)
@@ -175,8 +174,8 @@ function CutLimbHandler:checkItem(item)
end
---@param context ISContextMenu
function CutLimbHandler:addToMenu(context)
TOC_DEBUG.print("CutLimbHandler addToMenu")
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
TOC_DEBUG.print("addToMenu, types > 0")
@@ -186,7 +185,7 @@ function CutLimbHandler:addToMenu(context)
end
end
function CutLimbHandler:dropItems(items)
function CutLimbInteractionHandler:dropItems(items)
local types = self:getAllItemTypes(items)
if #self.items.ITEMS > 0 and #types == 1 and StaticData.BODYLOCS_IND_BPT[self.limbName] then
self:onMenuOptionSelected(types[1])
@@ -195,20 +194,20 @@ function CutLimbHandler:dropItems(items)
return false
end
---Check if CutLimbHandler is valid, the limb must not be cut to be valid
---Check if CutLimbInteractionHandler is valid, the limb must not be cut to be valid
---@return boolean
function CutLimbHandler:isValid()
TOC_DEBUG.print("CutLimbHandler isValid")
function CutLimbInteractionHandler:isValid()
--TOC_DEBUG.print("CutLimbInteractionHandler isValid")
self:checkItems()
return not DataController.GetInstance():getIsCut(self.limbName)
end
function CutLimbHandler:perform(previousAction, itemType)
function CutLimbInteractionHandler:perform(previousAction, itemType)
local item = self:getItemOfType(self.items.ITEMS, itemType)
previousAction = self:toPlayerInventory(item, previousAction)
TOC_DEBUG.print("perform CutLimbHandler on " .. self.limbName)
TOC_DEBUG.print("Perform CutLimbInteractionHandler on " .. self.limbName)
local action = CutLimbAction:new(self:getDoctor(),self:getPatient(), self.limbName, item)
ISTimedActionQueue.addAfter(previousAction, action)
end
return CutLimbHandler
return CutLimbInteractionHandler

View File

@@ -5,17 +5,16 @@ local DataController = require("TOC/Controllers/DataController")
local CleanWoundAction = require("TOC/TimedActions/CleanWoundAction")
-------------------------
---@class WoundCleaningHandler : BaseHandler
---@class WoundCleaningInteractionHandler : BaseHandler
---@field username string
---@field limbName string
local WoundCleaningHandler = BaseHandler:derive("WoundCleaningHandler")
local WoundCleaningInteractionHandler = BaseHandler:derive("WoundCleaningInteractionHandler")
---comment
---@param panel any
---@param bodyPart any
---@param username string
---@return table
function WoundCleaningHandler:new(panel, bodyPart, username)
function WoundCleaningInteractionHandler:new(panel, bodyPart, username)
local o = BaseHandler.new(self, panel, bodyPart)
o.items.ITEMS = {}
o.username = username
@@ -25,26 +24,32 @@ function WoundCleaningHandler:new(panel, bodyPart, username)
return o
end
function WoundCleaningHandler:checkItem(item)
if item:getBandagePower() >= 2 then
function WoundCleaningInteractionHandler:checkItem(item)
-- Disinfected rag or bandage
--TOC_DEBUG.print("WoundCleaningInteractionHandler checkItem")
if item:getBandagePower() >=2 and item:isAlcoholic() then
--TOC_DEBUG.print("Adding " .. item:getName())
self:addItem(self.items.ITEMS, item)
end
end
function WoundCleaningHandler:addToMenu(context)
function WoundCleaningInteractionHandler:addToMenu(context)
--TOC_DEBUG.print("WoundCleaningInteraction addToMenu")
local types = self:getAllItemTypes(self.items.ITEMS)
if #types > 0 and self:isValid() then
local option = context:addOption("Clean Wound", nil)
--TOC_DEBUG.print("WoundCleaningInteraction inside addToMenu")
local option = context:addOption(getText("ContextMenu_CleanWound"), nil)
local subMenu = context:getNew(context)
context:addSubMenu(option, subMenu)
for i=1,#types do
for i=1, #types do
local item = self:getItemOfType(self.items.ITEMS, types[i])
--TOC_DEBUG.print(item:getName())
subMenu:addOption(item:getName(), self, self.onMenuOptionSelected, item:getFullType())
end
end
end
function WoundCleaningHandler:dropItems(items)
function WoundCleaningInteractionHandler:dropItems(items)
local types = self:getAllItemTypes(items)
if #self.items.ITEMS > 0 and #types == 1 and self:isInjured() and self.bodyPart:isNeedBurnWash() then
-- FIXME: A bandage can be used to clean a burn or bandage it
@@ -54,7 +59,7 @@ function WoundCleaningHandler:dropItems(items)
return false
end
function WoundCleaningHandler:isValid()
function WoundCleaningInteractionHandler:isValid()
-- TODO Check if cut and not cicatrized and dirty
-- todo get username
@@ -63,12 +68,13 @@ function WoundCleaningHandler:isValid()
local dcInst = DataController.GetInstance(self.username)
--and dcInst:getWoundDirtyness(self.limbName) > 0.1
return dcInst:getIsCut(self.limbName) and not dcInst:getIsCicatrized(self.limbName)
local check = dcInst:getIsCut(self.limbName) and not dcInst:getIsCicatrized(self.limbName) and dcInst:getWoundDirtyness(self.limbName) > 0
--TOC_DEBUG.print("WoundCleaningInteraction isValid: " .. tostring(check))
return check
--return self:getItemOfType(self.items.ITEMS, itemType)
end
function WoundCleaningHandler:perform(previousAction, itemType)
function WoundCleaningInteractionHandler:perform(previousAction, itemType)
local item = self:getItemOfType(self.items.ITEMS, itemType)
previousAction = self:toPlayerInventory(item, previousAction)
local action = CleanWoundAction:new(self:getDoctor(), self:getPatient(), item, self.bodyPart)
@@ -76,4 +82,4 @@ function WoundCleaningHandler:perform(previousAction, itemType)
end
return WoundCleaningHandler
return WoundCleaningInteractionHandler