Big todos and double amputations for zombies
This commit is contained in:
@@ -9,6 +9,15 @@ local function PredicateAmputationItems(item)
|
|||||||
end
|
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
|
---@param zombie IsoZombie|IsoGameCharacter|IsoMovingObject|IsoObject
|
||||||
---@return integer trueID
|
---@return integer trueID
|
||||||
local function GetZombieID(zombie)
|
local function GetZombieID(zombie)
|
||||||
@@ -25,69 +34,105 @@ local function GetZombieID(zombie)
|
|||||||
return trueID
|
return trueID
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------
|
|
||||||
|
|
||||||
---@param zombie IsoZombie
|
---@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 zombieInv = zombie:getInventory()
|
||||||
local foundItem = zombieInv:containsEvalRecurse(PredicateAmputationItems)
|
|
||||||
|
|
||||||
if foundItem then
|
-- Check left or right
|
||||||
print("Item already in")
|
local leftItem = zombieInv:containsEval(PredicateAmputationItemLeft)
|
||||||
|
|
||||||
|
if not leftItem then
|
||||||
|
SpawnAmputation(zombie, "L")
|
||||||
return
|
return
|
||||||
else
|
end
|
||||||
|
|
||||||
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]
|
|
||||||
|
|
||||||
|
|
||||||
ItemsController.Zombie.SpawnAmputationItem(zombie, amputationFullType)
|
local rightItem = zombieInv:containsEval(PredicateAmputationItemRight)
|
||||||
|
if not rightItem then
|
||||||
|
SpawnAmputation(zombie, "R")
|
||||||
-- TODO Add reference and transmit it to server
|
return
|
||||||
local pID = GetZombieID(zombie)
|
|
||||||
local zombieKey = CommandsData.GetZombieKey()
|
|
||||||
local zombiesMD = ModData.getOrCreate(zombieKey)
|
|
||||||
zombiesMD[pID] = amputationFullType
|
|
||||||
ModData.add(zombieKey, zombiesMD)
|
|
||||||
ModData.transmit(zombieKey)
|
|
||||||
end
|
end
|
||||||
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
|
---@param zombie IsoZombie
|
||||||
local function ReapplyAmputation(zombie)
|
local function ReapplyAmputation(zombie)
|
||||||
local zombieKey = CommandsData.GetZombieKey()
|
|
||||||
local zombiesMD = ModData.getOrCreate(zombieKey)
|
|
||||||
local pID = GetZombieID(zombie)
|
local pID = GetZombieID(zombie)
|
||||||
|
|
||||||
-- TODO Remove already checked zombies
|
-- TODO Remove already checked zombies
|
||||||
if zombiesMD[pID] ~= nil then
|
if localOnlyZombiesMD[pID] ~= nil then
|
||||||
-- check if zombie has amputation
|
-- check if zombie has amputation
|
||||||
local fullType = zombiesMD[pID]
|
local zombiesAmpData = localOnlyZombiesMD[pID]
|
||||||
local zombieInv = zombie:getInventory()
|
local zombieInv = zombie:getInventory()
|
||||||
local foundItem = zombieInv:containsEvalRecurse(PredicateAmputationItems)
|
local foundItem = zombieInv:containsEvalRecurse(PredicateAmputationItems)
|
||||||
|
|
||||||
if foundItem then
|
if foundItem then
|
||||||
return
|
return
|
||||||
else
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Events.OnZombieUpdate.Add(ReapplyAmputation)
|
Events.OnZombieUpdate.Add(ReapplyAmputation)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ require("TOC/Debug")
|
|||||||
local group = BodyLocations.getGroup("Human")
|
local group = BodyLocations.getGroup("Human")
|
||||||
|
|
||||||
-- TODO Breaks if both arms are cut with one prost!!!
|
-- 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_R")
|
||||||
group:getOrCreateLocation("TOC_Arm_L")
|
group:getOrCreateLocation("TOC_Arm_L")
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ StaticData.MOD_NAME = "TOC"
|
|||||||
-------------------------
|
-------------------------
|
||||||
--* Base
|
--* Base
|
||||||
|
|
||||||
|
|
||||||
StaticData.SIDES_IND_STR = {
|
StaticData.SIDES_IND_STR = {
|
||||||
R = "R",
|
R = "R",
|
||||||
L = "L"
|
L = "L"
|
||||||
@@ -33,6 +34,13 @@ StaticData.PARTS_IND_STR = {
|
|||||||
ForeArm = "ForeArm",
|
ForeArm = "ForeArm",
|
||||||
UpperArm = "UpperArm"
|
UpperArm = "UpperArm"
|
||||||
}
|
}
|
||||||
|
StaticData.PARTS_STR = {
|
||||||
|
"Hand",
|
||||||
|
"ForeArm",
|
||||||
|
"UpperArm"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
StaticData.MOD_BODYLOCS_BASE_IND_STR = {
|
StaticData.MOD_BODYLOCS_BASE_IND_STR = {
|
||||||
TOC_ArmProst = "TOC_ArmProst",
|
TOC_ArmProst = "TOC_ArmProst",
|
||||||
TOC_Arm = "TOC_Arm",
|
TOC_Arm = "TOC_Arm",
|
||||||
|
|||||||
Reference in New Issue
Block a user