Working zombies amputation POC
This commit is contained in:
@@ -126,7 +126,7 @@ function ItemsController.Zombie.GetAmputationTexturesIndex(zombie)
|
|||||||
local level = tonumber(x:match("%d$")) - 1 -- it's from 1 to 3, but we're using it like 0 indexed arrays
|
local level = tonumber(x:match("%d$")) - 1 -- it's from 1 to 3, but we're using it like 0 indexed arrays
|
||||||
|
|
||||||
local finalId = 10 + matchedIndex + level
|
local finalId = 10 + matchedIndex + level
|
||||||
print("Zombie texture index: " .. tostring(finalId))
|
--print("Zombie texture index: " .. tostring(finalId))
|
||||||
return finalId
|
return finalId
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -143,8 +143,6 @@ local function AddInventoryAmputationMenu(playerNum, context, items)
|
|||||||
TOC_DEBUG.print("Bandage item: " .. tostring(bandageItem))
|
TOC_DEBUG.print("Bandage item: " .. tostring(bandageItem))
|
||||||
|
|
||||||
AddInvAmputationOptions(player, context, sawItem, stitchesItem, bandageItem)
|
AddInvAmputationOptions(player, context, sawItem, stitchesItem, bandageItem)
|
||||||
|
|
||||||
-- TODO Add stitches option and mixes
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,149 @@
|
|||||||
-- local ItemsController = require("TOC/Controllers/ItemsController")
|
local ItemsController = require("TOC/Controllers/ItemsController")
|
||||||
-- local StaticData = require("TOC/StaticData")
|
local StaticData = require("TOC/StaticData")
|
||||||
|
local CommandsData = require("TOC/CommandsData")
|
||||||
|
|
||||||
-- --------------------
|
|
||||||
|
|
||||||
-- This is low priority, work on it AFTER everything else is ok
|
local trackedZombies = {
|
||||||
|
[412412] = {
|
||||||
|
"FullTypeTest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
-- I doubt I can get this working, too many limitations
|
|
||||||
|
|
||||||
-- -------------------
|
local function predicate(item)
|
||||||
|
return (item:getType():contains("Amputation_"))
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param zombie IsoZombie|IsoGameCharacter|IsoMovingObject|IsoObject
|
||||||
|
---@return integer trueID
|
||||||
|
local function GetZombieID(zombie)
|
||||||
|
local pID = zombie:getPersistentOutfitID()
|
||||||
|
local bits = string.split(string.reverse(Long.toUnsignedString(pID, 2)), "")
|
||||||
|
while #bits < 16 do bits[#bits+1] = 0 end
|
||||||
|
|
||||||
|
-- trueID
|
||||||
|
bits[16] = 0
|
||||||
|
local trueID = Long.parseUnsignedLong(string.reverse(table.concat(bits, "")), 2)
|
||||||
|
|
||||||
|
return trueID
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
---@param zombie IsoZombie
|
||||||
|
---@param fullType string
|
||||||
|
local function AddZombieAmp(zombie, fullType)
|
||||||
|
local texId = ItemsController.Zombie.GetAmputationTexturesIndex(zombie)
|
||||||
|
local zombieVisuals = zombie:getItemVisuals()
|
||||||
|
local itemVisual = ItemVisual:new()
|
||||||
|
itemVisual:setItemType(fullType)
|
||||||
|
itemVisual:setTextureChoice(texId)
|
||||||
|
zombieVisuals:add(itemVisual)
|
||||||
|
zombie:resetModelNextFrame()
|
||||||
|
|
||||||
|
local zombieInv = zombie:getInventory()
|
||||||
|
zombieInv:AddItem(fullType)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
---@param zombie IsoZombie
|
||||||
|
function TestZombieThing(zombie)
|
||||||
|
local zombieInv = zombie:getInventory()
|
||||||
|
|
||||||
|
local foundItem = zombieInv:containsEvalRecurse(predicate)
|
||||||
|
|
||||||
|
if foundItem then
|
||||||
|
print("Item already in")
|
||||||
|
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 randomFullType = clothingItemFullTypes[index]
|
||||||
|
|
||||||
|
|
||||||
|
AddZombieAmp(zombie, randomFullType)
|
||||||
|
|
||||||
|
|
||||||
|
-- TODO Add reference and transmit it to server
|
||||||
|
local pID = GetZombieID(zombie)
|
||||||
|
local zombieKey = CommandsData.GetZombieKey()
|
||||||
|
local zombiesMD = ModData.getOrCreate(zombieKey)
|
||||||
|
zombiesMD[pID] = randomFullType
|
||||||
|
ModData.add(zombieKey, zombiesMD)
|
||||||
|
ModData.transmit(zombieKey)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
---@param zombie IsoZombie
|
||||||
|
---@param character any
|
||||||
|
---@param bodyPartType any
|
||||||
|
---@param handWeapon any
|
||||||
|
local function test(zombie, character, bodyPartType, handWeapon)
|
||||||
|
TestZombieThing(zombie)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Events.OnHitZombie.Add(test)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
---@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
|
||||||
|
-- check if zombie has amputation
|
||||||
|
local fullType = zombiesMD[pID]
|
||||||
|
local zombieInv = zombie:getInventory()
|
||||||
|
local foundItem = zombieInv:containsEvalRecurse(predicate)
|
||||||
|
|
||||||
|
if foundItem then
|
||||||
|
return
|
||||||
|
else
|
||||||
|
AddZombieAmp(zombie, fullType)
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Events.OnZombieUpdate.Add(ReapplyAmputation)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- ---@param zombie IsoZombie
|
-- ---@param zombie IsoZombie
|
||||||
@@ -96,4 +232,3 @@
|
|||||||
|
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
-- Events.OnHitZombie.Add(test)
|
|
||||||
@@ -35,5 +35,9 @@ function CommandsData.GetKey(username)
|
|||||||
return StaticData.MOD_NAME .. "_" .. username
|
return StaticData.MOD_NAME .. "_" .. username
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function CommandsData.GetZombieKey()
|
||||||
|
return StaticData.MOD_NAME .. "_ZOMBIES"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
return CommandsData
|
return CommandsData
|
||||||
|
|||||||
Reference in New Issue
Block a user