Added basic stuff to handle zombie amputations
This commit is contained in:
@@ -105,8 +105,8 @@ function AmputationHandler:execute(damagePlayer)
|
||||
modDataHandler:apply() -- This will force rechecking the cached amputated limbs on the other client
|
||||
|
||||
-- Give the player the correct amputation item
|
||||
ItemsHandler.DeleteOldAmputationItem(self.patientPl, self.limbName)
|
||||
ItemsHandler.SpawnAmputationItem(self.patientPl, self.limbName)
|
||||
ItemsHandler.Player.DeleteOldAmputationItem(self.patientPl, self.limbName)
|
||||
ItemsHandler.Player.SpawnAmputationItem(self.patientPl, self.limbName)
|
||||
|
||||
-- Add it to the list of cut limbs on this local client
|
||||
local username = self.patientPl:getUsername()
|
||||
|
||||
@@ -6,11 +6,18 @@ local CommonMethods = require("TOC/CommonMethods")
|
||||
---@class ItemsHandler
|
||||
local ItemsHandler = {}
|
||||
|
||||
|
||||
|
||||
--* Player Methods *--
|
||||
---@class ItemsHandler.Player
|
||||
ItemsHandler.Player = {}
|
||||
|
||||
---Returns the correct index for the textures of the amputation
|
||||
---@param playerObj IsoPlayer
|
||||
---@param isCicatrized boolean
|
||||
---@return number
|
||||
---@private
|
||||
function ItemsHandler.GetAmputationTexturesIndex(playerObj, isCicatrized)
|
||||
function ItemsHandler.Player.GetAmputationTexturesIndex(playerObj, isCicatrized)
|
||||
local textureString = playerObj:getHumanVisual():getSkinTexture()
|
||||
local isHairy = string.find(textureString, "a$")
|
||||
-- Hairy bodies
|
||||
@@ -42,7 +49,7 @@ end
|
||||
---@param clothingItem InventoryItem?
|
||||
---@return boolean
|
||||
---@private
|
||||
function ItemsHandler.RemoveClothingItem(playerObj, clothingItem)
|
||||
function ItemsHandler.Player.RemoveClothingItem(playerObj, clothingItem)
|
||||
if clothingItem and instanceof(clothingItem, "InventoryItem") then
|
||||
playerObj:removeWornItem(clothingItem)
|
||||
|
||||
@@ -56,7 +63,7 @@ end
|
||||
---Search and deletes an old amputation clothing item on the same side
|
||||
---@param playerObj IsoPlayer
|
||||
---@param limbName string
|
||||
function ItemsHandler.DeleteOldAmputationItem(playerObj, limbName)
|
||||
function ItemsHandler.Player.DeleteOldAmputationItem(playerObj, limbName)
|
||||
local side = CommonMethods.GetSide(limbName)
|
||||
for partName, _ in pairs(StaticData.PARTS_IND_STR) do
|
||||
local othLimbName = partName .. "_" .. side
|
||||
@@ -74,7 +81,7 @@ end
|
||||
|
||||
---Deletes all the old amputation items, used for resets
|
||||
---@param playerObj IsoPlayer
|
||||
function ItemsHandler.DeleteAllOldAmputationItems(playerObj)
|
||||
function ItemsHandler.Player.DeleteAllOldAmputationItems(playerObj)
|
||||
|
||||
for i=1, #StaticData.LIMBS_STR do
|
||||
local limbName = StaticData.LIMBS_STR[i]
|
||||
@@ -86,7 +93,9 @@ function ItemsHandler.DeleteAllOldAmputationItems(playerObj)
|
||||
end
|
||||
|
||||
---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)
|
||||
local clothingItem = playerObj:getInventory():AddItem(StaticData.AMPUTATION_CLOTHING_ITEM_BASE .. limbName)
|
||||
local texId = ItemsHandler.GetAmputationTexturesIndex(playerObj, false)
|
||||
@@ -96,6 +105,56 @@ function ItemsHandler.SpawnAmputationItem(playerObj, limbName)
|
||||
playerObj:setWornItem(clothingItem:getBodyLocation(), clothingItem)
|
||||
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 *--
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ function PlayerHandler.InitializePlayer(playerObj, isForced)
|
||||
if isForced then
|
||||
--ISHealthPanel.highestAmputations = {}
|
||||
local ItemsHandler = require("TOC/Handlers/ItemsHandler")
|
||||
ItemsHandler.DeleteAllOldAmputationItems(playerObj)
|
||||
ItemsHandler.Player.DeleteAllOldAmputationItems(playerObj)
|
||||
CachedDataHandler.Reset(username)
|
||||
end
|
||||
end
|
||||
@@ -149,9 +149,16 @@ end
|
||||
|
||||
--* 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
|
||||
---Add a condition to check the feasibility of having 2 handed weapons or if both arms are cut off
|
||||
---@return boolean
|
||||
---@diagnostic disable-next-line: duplicate-set-field
|
||||
function ISEquipWeaponAction:isValid()
|
||||
local isValid = og_ISEquipWeaponAction_isValid(self)
|
||||
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 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
|
||||
isValid = false
|
||||
|
||||
-- Both hands are cut off
|
||||
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
|
||||
return isValid
|
||||
@@ -171,7 +191,7 @@ end
|
||||
---@class ISEquipWeaponAction
|
||||
---@field character IsoPlayer
|
||||
|
||||
---comment
|
||||
---A recreation of the original method, but with amputations in mind
|
||||
---@param modDataHandler ModDataHandler
|
||||
function ISEquipWeaponAction:performWithAmputation(modDataHandler)
|
||||
local hand = nil
|
||||
@@ -236,10 +256,10 @@ function ISEquipWeaponAction:performWithAmputation(modDataHandler)
|
||||
setMethodFirst(self.character, self.item)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local og_ISEquipWeaponAction_perform = ISEquipWeaponAction.perform
|
||||
---@diagnostic disable-next-line: duplicate-set-field
|
||||
function ISEquipWeaponAction:perform()
|
||||
og_ISEquipWeaponAction_perform(self)
|
||||
|
||||
@@ -253,7 +273,4 @@ function ISEquipWeaponAction:perform()
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- TODO Limit 2 hands weapons and stuff like that
|
||||
|
||||
return PlayerHandler
|
||||
14
media/lua/client/TOC/Zombies/ZombiesAmputation.lua
Normal file
14
media/lua/client/TOC/Zombies/ZombiesAmputation.lua
Normal 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)
|
||||
Reference in New Issue
Block a user