< Summary

Information
Class: RaidLoop.Core.RaidInventory
Assembly: RaidLoop.Core
File(s): /home/runner/work/RaidLoop/RaidLoop/src/RaidLoop.Core/Models.cs
Line coverage
83%
Covered lines: 31
Uncovered lines: 6
Coverable lines: 37
Total lines: 173
Line coverage: 83.7%
Branch coverage
75%
Covered branches: 15
Total branches: 20
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_EquippedWeapon()100%11100%
get_EquippedArmor()100%11100%
get_EquippedBackpack()100%11100%
get_CarriedItems()100%11100%
get_DiscoveredLoot()100%11100%
get_MedkitCount()100%11100%
get_BackpackCapacity()100%11100%
get_MaxEncumbrance()100%11100%
GetExtractableItems()100%1010100%
FromItems(...)50%141066.66%

File(s)

/home/runner/work/RaidLoop/RaidLoop/src/RaidLoop.Core/Models.cs

#LineLine coverage
 1using System.Text.Json.Serialization;
 2
 3namespace RaidLoop.Core;
 4
 5public enum ItemType
 6{
 7    Weapon,
 8    Armor,
 9    Backpack,
 10    Consumable,
 11    Sellable,
 12    Material
 13}
 14
 15public enum OpeningContactState
 16{
 17    MutualContact,
 18    PlayerAmbush,
 19    EnemyAmbush
 20}
 21
 22public enum OpeningSide
 23{
 24    None,
 25    Player,
 26    Enemy
 27}
 28
 29public sealed record OpeningPhaseContext(
 30    OpeningContactState ContactState,
 31    int PlayerInitiative,
 32    int EnemyInitiative,
 33    int TimeOfDayVisibilityModifier = 0,
 34    int EnvironmentAwarenessModifier = 0,
 35    int PlayerGearAwarenessModifier = 0,
 36    int EnemyLocalizationModifier = 0);
 37
 38[JsonConverter(typeof(ItemJsonConverter))]
 39public sealed record Item(
 40    string Name,
 41    ItemType Type,
 42    int Weight,
 43    int Value = 1,
 44    int Slots = 1,
 45    Rarity Rarity = Rarity.Common,
 46    DisplayRarity DisplayRarity = DisplayRarity.Common)
 47{
 48    [JsonPropertyName("itemDefId")]
 49    public int ItemDefId { get; init; }
 50}
 51
 52public sealed class GameState
 53{
 54    public List<Item> Stash { get; } = [];
 55
 56    public GameState(IEnumerable<Item> initialStash)
 57    {
 58        Stash.AddRange(initialStash);
 59    }
 60}
 61
 62public sealed class RaidState
 63{
 64    public int Health { get; set; }
 65    public int BackpackCapacity { get; set; }
 66    public int MaxEncumbrance
 67    {
 68        get => Inventory.MaxEncumbrance;
 69        set => Inventory.MaxEncumbrance = value;
 70    }
 71    public List<Item> BroughtItems { get; } = [];
 72    public RaidInventory Inventory { get; }
 73    public List<Item> RaidLoot => Inventory.CarriedItems;
 74    public bool IsDead => Health <= 0;
 75
 76    public RaidState(int health, int backpackCapacity, List<Item> broughtItems, List<Item> raidLoot)
 77    {
 78        Health = health;
 79        BackpackCapacity = backpackCapacity;
 80        BroughtItems = broughtItems;
 81        Inventory = RaidInventory.FromItems(broughtItems, raidLoot, backpackCapacity);
 82    }
 83
 84    public RaidState(int health, RaidInventory inventory)
 85    {
 86        Health = health;
 87        Inventory = inventory;
 88        BackpackCapacity = inventory.BackpackCapacity;
 89        BroughtItems = inventory.GetExtractableItems().ToList();
 90    }
 91}
 92
 93public sealed class RaidInventory
 94{
 20795    public Item? EquippedWeapon { get; set; }
 13396    public Item? EquippedArmor { get; set; }
 17997    public Item? EquippedBackpack { get; set; }
 19398    public List<Item> CarriedItems { get; } = [];
 13899    public List<Item> DiscoveredLoot { get; } = [];
 133100    public int MedkitCount { get; set; }
 133101    public int BackpackCapacity { get; set; }
 88102    public int MaxEncumbrance { get; set; } = CombatBalance.GetMaxEncumbranceFromStrength(PlayerStatRules.MinimumScore);
 103
 104    public IEnumerable<Item> GetExtractableItems()
 105    {
 50106        if (EquippedWeapon is not null)
 107        {
 36108            yield return EquippedWeapon;
 109        }
 110
 50111        if (EquippedArmor is not null)
 112        {
 4113            yield return EquippedArmor;
 114        }
 115
 50116        if (EquippedBackpack is not null)
 117        {
 29118            yield return EquippedBackpack;
 119        }
 120
 124121        foreach (var item in CarriedItems)
 122        {
 12123            yield return item;
 124        }
 125
 116126        for (var i = 0; i < MedkitCount; i++)
 127        {
 8128            yield return ItemCatalog.Create("Medkit");
 129        }
 50130    }
 131
 132    public static RaidInventory FromItems(List<Item> broughtItems, List<Item> carriedItems, int backpackCapacity)
 133    {
 46134        var inventory = new RaidInventory
 46135        {
 37136            EquippedWeapon = broughtItems.FirstOrDefault(x => x.Type == ItemType.Weapon),
 67137            EquippedArmor = broughtItems.FirstOrDefault(x => x.Type == ItemType.Armor),
 69138            EquippedBackpack = broughtItems.FirstOrDefault(x => x.Type == ItemType.Backpack),
 46139            BackpackCapacity = backpackCapacity
 46140        };
 141
 161142        foreach (var item in broughtItems.Where(x => x.Type is not (ItemType.Weapon or ItemType.Armor or ItemType.Backpa
 143        {
 0144            if (CombatBalance.IsMedkit(item))
 145            {
 0146                inventory.MedkitCount++;
 0147                continue;
 148            }
 149
 0150            inventory.CarriedItems.Add(item);
 151        }
 152
 126153        foreach (var item in carriedItems)
 154        {
 17155            if (CombatBalance.IsMedkit(item))
 156            {
 0157                inventory.MedkitCount++;
 0158                continue;
 159            }
 160
 17161            inventory.CarriedItems.Add(item);
 162        }
 163
 46164        return inventory;
 165    }
 166}
 167
 168public sealed record OpeningPhaseResult(
 169    OpeningContactState ContactState,
 170    OpeningSide SurpriseSide,
 171    OpeningSide InitiativeWinner,
 172    int OpeningActionsRemaining,
 173    bool SurprisePersistenceEligible);