From 6e9e522731685a29bd1ae697f1cd95e5d9918393 Mon Sep 17 00:00:00 2001 From: ZioPao Date: Wed, 20 Mar 2024 00:27:00 +0100 Subject: [PATCH] BodyLocations should be FINALLY fine --- .../clothingItems/Amputation_ForeArm_L.xml | 8 +- .../clothingItems/Amputation_ForeArm_R.xml | 1 + .../TOC/Controllers/ItemsController.lua | 4 + media/lua/shared/TOC/BodyLocations.lua | 82 +++---------------- media/scripts/TOC_amputation_items.txt | 8 +- media/scripts/TOC_prosthesis_items.txt | 8 +- 6 files changed, 28 insertions(+), 83 deletions(-) diff --git a/media/clothing/clothingItems/Amputation_ForeArm_L.xml b/media/clothing/clothingItems/Amputation_ForeArm_L.xml index f7e96f1..1ca5f59 100644 --- a/media/clothing/clothingItems/Amputation_ForeArm_L.xml +++ b/media/clothing/clothingItems/Amputation_ForeArm_L.xml @@ -6,9 +6,11 @@ false false false - 3 - 4 - none + + 3 + 4 + + Amputations\Human\Forearm\skin01_b diff --git a/media/clothing/clothingItems/Amputation_ForeArm_R.xml b/media/clothing/clothingItems/Amputation_ForeArm_R.xml index 1cc12d0..73bf6b1 100644 --- a/media/clothing/clothingItems/Amputation_ForeArm_R.xml +++ b/media/clothing/clothingItems/Amputation_ForeArm_R.xml @@ -6,6 +6,7 @@ false false false + 5 6 diff --git a/media/lua/client/TOC/Controllers/ItemsController.lua b/media/lua/client/TOC/Controllers/ItemsController.lua index dd2cde6..8f217a1 100644 --- a/media/lua/client/TOC/Controllers/ItemsController.lua +++ b/media/lua/client/TOC/Controllers/ItemsController.lua @@ -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 diff --git a/media/lua/shared/TOC/BodyLocations.lua b/media/lua/shared/TOC/BodyLocations.lua index aa2af89..3778492 100644 --- a/media/lua/shared/TOC/BodyLocations.lua +++ b/media/lua/shared/TOC/BodyLocations.lua @@ -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) diff --git a/media/scripts/TOC_amputation_items.txt b/media/scripts/TOC_amputation_items.txt index 4ee608e..9c0d7b4 100644 --- a/media/scripts/TOC_amputation_items.txt +++ b/media/scripts/TOC_amputation_items.txt @@ -30,7 +30,7 @@ module TOC DisplayCategory = Amputation, ClothingItem = Amputation_ForeArm_R, - BodyLocation = TOC_Arm_R, + BodyLocation = TOC_Arm, Weight = 0, CombatSpeedModifier = 0.8, @@ -65,7 +65,7 @@ module TOC DisplayCategory = Amputation, ClothingItem = Amputation_Hand_L, - BodyLocation = TOC_Arm_L, + BodyLocation = TOC_Arm, Weight = 0, CombatSpeedModifier = 0.9, @@ -84,7 +84,7 @@ module TOC DisplayCategory = Amputation, ClothingItem = Amputation_ForeArm_L, - BodyLocation = TOC_Arm_L, + BodyLocation = TOC_Arm, Weight = 0, CombatSpeedModifier = 0.8, @@ -103,7 +103,7 @@ module TOC DisplayCategory = Amputation, ClothingItem = Amputation_UpperArm_L, - BodyLocation = TOC_Arm_L, + BodyLocation = TOC_Arm, Weight = 0, CombatSpeedModifier = 0.7, diff --git a/media/scripts/TOC_prosthesis_items.txt b/media/scripts/TOC_prosthesis_items.txt index 6bad195..6fb5ff9 100644 --- a/media/scripts/TOC_prosthesis_items.txt +++ b/media/scripts/TOC_prosthesis_items.txt @@ -16,7 +16,7 @@ module TOC ClothingItemExtra = Prost_HookArm_R, ClothingItemExtraOption = InstallProstRight, clothingExtraSubmenu = InstallProstLeft, - BodyLocation = TOC_ArmProst_L, + BodyLocation = TOC_ArmProst, Weight = 1.5, CombatSpeedModifier = 1.05, BloodLocation = UpperArms;UpperBody, @@ -38,7 +38,7 @@ module TOC ClothingItemExtra = Prost_HookArm_L, ClothingItemExtraOption = InstallProstLeft, clothingExtraSubmenu = InstallProstRight, - BodyLocation = TOC_ArmProst_R, + BodyLocation = TOC_ArmProst, Weight = 1.5, CombatSpeedModifier = 1.05, BloodLocation = UpperArms;UpperBody, @@ -60,7 +60,7 @@ module TOC ClothingItemExtra = Prost_NormalArm_R, ClothingItemExtraOption = InstallProstRight, clothingExtraSubmenu = InstallProstLeft, - BodyLocation = TOC_ArmProst_L, + BodyLocation = TOC_ArmProst, Weight = 2, CombatSpeedModifier = 1.1, BloodLocation = UpperArms;UpperBody, @@ -81,7 +81,7 @@ module TOC ClothingItemExtra = Prost_NormalArm_L, ClothingItemExtraOption = InstallProstLeft, clothingExtraSubmenu = InstallProstRight, - BodyLocation = TOC_ArmProst_R, + BodyLocation = TOC_ArmProst, Weight = 2, CombatSpeedModifier = 1.1, BloodLocation = UpperArms;UpperBody,