Added basic stuff to handle zombie amputations

This commit is contained in:
ZioPao
2023-11-15 01:33:58 +01:00
parent a7d49c7253
commit 441fe67890
4 changed files with 106 additions and 16 deletions

View File

@@ -105,8 +105,8 @@ function AmputationHandler:execute(damagePlayer)
modDataHandler:apply() -- This will force rechecking the cached amputated limbs on the other client modDataHandler:apply() -- This will force rechecking the cached amputated limbs on the other client
-- Give the player the correct amputation item -- Give the player the correct amputation item
ItemsHandler.DeleteOldAmputationItem(self.patientPl, self.limbName) ItemsHandler.Player.DeleteOldAmputationItem(self.patientPl, self.limbName)
ItemsHandler.SpawnAmputationItem(self.patientPl, self.limbName) ItemsHandler.Player.SpawnAmputationItem(self.patientPl, self.limbName)
-- Add it to the list of cut limbs on this local client -- Add it to the list of cut limbs on this local client
local username = self.patientPl:getUsername() local username = self.patientPl:getUsername()

View File

@@ -6,11 +6,18 @@ local CommonMethods = require("TOC/CommonMethods")
---@class ItemsHandler ---@class ItemsHandler
local ItemsHandler = {} local ItemsHandler = {}
--* Player Methods *--
---@class ItemsHandler.Player
ItemsHandler.Player = {}
---Returns the correct index for the textures of the amputation ---Returns the correct index for the textures of the amputation
---@param playerObj IsoPlayer
---@param isCicatrized boolean ---@param isCicatrized boolean
---@return number ---@return number
---@private ---@private
function ItemsHandler.GetAmputationTexturesIndex(playerObj, isCicatrized) function ItemsHandler.Player.GetAmputationTexturesIndex(playerObj, isCicatrized)
local textureString = playerObj:getHumanVisual():getSkinTexture() local textureString = playerObj:getHumanVisual():getSkinTexture()
local isHairy = string.find(textureString, "a$") local isHairy = string.find(textureString, "a$")
-- Hairy bodies -- Hairy bodies
@@ -42,7 +49,7 @@ end
---@param clothingItem InventoryItem? ---@param clothingItem InventoryItem?
---@return boolean ---@return boolean
---@private ---@private
function ItemsHandler.RemoveClothingItem(playerObj, clothingItem) function ItemsHandler.Player.RemoveClothingItem(playerObj, clothingItem)
if clothingItem and instanceof(clothingItem, "InventoryItem") then if clothingItem and instanceof(clothingItem, "InventoryItem") then
playerObj:removeWornItem(clothingItem) playerObj:removeWornItem(clothingItem)
@@ -56,7 +63,7 @@ end
---Search and deletes an old amputation clothing item on the same side ---Search and deletes an old amputation clothing item on the same side
---@param playerObj IsoPlayer ---@param playerObj IsoPlayer
---@param limbName string ---@param limbName string
function ItemsHandler.DeleteOldAmputationItem(playerObj, limbName) function ItemsHandler.Player.DeleteOldAmputationItem(playerObj, limbName)
local side = CommonMethods.GetSide(limbName) local side = CommonMethods.GetSide(limbName)
for partName, _ in pairs(StaticData.PARTS_IND_STR) do for partName, _ in pairs(StaticData.PARTS_IND_STR) do
local othLimbName = partName .. "_" .. side local othLimbName = partName .. "_" .. side
@@ -74,7 +81,7 @@ end
---Deletes all the old amputation items, used for resets ---Deletes all the old amputation items, used for resets
---@param playerObj IsoPlayer ---@param playerObj IsoPlayer
function ItemsHandler.DeleteAllOldAmputationItems(playerObj) function ItemsHandler.Player.DeleteAllOldAmputationItems(playerObj)
for i=1, #StaticData.LIMBS_STR do for i=1, #StaticData.LIMBS_STR do
local limbName = StaticData.LIMBS_STR[i] local limbName = StaticData.LIMBS_STR[i]
@@ -86,7 +93,9 @@ function ItemsHandler.DeleteAllOldAmputationItems(playerObj)
end end
---Spawns and equips the correct amputation item to the player. ---Spawns and equips the correct amputation item to the player.
function ItemsHandler.SpawnAmputationItem(playerObj, limbName) ---@param playerObj IsoPlayer
---@param limbName string
function ItemsHandler.Player.SpawnAmputationItem(playerObj, limbName)
TOC_DEBUG.print("clothing name " .. StaticData.AMPUTATION_CLOTHING_ITEM_BASE .. limbName) TOC_DEBUG.print("clothing name " .. StaticData.AMPUTATION_CLOTHING_ITEM_BASE .. limbName)
local clothingItem = playerObj:getInventory():AddItem(StaticData.AMPUTATION_CLOTHING_ITEM_BASE .. limbName) local clothingItem = playerObj:getInventory():AddItem(StaticData.AMPUTATION_CLOTHING_ITEM_BASE .. limbName)
local texId = ItemsHandler.GetAmputationTexturesIndex(playerObj, false) local texId = ItemsHandler.GetAmputationTexturesIndex(playerObj, false)
@@ -96,6 +105,56 @@ function ItemsHandler.SpawnAmputationItem(playerObj, limbName)
playerObj:setWornItem(clothingItem:getBodyLocation(), clothingItem) playerObj:setWornItem(clothingItem:getBodyLocation(), clothingItem)
end end
--* Zombie Methods *--
---@class ItemsHandler.Zombie
ItemsHandler.Zombie = {}
---comment
---@param zombie IsoZombie
function ItemsHandler.Zombie.SpawnAmputationItem(zombie)
-- TODO Set texture ID
local itemVisualsList = zombie:getItemVisuals()
local ignoredLimbs = {}
if itemVisualsList == nil then return end
for i=0, itemVisualsList:size() - 1 do
local itemVisual = itemVisualsList:get(i)
-- TODO Check body location of item and deletes potential amputation to apply
local clothingName = itemVisual:getClothingItemName()
print(clothingName)
if clothingName and luautils.stringStarts(clothingName, StaticData.AMPUTATION_CLOTHING_ITEM_BASE) then
TOC_DEBUG.print("added " .. clothingName .. " to ignoredLimbs")
ignoredLimbs[clothingName] = clothingName
end
end
-- TODO COnsider highest amputation
local usableClothingAmputations = {}
for i=1, #StaticData.LIMBS_STR do
local limbName = StaticData.LIMBS_STR[i]
local clothingName = StaticData.AMPUTATION_CLOTHING_ITEM_BASE .. limbName
if ignoredLimbs[clothingName] == nil then
table.insert(usableClothingAmputations, clothingName)
end
end
-- TODO Random index
local index = ZombRand(1, #usableClothingAmputations)
local itemVisual = ItemVisual:new()
itemVisual:setItemType(usableClothingAmputations[index])
zombie:getItemVisuals():add(itemVisual)
zombie:resetModelNextFrame()
end
-------------------------- --------------------------
--* Overrides *-- --* Overrides *--

View File

@@ -33,7 +33,7 @@ function PlayerHandler.InitializePlayer(playerObj, isForced)
if isForced then if isForced then
--ISHealthPanel.highestAmputations = {} --ISHealthPanel.highestAmputations = {}
local ItemsHandler = require("TOC/Handlers/ItemsHandler") local ItemsHandler = require("TOC/Handlers/ItemsHandler")
ItemsHandler.DeleteAllOldAmputationItems(playerObj) ItemsHandler.Player.DeleteAllOldAmputationItems(playerObj)
CachedDataHandler.Reset(username) CachedDataHandler.Reset(username)
end end
end end
@@ -149,9 +149,16 @@ end
--* Equipping items overrides *-- --* Equipping items overrides *--
local equipPrimaryText = getText("ContextMenu_Equip_Primary")
local equipSecondaryText = getText("ContextMenu_Equip_Secondary")
local primaryHand = StaticData.PARTS_IND_STR.Hand .. "_" .. StaticData.SIDES_IND_STR.R
local secondaryHand = StaticData.PARTS_IND_STR.Hand .. "_" .. StaticData.SIDES_IND_STR.L
local og_ISEquipWeaponAction_isValid = ISEquipWeaponAction.isValid local og_ISEquipWeaponAction_isValid = ISEquipWeaponAction.isValid
---Add a condition to check the feasibility of having 2 handed weapons or if both arms are cut off ---Add a condition to check the feasibility of having 2 handed weapons or if both arms are cut off
---@return boolean ---@return boolean
---@diagnostic disable-next-line: duplicate-set-field
function ISEquipWeaponAction:isValid() function ISEquipWeaponAction:isValid()
local isValid = og_ISEquipWeaponAction_isValid(self) local isValid = og_ISEquipWeaponAction_isValid(self)
local modDataHandler = ModDataHandler.GetInstance(self.character:getUsername()) local modDataHandler = ModDataHandler.GetInstance(self.character:getUsername())
@@ -159,9 +166,22 @@ function ISEquipWeaponAction:isValid()
-- TODO We need to consider amputating legs, this won't be correct anymore -- TODO We need to consider amputating legs, this won't be correct anymore
-- TODO Consider prosthesis -- TODO Consider prosthesis
-- TODO Maybe isValid isn't the right choice, we want them to be able to equip weapons nonetheless but one handed
if modDataHandler:getIsCut("Hand_L") and modDataHandler:getIsCut("Hand_R") then -- Both hands are cut off
isValid = false if modDataHandler:getIsCut(primaryHand) and modDataHandler:getIsCut(secondaryHand) then
return false
end
-- Equip primary and no right hand
if self.jobType:contains(equipPrimaryText) and modDataHandler:getIsCut(primaryHand) then
TOC_DEBUG.print("Equip primary, no right hand, not valid")
return false
end
-- Equip secondary and no left hand
if self.jobType:contains(equipSecondaryText) and modDataHandler:getIsCut(secondaryHand) then
TOC_DEBUG.print("Equip secondary, no left hand, not valid")
return false
end end
end end
return isValid return isValid
@@ -171,7 +191,7 @@ end
---@class ISEquipWeaponAction ---@class ISEquipWeaponAction
---@field character IsoPlayer ---@field character IsoPlayer
---comment ---A recreation of the original method, but with amputations in mind
---@param modDataHandler ModDataHandler ---@param modDataHandler ModDataHandler
function ISEquipWeaponAction:performWithAmputation(modDataHandler) function ISEquipWeaponAction:performWithAmputation(modDataHandler)
local hand = nil local hand = nil
@@ -236,10 +256,10 @@ function ISEquipWeaponAction:performWithAmputation(modDataHandler)
setMethodFirst(self.character, self.item) setMethodFirst(self.character, self.item)
end end
end end
end end
local og_ISEquipWeaponAction_perform = ISEquipWeaponAction.perform local og_ISEquipWeaponAction_perform = ISEquipWeaponAction.perform
---@diagnostic disable-next-line: duplicate-set-field
function ISEquipWeaponAction:perform() function ISEquipWeaponAction:perform()
og_ISEquipWeaponAction_perform(self) og_ISEquipWeaponAction_perform(self)
@@ -253,7 +273,4 @@ function ISEquipWeaponAction:perform()
end end
-- TODO Limit 2 hands weapons and stuff like that
return PlayerHandler return PlayerHandler

View File

@@ -0,0 +1,14 @@
local ItemsHandler = require("TOC/Handlers/ItemsHandler")
--------------------
-- TODO This is low priority, work on it AFTER everything else is ok
-------------------
local function test(zombie, character, bodyPartType, handWeapon)
ItemsHandler.Zombie.SpawnAmputationItem(zombie)
end
Events.OnHitZombie.Add(test)