< Summary

Information
Class: RaidLoop.Core.GameState
Assembly: RaidLoop.Core
File(s): /home/runner/work/RaidLoop/RaidLoop/src/RaidLoop.Core/Models.cs
Line coverage
100%
Covered lines: 4
Uncovered lines: 0
Coverable lines: 4
Total lines: 173
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Stash()100%11100%
.ctor(...)100%11100%

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{
 27254    public List<Item> Stash { get; } = [];
 55
 10656    public GameState(IEnumerable<Item> initialStash)
 57    {
 10658        Stash.AddRange(initialStash);
 10659    }
 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{
 95    public Item? EquippedWeapon { get; set; }
 96    public Item? EquippedArmor { get; set; }
 97    public Item? EquippedBackpack { get; set; }
 98    public List<Item> CarriedItems { get; } = [];
 99    public List<Item> DiscoveredLoot { get; } = [];
 100    public int MedkitCount { get; set; }
 101    public int BackpackCapacity { get; set; }
 102    public int MaxEncumbrance { get; set; } = CombatBalance.GetMaxEncumbranceFromStrength(PlayerStatRules.MinimumScore);
 103
 104    public IEnumerable<Item> GetExtractableItems()
 105    {
 106        if (EquippedWeapon is not null)
 107        {
 108            yield return EquippedWeapon;
 109        }
 110
 111        if (EquippedArmor is not null)
 112        {
 113            yield return EquippedArmor;
 114        }
 115
 116        if (EquippedBackpack is not null)
 117        {
 118            yield return EquippedBackpack;
 119        }
 120
 121        foreach (var item in CarriedItems)
 122        {
 123            yield return item;
 124        }
 125
 126        for (var i = 0; i < MedkitCount; i++)
 127        {
 128            yield return ItemCatalog.Create("Medkit");
 129        }
 130    }
 131
 132    public static RaidInventory FromItems(List<Item> broughtItems, List<Item> carriedItems, int backpackCapacity)
 133    {
 134        var inventory = new RaidInventory
 135        {
 136            EquippedWeapon = broughtItems.FirstOrDefault(x => x.Type == ItemType.Weapon),
 137            EquippedArmor = broughtItems.FirstOrDefault(x => x.Type == ItemType.Armor),
 138            EquippedBackpack = broughtItems.FirstOrDefault(x => x.Type == ItemType.Backpack),
 139            BackpackCapacity = backpackCapacity
 140        };
 141
 142        foreach (var item in broughtItems.Where(x => x.Type is not (ItemType.Weapon or ItemType.Armor or ItemType.Backpa
 143        {
 144            if (CombatBalance.IsMedkit(item))
 145            {
 146                inventory.MedkitCount++;
 147                continue;
 148            }
 149
 150            inventory.CarriedItems.Add(item);
 151        }
 152
 153        foreach (var item in carriedItems)
 154        {
 155            if (CombatBalance.IsMedkit(item))
 156            {
 157                inventory.MedkitCount++;
 158                continue;
 159            }
 160
 161            inventory.CarriedItems.Add(item);
 162        }
 163
 164        return inventory;
 165    }
 166}
 167
 168public sealed record OpeningPhaseResult(
 169    OpeningContactState ContactState,
 170    OpeningSide SurpriseSide,
 171    OpeningSide InitiativeWinner,
 172    int OpeningActionsRemaining,
 173    bool SurprisePersistenceEligible);