Reimplemented item handling

This commit is contained in:
ZioPao
2023-11-07 17:21:03 +01:00
parent 8faa5b9cc5
commit 301603ed68
5 changed files with 90 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
local ModDataHandler = require("Handlers/TOC_ModDataHandler")
local StaticData = require("TOC_StaticData")
local CommonMethods = require("TOC_Common")
---------------------------
@@ -34,6 +35,9 @@ function AmputationHandler:new(limbName, surgeonPl)
return o
end
--* Main methods *--
---Starts bleeding from the point where the saw is being used
function AmputationHandler:damageDuringAmputation()
print("TOC: Damage patient")
@@ -68,7 +72,9 @@ function AmputationHandler:execute()
patientStats:setStress(baseDamage - surgeonFactor)
-- Set the data in modData
ModDataHandler.GetInstance():setCutLimb(self.limbName, false, false, false, self.surgeonFactor)
ModDataHandler.GetInstance():setCutLimb(self.limbName, false, false, false, surgeonFactor)
-- Give the player the correct amputation item
end
---Force the execution of the amputation for a trait
@@ -81,5 +87,67 @@ function AmputationHandler:close()
AmputationHandler.instance = nil
end
--* Amputation Items *--
---Search and deletes an old amputation clothing item
---@private
function AmputationHandler:deleteOldAmputationItem()
local side = CommonMethods.GetSide(self.limbName)
for partName, _ in pairs(StaticData.PARTS_STRINGS) do
local othLimbName = partName .. "_" .. side
local othClothingItemName = StaticData.AMPUTATION_CLOTHING_ITEM_BASE .. othLimbName
local othClothingItem = self.patient:getInventory():FindAndReturn(othClothingItemName)
if othClothingItem then
self.patient:getInventory():Remove(othClothingItem) -- It accepts it as an Item, not a string
print("TOC: found and deleted " .. othClothingItemName)
return
end
end
end
---Returns the correct index for the textures of the amputation
---@param isCicatrized boolean
---@return number
function AmputationHandler:getAmputationTexturesIndex(isCicatrized)
local textureString = self.patient:getHumanVisual():getSkinTexture()
local isHairy = string.find(textureString, "a$")
-- Hairy bodies
if isHairy then
textureString = textureString:sub(1, -2) -- Removes b at the end to make it compatible
end
local matchedIndex = string.match(textureString, "%d$")
-- TODO Rework this
if isHairy then
matchedIndex = matchedIndex + 5
end
if isCicatrized then
if isHairy then
matchedIndex = matchedIndex + 5 -- to use the cicatrized texture on hairy bodies
else
matchedIndex = matchedIndex + 10 -- cicatrized texture only, no hairs
end
end
return matchedIndex - 1
end
---Spawns and equips the correct amputation item to the player. In case there was another amputation on the same side, it's gonna get deleted
---@private
function AmputationHandler:spawnAmputationItem()
-- TODO Check if there are previous amputation clothing items on that side and deletes them
local clothingItem = self.patient:getInventory():AddItem(StaticData.AMPUTATION_CLOTHING_ITEM_BASE .. self.limbName)
local texId = self:getAmputationTexturesIndex(false)
---@cast clothingItem InventoryItem
clothingItem:getVisual():setTextureChoice(texId) -- it counts from 0, so we have to subtract 1
self.patient:setWornItem(clothingItem:getBodyLocation(), clothingItem)
end
return AmputationHandler