BodyLocations should be FINALLY fine

This commit is contained in:
ZioPao
2024-03-20 00:27:00 +01:00
parent 509f03f2ef
commit 6e9e522731
6 changed files with 28 additions and 83 deletions

View File

@@ -44,6 +44,10 @@ function ItemsController.Player.RemoveClothingItem(playerObj, clothingItem)
playerObj:getInventory():Remove(clothingItem) -- Can be a InventoryItem too.. I guess? todo check it
TOC_DEBUG.print("found and deleted" .. tostring(clothingItem))
-- Reset model
playerObj:resetModelNextFrame()
return true
end
return false

View File

@@ -1,17 +1,18 @@
-- TODO This part is still one of the weakest and we don't have a better solution yet
require("TOC/Debug")
require("NPCs/BodyLocations")
local BodyLocationsAPI = {}
local function customGetVal(obj, int) return getClassFieldVal(obj, getClassField(obj, int)) end
local group = BodyLocations.getGroup("Human")
---@type ArrayList
local list = customGetVal(group, 1)
---@param toRelocateOrCreate string
---@param locationElement string
---@param afterBoolean boolean
---@return BodyLocation
function BodyLocationsAPI:moveOrCreateBeforeOrAfter(toRelocateOrCreate, locationElement, afterBoolean)
function BodyLocationsAPI.MoveOrCreateBeforeOrAfter(toRelocateOrCreate, locationElement, afterBoolean)
-- Check type of arg 2 == string - if not error out.
if type(locationElement) ~= "string" then error("Argument 2 is not of type string. Please re-check!", 2) end
local itemToMoveTo = group:getLocation(locationElement) -- get location to move to
@@ -23,74 +24,14 @@ function BodyLocationsAPI:moveOrCreateBeforeOrAfter(toRelocateOrCreate, location
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
list:add(index, curItem) -- we add the item again
return curItem
else -- we did not find the location to move to, so we throw an error.
error("Could not find the BodyLocation [",locationElement,"] - please check the passed arguments!", 2)
error("Could not find the BodyLocation [".. tostring(locationElement) .."] - please check the passed arguments!", 2)
end
end
---@param toRelocateOrCreate string
---@param locationElement string
---@return BodyLocation
function BodyLocationsAPI.moveOrCreateBefore(toRelocateOrCreate, locationElement) -- for simpler and clearer usage
return BodyLocationsAPI.moveOrCreateBeforeOrAfter(toRelocateOrCreate, locationElement, false)
end
---@param toRelocateOrCreate string
---@param locationElement string
---@return BodyLocation
function BodyLocationsAPI.moveOrCreateAfter(toRelocateOrCreate, locationElement) -- for simpler and clearer usage
return BodyLocationsAPI.moveOrCreateBeforeOrAfter(toRelocateOrCreate, locationElement, true)
end
---@param loc1 string
---@param alias string
---@return BodyLocation
function BodyLocationsAPI.removeAlias(loc1, alias) -- will remove 2nd arg (alias) from location 1
local item = group:getLocation(loc1)
if item ~= nil and type(alias) == "string" then
local aliases = customGetVal(item, 2)
aliases:remove(alias)
end
return item
end
---@param loc1 string
---@param loc2 string
---@return BodyLocation
function BodyLocationsAPI.unsetExclusive(loc1, loc2) -- will remove exclusive from each other
local item1 = group:getLocation(loc1)
local item2 = group:getLocation(loc2)
if item1 ~= nil and item2 ~= nil then
local exclusives1 = customGetVal(item1, 3)
exclusives1:remove(loc2)
local exclusives2 = customGetVal(item2, 3)
exclusives2:remove(loc1)
end
return item1
end
---@param loc1 string
---@param loc2 string
---@return BodyLocation
function BodyLocationsAPI.unhideModel(loc1, loc2) -- remove loc2 from loc1's hidemodel list
local item1 = group:getLocation(loc1)
local item2 = group:getLocation(loc2)
if item1 ~= nil and item2 ~= nil then
local hidemodels = customGetVal(item1, 4)
hidemodels:remove(loc2)
end
return item1
end
-- AddBodyLocationBefore("TOC_Arm_R", "Shoes")
-- AddBodyLocationBefore("TOC_Arm_L", "Shoes")
-- AddBodyLocationBefore("TOC_ArmProst_R", "TOC_Arm_R")
-- AddBodyLocationBefore("TOC_ArmProst_L", "TOC_Arm_L")
-- Locations must be declared in render-order.
-- Location IDs must match BodyLocation= and CanBeEquipped= values in items.txt.
function TestBodyLocations()
local group = BodyLocations.getGroup("Human")
local x = group:getAllLocations()
@@ -105,12 +46,9 @@ function TestBodyLocations()
end
local locationArm = BodyLocationsAPI.MoveOrCreateBeforeOrAfter("TOC_Arm", "FullTop", true)
locationArm:setMultiItem(true)
-- 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")
group:getOrCreateLocation("TOC_ArmProst_R")
group:getOrCreateLocation("TOC_ArmProst_L")
local locationArmProst = BodyLocationsAPI.MoveOrCreateBeforeOrAfter("TOC_ArmProst", "TOC_Arm", true)
locationArmProst:setMultiItem(true)