Better handling of items in containers
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
local ModDataHandler = require("Handlers/TOC_ModDataHandler")
|
local ModDataHandler = require("Handlers/TOC_ModDataHandler")
|
||||||
local StaticData = require("TOC_StaticData")
|
local StaticData = require("TOC_StaticData")
|
||||||
local ItemsHandler = require("Handlers/TOC_ItemsHandler")
|
local ItemsHandler = require("Handlers/TOC_ItemsHandler")
|
||||||
|
local PlayerHandler = require("Handlers/TOC_PlayerHandler")
|
||||||
|
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
@@ -50,27 +51,30 @@ function AmputationHandler:damageDuringAmputation()
|
|||||||
end
|
end
|
||||||
|
|
||||||
---Execute the amputation
|
---Execute the amputation
|
||||||
function AmputationHandler:execute()
|
---@param damagePlayer boolean?
|
||||||
|
function AmputationHandler:execute(damagePlayer)
|
||||||
|
|
||||||
-- TODO Calculate surgeonStats
|
-- TODO Calculate surgeonStats
|
||||||
-- TODO Cap it to a certain amount, it shouldn't be more than ...?
|
-- TODO Cap it to a certain amount, it shouldn't be more than ...?
|
||||||
local surgeonFactor = 1
|
local surgeonFactor = 1
|
||||||
|
if damagePlayer == nil then damagePlayer = true end -- Default at true
|
||||||
|
if damagePlayer then
|
||||||
|
local patientStats = self.patient:getStats()
|
||||||
|
local bd = self.patient:getBodyDamage()
|
||||||
|
local bodyPart = bd:getBodyPart(self.bodyPartType)
|
||||||
|
local baseDamage = StaticData.LIMBS_BASE_DAMAGE[self.limbName]
|
||||||
|
|
||||||
|
-- Set the bleeding and all the damage stuff in that part
|
||||||
|
bodyPart:AddDamage(baseDamage - surgeonFactor)
|
||||||
|
bodyPart:setAdditionalPain(baseDamage - surgeonFactor)
|
||||||
|
bodyPart:setBleeding(true)
|
||||||
|
bodyPart:setBleedingTime(baseDamage - surgeonFactor)
|
||||||
|
bodyPart:setDeepWounded(true)
|
||||||
|
bodyPart:setDeepWoundTime(baseDamage - surgeonFactor)
|
||||||
|
patientStats:setEndurance(surgeonFactor)
|
||||||
|
patientStats:setStress(baseDamage - surgeonFactor)
|
||||||
|
end
|
||||||
|
|
||||||
local patientStats = self.patient:getStats()
|
|
||||||
local bd = self.patient:getBodyDamage()
|
|
||||||
local bodyPart = bd:getBodyPart(self.bodyPartType)
|
|
||||||
local baseDamage = StaticData.LIMBS_BASE_DAMAGE[self.limbName]
|
|
||||||
|
|
||||||
-- Set the bleeding and all the damage stuff in that part
|
|
||||||
bodyPart:AddDamage(baseDamage - surgeonFactor)
|
|
||||||
bodyPart:setAdditionalPain(baseDamage - surgeonFactor)
|
|
||||||
bodyPart:setBleeding(true)
|
|
||||||
bodyPart:setBleedingTime(baseDamage - surgeonFactor)
|
|
||||||
bodyPart:setDeepWounded(true)
|
|
||||||
bodyPart:setDeepWoundTime(baseDamage - surgeonFactor)
|
|
||||||
patientStats:setEndurance(surgeonFactor)
|
|
||||||
patientStats:setStress(baseDamage - surgeonFactor)
|
|
||||||
|
|
||||||
-- Set the data in modData
|
-- Set the data in modData
|
||||||
ModDataHandler.GetInstance():setCutLimb(self.limbName, false, false, false, surgeonFactor)
|
ModDataHandler.GetInstance():setCutLimb(self.limbName, false, false, false, surgeonFactor)
|
||||||
@@ -78,11 +82,10 @@ function AmputationHandler:execute()
|
|||||||
-- Give the player the correct amputation item
|
-- Give the player the correct amputation item
|
||||||
ItemsHandler.DeleteOldAmputationItem(self.patient, self.limbName)
|
ItemsHandler.DeleteOldAmputationItem(self.patient, self.limbName)
|
||||||
ItemsHandler.SpawnAmputationItem(self.patient, self.limbName)
|
ItemsHandler.SpawnAmputationItem(self.patient, self.limbName)
|
||||||
end
|
|
||||||
|
|
||||||
---Force the execution of the amputation for a trait
|
-- Add it to the list of cut limbs
|
||||||
function AmputationHandler:executeForTrait()
|
PlayerHandler.AddLocalAmputatedLimb(self.limbName)
|
||||||
ModDataHandler.GetInstance():setCutLimb(self.limbName, true, true, true, 0)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---Deletes the instance
|
---Deletes the instance
|
||||||
@@ -90,5 +93,11 @@ function AmputationHandler:close()
|
|||||||
AmputationHandler.instance = nil
|
AmputationHandler.instance = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--* Events *--
|
||||||
|
function AmputationHandler.UpdateCicatrization()
|
||||||
|
if ModDataHandler.GetInstance():getIsAnyLimbCut() == false then return end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
return AmputationHandler
|
return AmputationHandler
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
local StaticData = require("TOC_StaticData")
|
local StaticData = require("TOC_StaticData")
|
||||||
local CommonMethods = require("TOC_Common")
|
local CommonMethods = require("TOC_Common")
|
||||||
|
local PlayerHandler = require("Handlers/TOC_PlayerHandler")
|
||||||
|
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
@@ -98,6 +99,27 @@ function ItemsHandler.SpawnAmputationItem(playerObj, limbName)
|
|||||||
playerObj:setWornItem(clothingItem:getBodyLocation(), clothingItem)
|
playerObj:setWornItem(clothingItem:getBodyLocation(), clothingItem)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--------------------------
|
||||||
|
--* Overrides *--
|
||||||
|
|
||||||
|
local og_ISInventoryPane_refreshContainer = ISInventoryPane.refreshContainer
|
||||||
|
|
||||||
|
---Get the list of items for the container and remove the amputations
|
||||||
|
function ISInventoryPane:refreshContainer()
|
||||||
|
|
||||||
|
-- Search into the container and remove the reference to the amputation item
|
||||||
|
|
||||||
|
og_ISInventoryPane_refreshContainer(self)
|
||||||
|
for i=1, #self.itemslist do
|
||||||
|
local cItem = self.itemslist[i]
|
||||||
|
if cItem and cItem.cat == "Amputation" then
|
||||||
|
--print("TOC: current item is an amputation, removing it from the list")
|
||||||
|
table.remove(self.itemslist, i)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
return ItemsHandler
|
return ItemsHandler
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
local ModDataHandler = require("Handlers/TOC_ModDataHandler")
|
local ModDataHandler = require("Handlers/TOC_ModDataHandler")
|
||||||
local AmputationHandler = require("Handlers/TOC_AmputationHandler")
|
|
||||||
local ItemsHandler = require("Handlers/TOC_ItemsHandler")
|
|
||||||
local CommonMethods = require("TOC_Common")
|
local CommonMethods = require("TOC_Common")
|
||||||
local StaticData = require("TOC_StaticData")
|
local StaticData = require("TOC_StaticData")
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
-- TODO We should instantiate this anyway if we want to keep track of cut limbs here. Doing so, we would be able to handle other players too
|
||||||
|
|
||||||
-- LIST OF STUFF THAT THIS CLASS NEEDS TO DO
|
-- LIST OF STUFF THAT THIS CLASS NEEDS TO DO
|
||||||
|
-- Keep track of cut limbs so that we don't have to loop through all of them all the time
|
||||||
-- Update current player status (infection checks)
|
-- Update current player status (infection checks)
|
||||||
-- handle stats increase\decrease
|
-- handle stats increase\decrease
|
||||||
|
|
||||||
@@ -24,9 +24,20 @@ function PlayerHandler.InitializePlayer(_, playerObj, isForced)
|
|||||||
PlayerHandler.modDataHandler:setup(isForced)
|
PlayerHandler.modDataHandler:setup(isForced)
|
||||||
PlayerHandler.playerObj = playerObj
|
PlayerHandler.playerObj = playerObj
|
||||||
|
|
||||||
|
-- Calculate amputated limbs at startup
|
||||||
|
PlayerHandler.amputatedLimbs = {}
|
||||||
|
|
||||||
|
for i=1, #StaticData.LIMBS_STRINGS do
|
||||||
|
local limbName = StaticData.LIMBS_STRINGS[i]
|
||||||
|
if PlayerHandler.modDataHandler:getIsCut(limbName) then
|
||||||
|
PlayerHandler.AddLocalAmputatedLimb(limbName)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Since isForced is used to reset an existing player data, we're gonna clean their ISHealthPanel table too
|
-- Since isForced is used to reset an existing player data, we're gonna clean their ISHealthPanel table too
|
||||||
if isForced then
|
if isForced then
|
||||||
ISHealthPanel.highestAmputations = {}
|
ISHealthPanel.highestAmputations = {}
|
||||||
|
local ItemsHandler = require("Handlers/TOC_ItemsHandler")
|
||||||
ItemsHandler.DeleteAllOldAmputationItems(playerObj)
|
ItemsHandler.DeleteAllOldAmputationItems(playerObj)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -34,11 +45,12 @@ end
|
|||||||
---Handles the traits
|
---Handles the traits
|
||||||
---@param playerObj IsoPlayer
|
---@param playerObj IsoPlayer
|
||||||
function PlayerHandler.ManageTraits(playerObj)
|
function PlayerHandler.ManageTraits(playerObj)
|
||||||
|
local AmputationHandler = require("Handlers/TOC_AmputationHandler")
|
||||||
for k, v in pairs(StaticData.TRAITS_BP) do
|
for k, v in pairs(StaticData.TRAITS_BP) do
|
||||||
if playerObj:HasTrait(k) then
|
if playerObj:HasTrait(k) then
|
||||||
-- Once we find one, we should be done.
|
-- Once we find one, we should be done.
|
||||||
local tempHandler = AmputationHandler:new(v)
|
local tempHandler = AmputationHandler:new(v)
|
||||||
tempHandler:executeForTrait()
|
tempHandler:execute(false) -- No damage
|
||||||
tempHandler:close()
|
tempHandler:close()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -46,6 +58,18 @@ function PlayerHandler.ManageTraits(playerObj)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---Cache the currently amputated limbs
|
||||||
|
---@param limbName string
|
||||||
|
function PlayerHandler.AddLocalAmputatedLimb(limbName)
|
||||||
|
print("TOC: added " .. limbName .. " to known amputated limbs")
|
||||||
|
table.insert(PlayerHandler.amputatedLimbs, limbName)
|
||||||
|
end
|
||||||
|
|
||||||
|
--* Getters *--
|
||||||
|
function PlayerHandler.GetAmputatedLimbs()
|
||||||
|
return PlayerHandler.amputatedLimbs or {}
|
||||||
|
end
|
||||||
|
|
||||||
--* Events *--
|
--* Events *--
|
||||||
|
|
||||||
---Check if the player has an infected (as in, zombie infection) body part
|
---Check if the player has an infected (as in, zombie infection) body part
|
||||||
@@ -100,20 +124,21 @@ function PlayerHandler.UpdatePerks(player)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Events.OnPlayerUpdate.Add(PlayerHandler.UpdatePerks)
|
--Events.OnPlayerUpdate.Add(PlayerHandler.UpdatePerks)
|
||||||
|
|
||||||
|
|
||||||
--* Some overrides *--
|
--* Some overrides *--
|
||||||
|
|
||||||
|
|
||||||
local og_ISBaseTimedAction_adjustMaxTime = ISBaseTimedAction.adjustMaxTime
|
local og_ISBaseTimedAction_adjustMaxTime = ISBaseTimedAction.adjustMaxTime
|
||||||
|
--- Adjust time
|
||||||
function ISBaseTimedAction:adjustMaxTime(maxTime)
|
function ISBaseTimedAction:adjustMaxTime(maxTime)
|
||||||
local time = og_ISBaseTimedAction_adjustMaxTime(self, maxTime)
|
local time = og_ISBaseTimedAction_adjustMaxTime(self, maxTime)
|
||||||
local modDataHandler = ModDataHandler.GetInstance()
|
local modDataHandler = ModDataHandler.GetInstance()
|
||||||
if time ~= -1 and modDataHandler and modDataHandler:getIsAnyLimbCut() then
|
if time ~= -1 and modDataHandler and modDataHandler:getIsAnyLimbCut() then
|
||||||
local pl = getPlayer()
|
local pl = getPlayer()
|
||||||
for i=1, #StaticData.LIMBS_STRINGS do
|
|
||||||
local limbName = StaticData.LIMBS_STRINGS[i]
|
for i=1, #PlayerHandler.amputatedLimbs do
|
||||||
|
local limbName = PlayerHandler.amputatedLimbs[i]
|
||||||
if modDataHandler:getIsCut(limbName) then
|
if modDataHandler:getIsCut(limbName) then
|
||||||
local perk = Perks["Side_" .. CommonMethods.GetSide(limbName)]
|
local perk = Perks["Side_" .. CommonMethods.GetSide(limbName)]
|
||||||
local perkLevel = pl:getPerkLevel(perk)
|
local perkLevel = pl:getPerkLevel(perk)
|
||||||
@@ -127,6 +152,7 @@ function ISBaseTimedAction:adjustMaxTime(maxTime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local og_ISBaseTimedAction_perform = ISBaseTimedAction.perform
|
local og_ISBaseTimedAction_perform = ISBaseTimedAction.perform
|
||||||
|
--- After each action, level up perks
|
||||||
function ISBaseTimedAction:perform()
|
function ISBaseTimedAction:perform()
|
||||||
og_ISBaseTimedAction_perform(self)
|
og_ISBaseTimedAction_perform(self)
|
||||||
|
|
||||||
@@ -142,7 +168,4 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return PlayerHandler
|
return PlayerHandler
|
||||||
@@ -2,8 +2,9 @@ IG_UI_EN = {
|
|||||||
IGUI_perks_Amputations = "Amputations",
|
IGUI_perks_Amputations = "Amputations",
|
||||||
IGUI_perks_Side_R = "Right Side",
|
IGUI_perks_Side_R = "Right Side",
|
||||||
IGUI_perks_Side_L = "Left Side",
|
IGUI_perks_Side_L = "Left Side",
|
||||||
|
|
||||||
IGUI_perks_Prosthesis = "Prosthesis",
|
IGUI_perks_Prosthesis = "Prosthesis",
|
||||||
IGUI_perks_ProstFamiliarity= "Familiarity",
|
IGUI_perks_ProstFamiliarity= "Familiarity",
|
||||||
|
|
||||||
|
IGUI_ItemCat_Prosthesis = "Prosthesis",
|
||||||
|
IGUI_ItemCat_Amputation = "Amputation"
|
||||||
}
|
}
|
||||||
BIN
media/textures/Item_genericAmputation.png
Normal file
BIN
media/textures/Item_genericAmputation.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 820 B |
Reference in New Issue
Block a user