Skip to content

Commit

Permalink
Add new armor collider info (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xerxes-17 authored Jan 19, 2024
1 parent e66f2b6 commit ead0ab4
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 1 deletion.
48 changes: 48 additions & 0 deletions RatStash/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 25 additions & 0 deletions RatStash/Item/CompoundItem/Equipment/ArmoredEquipment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public class ArmoredEquipment : Equipment
[JsonProperty("headSegments", ItemConverterType = typeof(StringEnumConverter))]
public List<HeadSegment> HeadSegments { get; set; } = new();

[JsonProperty("armorColliders", ItemConverterType = typeof(StringEnumConverter))]
public List<ArmorCollider> ArmorColliders { get; set; } = new();

[JsonProperty("armorPlateColliders", ItemConverterType = typeof(StringEnumConverter))]
public List<ArmorCollider> ArmorPlateColliders { get; set; } = new();

[JsonProperty("mousePenalty")]
public int MousePenalty { get; set; }

Expand All @@ -62,6 +68,25 @@ public class ArmoredEquipment : Equipment

[JsonProperty("weaponErgonomicPenalty")]
public int WeaponErgonomicPenalty { get; set; }

public List<ArmorCollider> GetArmorColliders()
{
List<ArmorCollider> result = new List<ArmorCollider>();
foreach(var slot in Slots)
{
result.AddRange(slot.Filters[0].ArmorColliders);
}
return result;
}
public List<ArmorPlateCollider> GetArmorPlateColliders()
{
List<ArmorPlateCollider> result = new List<ArmorPlateCollider>();
foreach(var slot in Slots)
{
result.AddRange(slot.Filters[0].ArmorPlateColliders);
}
return result;
}
}

public class RicochetParams
Expand Down
25 changes: 25 additions & 0 deletions RatStash/Item/CompoundItem/SearchableItem/ChestRig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public class ChestRig : SearchableItem
[JsonProperty("armorZone", ItemConverterType = typeof(StringEnumConverter))]
public List<ArmorZone> ArmorZone { get; set; } = new();

[JsonProperty("armorColliders", ItemConverterType = typeof(StringEnumConverter))]
public List<ArmorCollider> ArmorColliders { get; set; } = new();

[JsonProperty("armorPlateColliders", ItemConverterType = typeof(StringEnumConverter))]
public List<ArmorCollider> ArmorPlateColliders { get; set; } = new();

[JsonProperty("mousePenalty")]
public int MousePenalty { get; set; }

Expand All @@ -39,4 +45,23 @@ public class ChestRig : SearchableItem

[JsonProperty("weaponErgonomicPenalty")]
public int WeaponErgonomicPenalty { get; set; }

public List<ArmorCollider> GetArmorColliders()
{
List<ArmorCollider> result = new List<ArmorCollider>();
foreach (var slot in Slots)
{
result.AddRange(slot.Filters[0].ArmorColliders);
}
return result;
}
public List<ArmorPlateCollider> GetArmorPlateColliders()
{
List<ArmorPlateCollider> result = new List<ArmorPlateCollider>();
foreach (var slot in Slots)
{
result.AddRange(slot.Filters[0].ArmorPlateColliders);
}
return result;
}
}
12 changes: 12 additions & 0 deletions RatStash/ItemFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArmorCollider> ArmorColliders { get; set; } = new();

[JsonProperty("armorPlateColliders")]
public List<ArmorPlateCollider> ArmorPlateColliders { get; set; } = new();

[JsonProperty("Filter")]
public List<string> Whitelist { get; set; } = new();

Expand Down
66 changes: 66 additions & 0 deletions RatStashTest/ArmorTest.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 1 addition & 1 deletion RatStashTest/TestEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit ead0ab4

Please sign in to comment.