From 40fe46c1c6d7d06d0bd39b5233e457f800cb3c8d Mon Sep 17 00:00:00 2001 From: ZioPao Date: Tue, 19 Mar 2024 21:05:44 +0100 Subject: [PATCH] Big todos and double amputations for zombies --- .../client/TOC/Zombies/ZombiesAmputation.lua | 111 ++++++++++++------ media/lua/shared/TOC/BodyLocations.lua | 1 + media/lua/shared/TOC/StaticData.lua | 8 ++ 3 files changed, 87 insertions(+), 33 deletions(-) diff --git a/media/lua/client/TOC/Zombies/ZombiesAmputation.lua b/media/lua/client/TOC/Zombies/ZombiesAmputation.lua index e7669a4..9040709 100644 --- a/media/lua/client/TOC/Zombies/ZombiesAmputation.lua +++ b/media/lua/client/TOC/Zombies/ZombiesAmputation.lua @@ -9,6 +9,15 @@ local function PredicateAmputationItems(item) end + +local function PredicateAmputationItemLeft(item) + return item:getType():contains("Amputation_") and item:getType():contains("_L") +end + +local function PredicateAmputationItemRight(item) + return item:getType():contains("Amputation_") and item:getType():contains("_R") +end + ---@param zombie IsoZombie|IsoGameCharacter|IsoMovingObject|IsoObject ---@return integer trueID local function GetZombieID(zombie) @@ -25,69 +34,105 @@ local function GetZombieID(zombie) return trueID end -------------------------------- ---@param zombie IsoZombie -function HandleZombiesAmputations(zombie, character, bodyPartType, handWeapon) +local function SpawnAmputation(zombie, side) + local index = ZombRand(1, #StaticData.PARTS_STR) + local limb = StaticData.PARTS_STR[index] .. "_" .. side + local amputationFullType = StaticData.AMPUTATION_CLOTHING_ITEM_BASE .. limb + + + ItemsController.Zombie.SpawnAmputationItem(zombie, amputationFullType) + + + -- Add reference and transmit it to server + local pID = GetZombieID(zombie) + local zombieKey = CommandsData.GetZombieKey() + local zombiesMD = ModData.getOrCreate(zombieKey) + if zombiesMD[pID] == nil then zombiesMD[pID] = {} end + zombiesMD[pID][side] = amputationFullType + ModData.add(zombieKey, zombiesMD) + ModData.transmit(zombieKey) +end + +------------------------------- + +---@param player IsoGameCharacter +---@param zombie IsoZombie +function HandleZombiesAmputations(player, zombie, handWeapon, damage) + if not instanceof(zombie, "IsoZombie") or not instanceof(player, "IsoPlayer") then return end + if player ~= getPlayer() then return end + if damage < 3 or ZombRand(0,100) < 25 then return end + local zombieInv = zombie:getInventory() - local foundItem = zombieInv:containsEvalRecurse(PredicateAmputationItems) - if foundItem then - print("Item already in") + -- Check left or right + local leftItem = zombieInv:containsEval(PredicateAmputationItemLeft) + + if not leftItem then + SpawnAmputation(zombie, "L") return - else - - local clothingItemFullTypes = {} - -- Common function? - for i=1, #StaticData.LIMBS_STR do - local limbName = StaticData.LIMBS_STR[i] - local clothingName = StaticData.AMPUTATION_CLOTHING_ITEM_BASE .. limbName - table.insert(clothingItemFullTypes, clothingName) - end - - local index = ZombRand(1, #clothingItemFullTypes) - local amputationFullType = clothingItemFullTypes[index] + end - ItemsController.Zombie.SpawnAmputationItem(zombie, amputationFullType) - - - -- TODO Add reference and transmit it to server - local pID = GetZombieID(zombie) - local zombieKey = CommandsData.GetZombieKey() - local zombiesMD = ModData.getOrCreate(zombieKey) - zombiesMD[pID] = amputationFullType - ModData.add(zombieKey, zombiesMD) - ModData.transmit(zombieKey) + local rightItem = zombieInv:containsEval(PredicateAmputationItemRight) + if not rightItem then + SpawnAmputation(zombie, "R") + return end end -Events.OnHitZombie.Add(HandleZombiesAmputations) +Events.OnWeaponHitCharacter.Add(HandleZombiesAmputations) ----------------------------- +local localOnlyZombiesMD + +local function SetupZombiesModData() + local zombieKey = CommandsData.GetZombieKey() + localOnlyZombiesMD = ModData.getOrCreate(zombieKey) + +end + +Events.OnInitGlobalModData.Add(SetupZombiesModData) + + + ---@param zombie IsoZombie local function ReapplyAmputation(zombie) - local zombieKey = CommandsData.GetZombieKey() - local zombiesMD = ModData.getOrCreate(zombieKey) local pID = GetZombieID(zombie) -- TODO Remove already checked zombies - if zombiesMD[pID] ~= nil then + if localOnlyZombiesMD[pID] ~= nil then -- check if zombie has amputation - local fullType = zombiesMD[pID] + local zombiesAmpData = localOnlyZombiesMD[pID] local zombieInv = zombie:getInventory() local foundItem = zombieInv:containsEvalRecurse(PredicateAmputationItems) if foundItem then return else - AddZombieAmp(zombie, fullType) + local leftAmp = zombiesAmpData['L'] + if leftAmp then + ItemsController.Zombie.SpawnAmputationItem(zombie, leftAmp) + end + local rightAmp = zombiesAmpData['R'] + if rightAmp then + ItemsController.Zombie.SpawnAmputationItem(zombie, rightAmp) + end + + -- Removes reference, local only + localOnlyZombiesMD[pID] = nil end end end Events.OnZombieUpdate.Add(ReapplyAmputation) + + + + + diff --git a/media/lua/shared/TOC/BodyLocations.lua b/media/lua/shared/TOC/BodyLocations.lua index 2ffdaff..dcb27eb 100644 --- a/media/lua/shared/TOC/BodyLocations.lua +++ b/media/lua/shared/TOC/BodyLocations.lua @@ -12,6 +12,7 @@ require("TOC/Debug") local group = BodyLocations.getGroup("Human") -- TODO Breaks if both arms are cut with one prost!!! +-- TODO Breaks even if you have both amputations in general. We need a way to fix this piece of shit before realising group:getOrCreateLocation("TOC_Arm_R") group:getOrCreateLocation("TOC_Arm_L") diff --git a/media/lua/shared/TOC/StaticData.lua b/media/lua/shared/TOC/StaticData.lua index 518b150..224225e 100644 --- a/media/lua/shared/TOC/StaticData.lua +++ b/media/lua/shared/TOC/StaticData.lua @@ -24,6 +24,7 @@ StaticData.MOD_NAME = "TOC" ------------------------- --* Base + StaticData.SIDES_IND_STR = { R = "R", L = "L" @@ -33,6 +34,13 @@ StaticData.PARTS_IND_STR = { ForeArm = "ForeArm", UpperArm = "UpperArm" } +StaticData.PARTS_STR = { + "Hand", + "ForeArm", + "UpperArm" +} + + StaticData.MOD_BODYLOCS_BASE_IND_STR = { TOC_ArmProst = "TOC_ArmProst", TOC_Arm = "TOC_Arm",