refactor: restored new bodylocs

This commit is contained in:
ZioPao
2026-01-08 01:23:53 +01:00
parent 943e3a8f3c
commit 898e8ec653
5 changed files with 117 additions and 82 deletions

View File

@@ -1,74 +1,109 @@
require("TOC/Debug") --Based on RabenRabo's bodylocation solution from their mod "Fantasy Bodyparts" and "Fantasy Legs" sub-mod.
require("NPCs/BodyLocations") --Modified by GanydeBielovzki with permission for batch use for the Frockin' Splendor franchise and spin-offs.
local TOC = require("TOC/Registries") --To copy, further modify or otherwise use this code the original creator and the modifier must be credited.
local StaticData = require("TOC/StaticData")
local BodyLocationsAPI = {} local function copyBodyLocationProperties(oldGroup, oldLocID, newGroup)
local function customGetVal(obj, int) return getClassFieldVal(obj, getClassField(obj, int)) end for k = 0, oldGroup:size()-1 do
local group = BodyLocations.getGroup("Human") local otherLocID = oldGroup:getLocationByIndex(k):getId()
if oldGroup:isExclusive(oldLocID, otherLocID)
---@type ArrayList then
local list = customGetVal(group, 1) newGroup:setExclusive(oldLocID, otherLocID)
end
---@param bodyLoc string if oldGroup:isHideModel(oldLocID, otherLocID)
function BodyLocationsAPI.New(bodyLoc) then
curItem = group:getOrCreateLocation(bodyLoc) -- get current item - or create newGroup:setHideModel(oldLocID, otherLocID)
return curItem end
if oldGroup:isAltModel(oldLocID, otherLocID)
then
newGroup:setAltModel(oldLocID, otherLocID)
end
end
end end
-- TODO Not sure if this method actually works as intende with b42, but for our use case it's fine... local function addBodyLocationsAt(groupName, locationList)
---@param toRelocateOrCreate string local results = {}
---@param locationElement string
---@param afterBoolean boolean
---@return BodyLocation
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
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 = BodyLocationsAPI.New(toRelocateOrCreate) -- get list (!!actually a view!!) of all groups and copy to array (BodyLocations.reset() will also clear the view)
list:remove(curItem) -- remove from the list local allGroupsList = BodyLocations.getAllGroups()
local index = group:indexOf(locationElement) -- get current index after removal of the location to move to local allGroups = {}
if afterBoolean then index = index + 1 end -- if we want it after it, we increase the index to move to by one for i = 0, allGroupsList:size()-1 do
list:add(index, curItem) -- we add the item again allGroups[i + 1] = allGroupsList:get(i)
end
BodyLocations.reset()
return curItem -- recreate all groups/bodylocations and insert new bodylocations
else -- we did not find the location to move to, so we throw an error. for i = 1, #allGroups do
error("Could not find the BodyLocation [".. tostring(locationElement) .."] - please check the passed arguments!", 2) local oldGroup = allGroups[i]
end local newGroup = BodyLocations.getGroup(oldGroup:getId())
-- FIRST: Process all original locations AND insert new ones at correct positions
for j = 0, oldGroup:size()-1 do
local oldLoc = oldGroup:getLocationByIndex(j)
local oldLocID = oldLoc:getId()
-- For each location definition, check if it should be inserted here
for _, locDef in ipairs(locationList) do
if oldGroup:getId() == groupName then
local newLocID = type(locDef.name) ~= "string" and locDef.name or
ItemBodyLocation.get(ResourceLocation.of(locDef.name))
local refLocID = type(locDef.reference) ~= "string" and locDef.reference or
ResourceLocation.of(locDef.reference)
local isTargetGroupAndLoc = refLocID == oldLocID
if isTargetGroupAndLoc and locDef.before then
results[locDef.name] = newGroup:getOrCreateLocation(newLocID)
end
end
end
-- Add the original location
newGroup:getOrCreateLocation(oldLocID)
-- Check for "after" insertions
for _, locDef in ipairs(locationList) do
if oldGroup:getId() == groupName then
local newLocID = type(locDef.name) ~= "string" and locDef.name or
ItemBodyLocation.get(ResourceLocation.of(locDef.name))
local refLocID = type(locDef.reference) ~= "string" and locDef.reference or
ResourceLocation.of(locDef.reference)
local isTargetGroupAndLoc = refLocID == oldLocID
if isTargetGroupAndLoc and not locDef.before then
results[locDef.name] = newGroup:getOrCreateLocation(newLocID)
end
end
end
end
-- SECOND: copy bodylocation properties from old groups to new groups
for j = 0, oldGroup:size()-1 do
local oldLocID = oldGroup:getLocationByIndex(j):getId()
newGroup:setMultiItem(oldLocID, oldGroup:isMultiItem(oldLocID))
copyBodyLocationProperties(oldGroup, oldLocID, newGroup)
end
end
return results
end end
local results = addBodyLocationsAt("Human", {
{name = "toc:Arm_L", reference = ItemBodyLocation.FULL_TOP, before = false},
{name = "toc:Arm_R", reference = ItemBodyLocation.FULL_TOP, before = false},
{name = "toc:ArmProst_L", reference = ItemBodyLocation.FULL_TOP, before = false},
{name = "toc:ArmProst_R", reference = ItemBodyLocation.FULL_TOP, before = false},
{name = "toc:ArmAccessory_L", reference = ItemBodyLocation.FULL_TOP, before = false},
{name = "toc:ArmAccessory_R", reference = ItemBodyLocation.FULL_TOP, before = false},
})
-- function TestBodyLocations() results['toc:Arm_L']:setMultiItem(true)
-- local group = BodyLocations.getGroup("Human") results['toc:Arm_R']:setMultiItem(true)
-- local x = group:getAllLocations() results['toc:ArmProst_L']:setMultiItem(true)
results['toc:ArmProst_R']:setMultiItem(true)
-- for i=0, x:size() -1 do results['toc:ArmAccessory_L']:setMultiItem(true)
results['toc:ArmAccessory_R']:setMultiItem(true)
-- ---@type BodyLocation
-- local bl = x:get(i)
-- print(bl:getId())
-- end
-- end
-- MultiItem causes a ton of issues... fucking hell
-- local curItem = BodyLocation.new(group, "TOC_Arm_L")
-- group:getAllLocations():add(curItem)
-- local curItem = BodyLocation.new(group, "TOC_Arm_R")
-- group:getAllLocations():add(curItem)
BodyLocationsAPI.New(TOC.bodylocations.TOC_Arm_L)
BodyLocationsAPI.New(TOC.bodylocations.TOC_Arm_R)
BodyLocationsAPI.New(TOC.bodylocations.TOC_ArmProst_L)
BodyLocationsAPI.New(TOC.bodylocations.TOC_ArmProst_R)
BodyLocationsAPI.New(TOC.bodylocations.TOC_ArmAccessory_L)
BodyLocationsAPI.New(TOC.bodylocations.TOC_ArmAccessory_R)

