Reimplemented item handling
This commit is contained in:
@@ -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
|
||||
@@ -11,12 +11,9 @@ local StaticData = require("TOC_StaticData")
|
||||
-- Update current player status (infection checks)
|
||||
-- handle stats increase\decrease
|
||||
|
||||
|
||||
---@class PlayerHandler
|
||||
local PlayerHandler = {}
|
||||
|
||||
-- TODO This should be instanceable for a player. Separate handlers not
|
||||
|
||||
---Setup player modData
|
||||
---@param _ nil
|
||||
---@param playerObj IsoPlayer
|
||||
|
||||
10
media/lua/client/TOC_Common.lua
Normal file
10
media/lua/client/TOC_Common.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
local CommonMethods = {}
|
||||
|
||||
---Returns the side for a certain limb
|
||||
---@param limbName string
|
||||
---@return string "L" or "R"
|
||||
function CommonMethods.GetSide(limbName)
|
||||
if string.find(limbName, "_L") then return "L" else return "R" end
|
||||
end
|
||||
|
||||
return CommonMethods
|
||||
@@ -70,4 +70,13 @@ StaticData.HEALTH_PANEL_TEXTURES = {
|
||||
}
|
||||
|
||||
|
||||
-----------------
|
||||
-- Visuals and clothing
|
||||
|
||||
|
||||
|
||||
|
||||
StaticData.AMPUTATION_CLOTHING_ITEM_BASE = "TOC.Amputation_"
|
||||
|
||||
|
||||
return StaticData
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local PlayerHandler = require("TOC_PlayerHandler")
|
||||
local StaticData = require("TOC_StaticData")
|
||||
local CommonMethods = require("TOC_Common")
|
||||
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
local CutLimbHandler = require("UI/TOC_CutLimbHandler")
|
||||
@@ -42,8 +43,7 @@ function ISHealthPanel.GetHighestAmputation()
|
||||
ISHealthPanel.highestAmputations = {}
|
||||
for i=1, #StaticData.LIMBS_STRINGS do
|
||||
local limbName = StaticData.LIMBS_STRINGS[i]
|
||||
local index
|
||||
if string.find(limbName, "_L") then index = "L" else index = "R" end
|
||||
local index = CommonMethods.GetSide(limbName)
|
||||
if PlayerHandler.modDataHandler:getIsCut(limbName) and PlayerHandler.modDataHandler:getIsVisible(limbName) then
|
||||
ISHealthPanel.highestAmputations[index] = limbName
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user