From ead0ab4e138768154516380df9e8b6f3fda543d1 Mon Sep 17 00:00:00 2001 From: Xerxes-17 <123531217+Xerxes-17@users.noreply.github.com> Date: Sat, 20 Jan 2024 05:44:11 +1100 Subject: [PATCH] Add new armor collider info (#6) --- RatStash/Enums.cs | 48 ++++++++++++++ .../Equipment/ArmoredEquipment.cs | 25 +++++++ .../CompoundItem/SearchableItem/ChestRig.cs | 25 +++++++ RatStash/ItemFilter.cs | 12 ++++ RatStashTest/ArmorTest.cs | 66 +++++++++++++++++++ RatStashTest/TestEnvironment.cs | 2 +- 6 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 RatStashTest/ArmorTest.cs diff --git a/RatStash/Enums.cs b/RatStash/Enums.cs index 7f97f46..ff9212b 100644 --- a/RatStash/Enums.cs +++ b/RatStash/Enums.cs @@ -46,6 +46,54 @@ public enum ArmorType Heavy, } +public enum ArmorCollider +{ + BackHead, + Ears, + Eyes, + HeadCommon, + Jaw, + LeftCalf, + LeftForearm, + LeftSideChestDown, + LeftSideChestUp, + LeftThigh, + LeftUpperArm, + NeckBack, + NeckFront, + ParietalHead, + Pelvis, + PelvisBack, + RibcageLow, + RibcageUp, + RightCalf, + RightForearm, + RightSideChestDown, + RightSideChestUp, + RightThigh, + RightUpperArm, + SpineDown, + SpineTop +} + +public enum ArmorPlateCollider +{ + // NATO + Plate_Granit_SAPI_chest, + Plate_Granit_SAPI_back, + Plate_Granit_SSAPI_side_left_high, + Plate_Granit_SSAPI_side_left_low, + Plate_Granit_SSAPI_side_right_high, + Plate_Granit_SSAPI_side_right_low, + // RU + Plate_Korund_chest, + Plate_6B13_back, + Plate_Korund_side_left_high, + Plate_Korund_side_left_low, + Plate_Korund_side_right_high, + Plate_Korund_side_right_low +} + public enum ArmorZone { Chest, diff --git a/RatStash/Item/CompoundItem/Equipment/ArmoredEquipment.cs b/RatStash/Item/CompoundItem/Equipment/ArmoredEquipment.cs index fb37799..c2f59cc 100644 --- a/RatStash/Item/CompoundItem/Equipment/ArmoredEquipment.cs +++ b/RatStash/Item/CompoundItem/Equipment/ArmoredEquipment.cs @@ -54,6 +54,12 @@ public class ArmoredEquipment : Equipment [JsonProperty("headSegments", ItemConverterType = typeof(StringEnumConverter))] public List HeadSegments { get; set; } = new(); + [JsonProperty("armorColliders", ItemConverterType = typeof(StringEnumConverter))] + public List ArmorColliders { get; set; } = new(); + + [JsonProperty("armorPlateColliders", ItemConverterType = typeof(StringEnumConverter))] + public List ArmorPlateColliders { get; set; } = new(); + [JsonProperty("mousePenalty")] public int MousePenalty { get; set; } @@ -62,6 +68,25 @@ public class ArmoredEquipment : Equipment [JsonProperty("weaponErgonomicPenalty")] public int WeaponErgonomicPenalty { get; set; } + + public List GetArmorColliders() + { + List result = new List(); + foreach(var slot in Slots) + { + result.AddRange(slot.Filters[0].ArmorColliders); + } + return result; + } + public List GetArmorPlateColliders() + { + List result = new List(); + foreach(var slot in Slots) + { + result.AddRange(slot.Filters[0].ArmorPlateColliders); + } + return result; + } } public class RicochetParams diff --git a/RatStash/Item/CompoundItem/SearchableItem/ChestRig.cs b/RatStash/Item/CompoundItem/SearchableItem/ChestRig.cs index f2da23a..2a33317 100644 --- a/RatStash/Item/CompoundItem/SearchableItem/ChestRig.cs +++ b/RatStash/Item/CompoundItem/SearchableItem/ChestRig.cs @@ -31,6 +31,12 @@ public class ChestRig : SearchableItem [JsonProperty("armorZone", ItemConverterType = typeof(StringEnumConverter))] public List ArmorZone { get; set; } = new(); + [JsonProperty("armorColliders", ItemConverterType = typeof(StringEnumConverter))] + public List ArmorColliders { get; set; } = new(); + + [JsonProperty("armorPlateColliders", ItemConverterType = typeof(StringEnumConverter))] + public List ArmorPlateColliders { get; set; } = new(); + [JsonProperty("mousePenalty")] public int MousePenalty { get; set; } @@ -39,4 +45,23 @@ public class ChestRig : SearchableItem [JsonProperty("weaponErgonomicPenalty")] public int WeaponErgonomicPenalty { get; set; } + + public List GetArmorColliders() + { + List result = new List(); + foreach (var slot in Slots) + { + result.AddRange(slot.Filters[0].ArmorColliders); + } + return result; + } + public List GetArmorPlateColliders() + { + List result = new List(); + foreach (var slot in Slots) + { + result.AddRange(slot.Filters[0].ArmorPlateColliders); + } + return result; + } } diff --git a/RatStash/ItemFilter.cs b/RatStash/ItemFilter.cs index 0335cff..3ae4fa8 100644 --- a/RatStash/ItemFilter.cs +++ b/RatStash/ItemFilter.cs @@ -4,6 +4,18 @@ namespace RatStash; public class ItemFilter { + [JsonProperty("locked")] + public bool Locked { get; set; } = new(); + + [JsonProperty("Plate")] + public string PlateId { get; set; } = ""; + + [JsonProperty("armorColliders")] + public List ArmorColliders { get; set; } = new(); + + [JsonProperty("armorPlateColliders")] + public List ArmorPlateColliders { get; set; } = new(); + [JsonProperty("Filter")] public List Whitelist { get; set; } = new(); diff --git a/RatStashTest/ArmorTest.cs b/RatStashTest/ArmorTest.cs new file mode 100644 index 0000000..91f81c0 --- /dev/null +++ b/RatStashTest/ArmorTest.cs @@ -0,0 +1,66 @@ +using System.Collections.Generic; +using RatStash; +using Xunit; +using System.Linq; + +namespace RatStashTest; + +public class ArmorTest : TestEnvironment +{ + [Fact] + public void TestGettingArmorArmorRigPlateInserts() + { + var database = GetDatabase(); + var armor = database.GetItem("545cdb794bdc2d3a198b456a"); + var armorRig = database.GetItem("61bcc89aef0f505f0c6cd0fc"); + var plate = database.GetItem("6575ce3716c2762fba0057fd"); + var insert = database.GetItem("6570f71dd67d0309980a7af8"); + + var BuiltIns = database.GetItems(x => x is BuiltInInserts).ToList(); + + Assert.NotNull(armor); + Assert.NotNull(armorRig); + Assert.NotNull(plate); + Assert.NotNull(insert); + Assert.True(BuiltIns.Count > 0); + } + + [Fact] + public void TestAssembleArmor() + { + var database = GetDatabase(); + Armor item = (Armor) database.GetItem("545cdb794bdc2d3a198b456a"); + foreach(var slot in item.Slots) + { + var plate = database.GetItem(slot.Filters[0].PlateId); + Assert.NotNull(item); + slot.ContainedItem = plate; + } + Assert.NotNull(item); + + foreach(var slot in item.Slots) + { + Assert.NotNull(slot.ContainedItem); + } + } + [Fact] + public void TestGetArmorCollidersArmor() + { + var database = GetDatabase(); + Armor item = (Armor)database.GetItem("545cdb794bdc2d3a198b456a"); + var colliders = item.GetArmorColliders(); + var plateColliders = item.GetArmorPlateColliders(); + Assert.True(colliders.Count > 0); + Assert.True(plateColliders.Count > 0); + } + [Fact] + public void TestGetArmorCollidersRig() + { + var database = GetDatabase(); + ChestRig item = (ChestRig)database.GetItem("61bcc89aef0f505f0c6cd0fc"); + var colliders = item.GetArmorColliders(); + var plateColliders = item.GetArmorPlateColliders(); + Assert.True(colliders.Count > 0); + Assert.True(plateColliders.Count > 0); + } +} diff --git a/RatStashTest/TestEnvironment.cs b/RatStashTest/TestEnvironment.cs index edcec45..7f339f8 100644 --- a/RatStashTest/TestEnvironment.cs +++ b/RatStashTest/TestEnvironment.cs @@ -69,6 +69,6 @@ public Database GetDatabase(string locale = "en", bool cleaned = false) { var itemsPath = Combine(BasePath, "TestData\\items.json"); var localePath = Combine(BasePath, $"TestData\\locales\\{locale}.json"); - return Database.FromFile(itemsPath, cleaned, localePath).Filter(i => i.Name != "" && i.ShortName != ""); + return Database.FromFile(itemsPath, cleaned, localePath); } }