View File

@@ -12,7 +12,7 @@ module TOC
hidden = true, hidden = true,
ClothingItem = Amputation_Hand_R, ClothingItem = Amputation_Hand_R,
BodyLocation = toc:TOC_Arm_R, BodyLocation = toc:Arm_R,
Weight = 0, Weight = 0,
CombatSpeedModifier = 0.9, CombatSpeedModifier = 0.9,
@@ -31,7 +31,7 @@ module TOC
hidden = true, hidden = true,
ClothingItem = Amputation_ForeArm_R, ClothingItem = Amputation_ForeArm_R,
BodyLocation = toc:TOC_Arm_R, BodyLocation = toc:Arm_R,
Weight = 0, Weight = 0,
CombatSpeedModifier = 0.8, CombatSpeedModifier = 0.8,
@@ -49,7 +49,7 @@ module TOC
hidden = true, hidden = true,
ClothingItem = Amputation_UpperArm_R, ClothingItem = Amputation_UpperArm_R,
BodyLocation = toc:TOC_Arm_R, BodyLocation = toc:Arm_R,
BloodLocation = UpperArms;UpperBody, BloodLocation = UpperArms;UpperBody,
Weight = 0, Weight = 0,
CombatSpeedModifier = 0.7, CombatSpeedModifier = 0.7,
@@ -66,7 +66,7 @@ module TOC
hidden = true, hidden = true,
ClothingItem = Amputation_Hand_L, ClothingItem = Amputation_Hand_L,
BodyLocation = toc:TOC_Arm_L, BodyLocation = toc:Arm_L,
Weight = 0, Weight = 0,
CombatSpeedModifier = 0.9, CombatSpeedModifier = 0.9,
@@ -85,7 +85,7 @@ module TOC
hidden = true, hidden = true,
ClothingItem = Amputation_ForeArm_L, ClothingItem = Amputation_ForeArm_L,
BodyLocation = toc:TOC_Arm_L, BodyLocation = toc:Arm_L,
Weight = 0, Weight = 0,
CombatSpeedModifier = 0.8, CombatSpeedModifier = 0.8,
@@ -104,7 +104,7 @@ module TOC
hidden = true, hidden = true,
ClothingItem = Amputation_UpperArm_L, ClothingItem = Amputation_UpperArm_L,
BodyLocation = toc:TOC_Arm_L, BodyLocation = toc:Arm_L,
Weight = 0, Weight = 0,
CombatSpeedModifier = 0.7, CombatSpeedModifier = 0.7,

View File

