Handling WoundCleaning

This commit is contained in:
ZioPao
2023-12-29 23:24:49 -05:00
parent 2bf1631809
commit 4e4b771e41
9 changed files with 244 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ local StaticData = require("TOC/StaticData")
local ModDataHandler = require("TOC/Handlers/ModDataHandler")
local CachedDataHandler = require("TOC/Handlers/CachedDataHandler")
local CutLimbHandler = require("TOC/UI/CutLimbInteractions")
local WoundCleaningHandler = require("TOC/UI/WoundCleaningInteraction")
---------------------------------
-- We're overriding ISHealthPanel to add custom textures to the body panel.
@@ -36,11 +37,14 @@ 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 woundCleaningHandler = WoundCleaningHandler:new(self, bodyPart, self.character:getUsername())
self:checkItems({woundCleaningHandler})
woundCleaningHandler:addToMenu(context)
end
@@ -183,14 +187,12 @@ function ISHealthBodyPartListBox:doDrawItem(y, item, alt)
if limbName then
local modDataHandler = ModDataHandler.GetInstance(username)
if modDataHandler:getIsCut(limbName) and modDataHandler:getIsVisible(limbName) then
if modDataHandler:getIsCicatrized(limbName) then
if modDataHandler:getIsCauterized(limbName) then
self:drawText("- " .. getText("IGUI_HealthPanel_Cauterized"), x, y, 0.58, 0.75, 0.28, 1, UIFont.Small)
else
self:drawText("- " .. getText("IGUI_HealthPanel_Cicatrized"), x, y, 0.28, 0.89, 0.28, 1, UIFont.Small)
end
else
local cicaTime = modDataHandler:getCicatrizationTime(limbName)

View File

@@ -1,8 +1,9 @@
local CachedDataHandler = require("TOC/Handlers/CachedDataHandler")
local StaticData = require("TOC/StaticData")
local ModDataHandler = require("TOC/Handlers/ModDataHandler")
---------------
-- TODO Surgery Kits
local function AddInventorySurgeryMenu(playerNum, context, items)

View File

@@ -0,0 +1,80 @@
local BaseHandler = require("TOC/UI/HealthPanelBaseHandler")
local CommonMethods = require("TOC/CommonMethods")
local ModDataHandler = require("TOC/Handlers/ModDataHandler")
local CleanWoundAction = require("TOC/TimedActions/CleanWoundAction")
-------------------------
---@class WoundCleaningHandler : BaseHandler
---@field username string
---@field limbName string
local WoundCleaningHandler = BaseHandler:derive("WoundCleaningHandler")
---comment
---@param panel any
---@param bodyPart any
---@param username string
---@return table
function WoundCleaningHandler:new(panel, bodyPart, username)
local o = BaseHandler.new(self, panel, bodyPart)
o.items.ITEMS = {}
o.username = username
o.limbName = CommonMethods.GetLimbNameFromBodyPart(bodyPart)
return o
end
function WoundCleaningHandler:checkItem(item)
if item:getBandagePower() >= 2 then
self:addItem(self.items.ITEMS, item)
end
end
function WoundCleaningHandler:addToMenu(context)
local types = self:getAllItemTypes(self.items.ITEMS)
if #types > 0 and self:isValid() then
local option = context:addOption("Clean Wound", nil)
local subMenu = context:getNew(context)
context:addSubMenu(option, subMenu)
for i=1,#types do
local item = self:getItemOfType(self.items.ITEMS, types[i])
subMenu:addOption(item:getName(), self, self.onMenuOptionSelected, item:getFullType())
end
end
end
function WoundCleaningHandler: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
self:onMenuOptionSelected(types[1])
return true
end
return false
end
function WoundCleaningHandler:isValid()
-- TODO Check if cut and not cicatrized and dirty
-- todo get username
if self.limbName == nil then return false end
local modDataHandler = ModDataHandler.GetInstance(self.username)
--and modDataHandler:getWoundDirtyness(self.limbName) > 0.1
return modDataHandler:getIsCut(self.limbName) and not modDataHandler:getIsCicatrized(self.limbName)
--return self:getItemOfType(self.items.ITEMS, itemType)
end
function WoundCleaningHandler: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)
ISTimedActionQueue.addAfter(previousAction, action)
end
return WoundCleaningHandler