fix: 42.12 new bodyloc

This commit is contained in:
ZioPao
2025-09-29 01:31:18 +02:00
parent 89a28e846a
commit 5ec0ec1a9b
2 changed files with 23 additions and 13 deletions

View File

@@ -1,5 +1,6 @@
require("TOC/Debug")
require("NPCs/BodyLocations")
local StaticData = require("TOC/StaticData")
local BodyLocationsAPI = {}
local function customGetVal(obj, int) return getClassFieldVal(obj, getClassField(obj, int)) end
@@ -8,6 +9,8 @@ local group = BodyLocations.getGroup("Human")
---@type ArrayList
local list = customGetVal(group, 1)
-- TODO Not sure if this method actually works as intende with b42, but for our use case it's fine...
---@param toRelocateOrCreate string
---@param locationElement string
---@param afterBoolean boolean
@@ -19,7 +22,15 @@ function BodyLocationsAPI.MoveOrCreateBeforeOrAfter(toRelocateOrCreate, location
if itemToMoveTo ~= nil then
-- Check type of arg 1 == string - if not, error out.
if type(toRelocateOrCreate) ~= "string" then error("Argument 1 is not of type string. Please re-check!", 2) end
local curItem = group:getOrCreateLocation(toRelocateOrCreate) -- get current item - or create
local curItem
if StaticData.COMPAT_42 then
curItem = BodyLocation.new(group, toRelocateOrCreate) -- create new item
group:getAllLocations():add(curItem) -- add to the list
else
curItem = group:getOrCreateLocation(toRelocateOrCreate) -- get current item - or create
end
list:remove(curItem) -- remove from the list
local index = group:indexOf(locationElement) -- get current index after removal of the location to move to
if afterBoolean then index = index + 1 end -- if we want it after it, we increase the index to move to by one
@@ -32,19 +43,18 @@ function BodyLocationsAPI.MoveOrCreateBeforeOrAfter(toRelocateOrCreate, location
end
end
function TestBodyLocations()
local group = BodyLocations.getGroup("Human")
local x = group:getAllLocations()
-- function TestBodyLocations()
-- local group = BodyLocations.getGroup("Human")
-- local x = group:getAllLocations()
for i=0, x:size() -1 do
-- for i=0, x:size() -1 do
---@type BodyLocation
local bl = x:get(i)
-- ---@type BodyLocation
-- local bl = x:get(i)
print(bl:getId())
end
end
-- print(bl:getId())
-- end
-- end
-- MultiItem causes a ton of issues... fucking hell