@@ -16,7 +16,7 @@ module TOC
ClothingItemExtra = Prost_HookArm_R, ClothingItemExtra = Prost_HookArm_R,
ClothingItemExtraOption = InstallProstRight, ClothingItemExtraOption = InstallProstRight,
clothingExtraSubmenu = InstallProstLeft, clothingExtraSubmenu = InstallProstLeft,
BodyLocation = toc:TOC_ArmProst_L, BodyLocation = toc:ArmProst_L,
Weight = 1.5, Weight = 1.5,
CombatSpeedModifier = 1.05, CombatSpeedModifier = 1.05,
BloodLocation = UpperArms;UpperBody, BloodLocation = UpperArms;UpperBody,
@@ -38,7 +38,7 @@ module TOC
ClothingItemExtra = Prost_HookArm_L, ClothingItemExtra = Prost_HookArm_L,
ClothingItemExtraOption = InstallProstLeft, ClothingItemExtraOption = InstallProstLeft,
clothingExtraSubmenu = InstallProstRight, clothingExtraSubmenu = InstallProstRight,
BodyLocation = toc:TOC_ArmProst_R, BodyLocation = toc:ArmProst_R,
Weight = 1.5, Weight = 1.5,
CombatSpeedModifier = 1.05, CombatSpeedModifier = 1.05,
BloodLocation = UpperArms;UpperBody, BloodLocation = UpperArms;UpperBody,
@@ -60,7 +60,7 @@ module TOC
ClothingItemExtra = Prost_NormalArm_R, ClothingItemExtra = Prost_NormalArm_R,
ClothingItemExtraOption = InstallProstRight, ClothingItemExtraOption = InstallProstRight,
clothingExtraSubmenu = InstallProstLeft, clothingExtraSubmenu = InstallProstLeft,
BodyLocation = toc:TOC_ArmProst_L, BodyLocation = toc:ArmProst_L,
Weight = 2, Weight = 2,
CombatSpeedModifier = 1.1, CombatSpeedModifier = 1.1,
BloodLocation = UpperArms;UpperBody, BloodLocation = UpperArms;UpperBody,
@@ -82,7 +82,7 @@ module TOC
ClothingItemExtra = Prost_NormalArm_L, ClothingItemExtra = Prost_NormalArm_L,
ClothingItemExtraOption = InstallProstLeft, ClothingItemExtraOption = InstallProstLeft,
clothingExtraSubmenu = InstallProstRight, clothingExtraSubmenu = InstallProstRight,
BodyLocation = toc:TOC_ArmProst_R, BodyLocation = toc:ArmProst_R,
Weight = 2, Weight = 2,
CombatSpeedModifier = 1.1, CombatSpeedModifier = 1.1,
BloodLocation = UpperArms;UpperBody, BloodLocation = UpperArms;UpperBody,

View File

@@ -15,7 +15,7 @@ module TOC
ClothingItemExtra = Surg_Arm_Tourniquet_R, ClothingItemExtra = Surg_Arm_Tourniquet_R,
ClothingItemExtraOption = PutTourniquetArmRight, ClothingItemExtraOption = PutTourniquetArmRight,
clothingExtraSubmenu = PutTourniquetArmLeft, clothingExtraSubmenu = PutTourniquetArmLeft,
BodyLocation = toc:TOC_ArmAccessory_L, BodyLocation = toc:ArmAccessory_L,
BloodLocation = UpperArms;UpperBody, BloodLocation = UpperArms;UpperBody,
Weight = 0.25, Weight = 0.25,
@@ -35,7 +35,7 @@ module TOC
ClothingItemExtra = Surg_Arm_Tourniquet_L, ClothingItemExtra = Surg_Arm_Tourniquet_L,
ClothingItemExtraOption = PutTourniquetArmLeft, ClothingItemExtraOption = PutTourniquetArmLeft,
clothingExtraSubmenu = PutTourniquetArmRight, clothingExtraSubmenu = PutTourniquetArmRight,
BodyLocation = toc:TOC_ArmAccessory_R, BodyLocation = toc:ArmAccessory_R,
BloodLocation = UpperArms;UpperBody, BloodLocation = UpperArms;UpperBody,
Weight = 0.25, Weight = 0.25,

View File

@@ -1,8 +1,8 @@
local BodyLocationsAPI = require("TOC/BodyLocations") local BodyLocationsAPI = require("TOC/BodyLocations")
BodyLocationsAPI.New("TOC_Arm_L") BodyLocationsAPI.New("Arm_L")
BodyLocationsAPI.New("TOC_Arm_R") BodyLocationsAPI.New("Arm_R")
BodyLocationsAPI.New("TOC_ArmProst_L") BodyLocationsAPI.New("ArmProst_L")
BodyLocationsAPI.New("TOC_ArmProst_R") BodyLocationsAPI.New("ArmProst_R")
BodyLocationsAPI.New("TOC_ArmAccessory_L") BodyLocationsAPI.New("ArmAccessory_L")
BodyLocationsAPI.New("TOC_ArmAccessory_R") BodyLocationsAPI.New("ArmAccessory_R")