< Summary

Information
Class: RaidLoop.Core.ItemCatalog
Assembly: RaidLoop.Core
File(s): /home/runner/work/RaidLoop/RaidLoop/src/RaidLoop.Core/ItemCatalog.cs
Line coverage
98%
Covered lines: 237
Uncovered lines: 4
Coverable lines: 241
Total lines: 346
Line coverage: 98.3%
Branch coverage
90%
Covered branches: 39
Total branches: 43
Branch coverage: 90.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
Get(...)100%11100%
GetByItemDefId(...)50%2266.66%
GetByLegacyName(...)50%2266.66%
TryGet(...)100%11100%
TryGetByLegacyName(...)100%22100%
TryResolveAuthoredItem(...)100%44100%
TryGetByItemDefId(...)100%22100%
GetLookupToken(...)92%252592.85%
Create(...)100%11100%
CreateLegacy(...)100%11100%
RegisterAuthored(...)100%22100%
RegisterCanonical(...)100%22100%
RegisterAlias(...)100%22100%

File(s)

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

#LineLine coverage
 1namespace RaidLoop.Core;
 2
 3public static class ItemCatalog
 4{
 15    private static readonly Dictionary<int, Item> ItemsById = [];
 16    private static readonly Dictionary<string, Item> LegacyNames = new(StringComparer.OrdinalIgnoreCase);
 7
 8    static ItemCatalog()
 9    {
 110        RegisterCanonical(new Item("Rusty Knife", ItemType.Weapon, Value: 1, Slots: 1, Rarity: Rarity.Common, DisplayRar
 111        {
 112            ItemDefId = 1
 113        }, "rusty_knife");
 14
 115        RegisterAuthored(
 116            itemDefId: 2,
 117            displayName: "Makarov",
 118            itemType: ItemType.Weapon,
 119            weight: 2,
 120            value: 60,
 121            rarity: Rarity.Common,
 122            displayRarity: DisplayRarity.Common,
 123            aliases: ["makarov", "Light Pistol"]);
 24
 125        RegisterAuthored(
 126            itemDefId: 3,
 127            displayName: "PPSH",
 128            itemType: ItemType.Weapon,
 129            weight: 12,
 130            value: 160,
 131            rarity: Rarity.Uncommon,
 132            displayRarity: DisplayRarity.Uncommon,
 133            aliases: ["ppsh", "Drum SMG"]);
 34
 135        RegisterAuthored(
 136            itemDefId: 4,
 137            displayName: "AK74",
 138            itemType: ItemType.Weapon,
 139            weight: 7,
 140            value: 320,
 141            rarity: Rarity.Rare,
 142            displayRarity: DisplayRarity.Rare,
 143            aliases: ["ak74", "Field Carbine", "Hunting Rifle", "Compact Carbine"]);
 44
 145        RegisterAuthored(
 146            itemDefId: 5,
 147            displayName: "AK47",
 148            itemType: ItemType.Weapon,
 149            weight: 10,
 150            value: 375,
 151            rarity: Rarity.Rare,
 152            displayRarity: DisplayRarity.Rare,
 153            aliases: ["ak47", "Battle Rifle", "Sawed Shotgun"]);
 54
 155        RegisterAuthored(
 156            itemDefId: 6,
 157            displayName: "SVDS",
 158            itemType: ItemType.Weapon,
 159            weight: 10,
 160            value: 550,
 161            rarity: Rarity.Epic,
 162            displayRarity: DisplayRarity.Epic,
 163            aliases: ["svds", "Marksman Rifle"]);
 64
 165        RegisterAuthored(
 166            itemDefId: 7,
 167            displayName: "PKP",
 168            itemType: ItemType.Weapon,
 169            weight: 18,
 170            value: 800,
 171            rarity: Rarity.Legendary,
 172            displayRarity: DisplayRarity.Legendary,
 173            aliases: ["pkp", "Support Machine Gun"]);
 74
 175        RegisterAuthored(
 176            itemDefId: 8,
 177            displayName: "6B2 body armor",
 178            itemType: ItemType.Armor,
 179            weight: 9,
 180            value: 95,
 181            rarity: Rarity.Common,
 182            displayRarity: DisplayRarity.Common,
 183            aliases: ["6b2_body_armor", "Soft Armor Vest", "Soft Vest"]);
 84
 185        RegisterAuthored(
 186            itemDefId: 9,
 187            displayName: "BNTI Kirasa-N",
 188            itemType: ItemType.Armor,
 189            weight: 7,
 190            value: 160,
 191            rarity: Rarity.Uncommon,
 192            displayRarity: DisplayRarity.Uncommon,
 193            aliases: ["bnti_kirasa_n", "Reinforced Vest"]);
 94
 195        RegisterAuthored(
 196            itemDefId: 10,
 197            displayName: "6B13 assault armor",
 198            itemType: ItemType.Armor,
 199            weight: 7,
 1100            value: 225,
 1101            rarity: Rarity.Rare,
 1102            displayRarity: DisplayRarity.Rare,
 1103            aliases: ["6b13_assault_armor", "Light Plate Carrier", "Plate Carrier"]);
 104
 1105        RegisterAuthored(
 1106            itemDefId: 11,
 1107            displayName: "FORT Defender-2",
 1108            itemType: ItemType.Armor,
 1109            weight: 22,
 1110            value: 375,
 1111            rarity: Rarity.Epic,
 1112            displayRarity: DisplayRarity.Epic,
 1113            aliases: ["fort_defender_2", "Medium Plate Carrier"]);
 114
 1115        RegisterAuthored(
 1116            itemDefId: 12,
 1117            displayName: "6B43 Zabralo-Sh body armor",
 1118            itemType: ItemType.Armor,
 1119            weight: 28,
 1120            value: 450,
 1121            rarity: Rarity.Legendary,
 1122            displayRarity: DisplayRarity.Legendary,
 1123            aliases: ["6b43_zabralo_sh_body_armor", "Heavy Plate Carrier"]);
 124
 1125        RegisterAuthored(
 1126            itemDefId: 13,
 1127            displayName: "NFM THOR",
 1128            itemType: ItemType.Armor,
 1129            weight: 19,
 1130            value: 650,
 1131            rarity: Rarity.Legendary,
 1132            displayRarity: DisplayRarity.Legendary,
 1133            aliases: ["nfm_thor", "Assault Plate Carrier"]);
 134
 1135        RegisterCanonical(new Item("Small Backpack", ItemType.Backpack, Value: 25, Slots: 1, Rarity: Rarity.Common, Disp
 1136        {
 1137            ItemDefId = 14
 1138        }, "small_backpack");
 1139        RegisterAuthored(
 1140            itemDefId: 15,
 1141            displayName: "Large Backpack",
 1142            itemType: ItemType.Backpack,
 1143            weight: 1,
 1144            value: 50,
 1145            rarity: Rarity.Uncommon,
 1146            displayRarity: DisplayRarity.Uncommon,
 1147            aliases: ["large_backpack"]);
 1148        RegisterCanonical(new Item("Tactical Backpack", ItemType.Backpack, Value: 75, Slots: 2, Rarity: Rarity.Rare, Dis
 1149        {
 1150            ItemDefId = 16
 1151        }, "tactical_backpack");
 1152        RegisterAuthored(
 1153            itemDefId: 17,
 1154            displayName: "Tasmanian Tiger Trooper 35",
 1155            itemType: ItemType.Backpack,
 1156            weight: 2,
 1157            value: 400,
 1158            rarity: Rarity.Epic,
 1159            displayRarity: DisplayRarity.Epic,
 1160            aliases: ["tasmanian_tiger_trooper_35", "Hiking Backpack"]);
 1161        RegisterAuthored(
 1162            itemDefId: 18,
 1163            displayName: "6Sh118",
 1164            itemType: ItemType.Backpack,
 1165            weight: 8,
 1166            value: 600,
 1167            rarity: Rarity.Legendary,
 1168            displayRarity: DisplayRarity.Legendary,
 1169            aliases: ["6sh118", "Raid Backpack"]);
 170
 1171        RegisterCanonical(new Item("Medkit", ItemType.Consumable, Value: 30, Slots: 1, Rarity: Rarity.Common, DisplayRar
 1172        {
 1173            ItemDefId = 19
 1174        }, "medkit");
 1175        RegisterCanonical(new Item("Bandage", ItemType.Sellable, Value: 15, Slots: 1, Rarity: Rarity.Common, DisplayRari
 1176        {
 1177            ItemDefId = 20
 1178        }, "bandage");
 1179        RegisterCanonical(new Item("Ammo Box", ItemType.Sellable, Value: 20, Slots: 1, Rarity: Rarity.Common, DisplayRar
 1180        {
 1181            ItemDefId = 21
 1182        }, "ammo_box");
 1183        RegisterCanonical(new Item("Scrap Metal", ItemType.Material, Value: 18, Slots: 1, Rarity: Rarity.Common, Display
 1184        {
 1185            ItemDefId = 22
 1186        }, "scrap_metal");
 1187        RegisterCanonical(new Item("Rare Scope", ItemType.Material, Value: 80, Slots: 1, Rarity: Rarity.Rare, DisplayRar
 1188        {
 1189            ItemDefId = 23
 1190        }, "rare_scope");
 1191        RegisterCanonical(new Item("Legendary Trigger Group", ItemType.Material, Value: 150, Slots: 1, Rarity: Rarity.Le
 1192        {
 1193            ItemDefId = 24
 1194        }, "legendary_trigger_group");
 1195    }
 196
 197    public static Item Get(string name)
 198    {
 160199        return GetByLegacyName(name);
 200    }
 201
 202    public static Item GetByItemDefId(int itemDefId)
 203    {
 9204        if (!TryGetByItemDefId(itemDefId, out var item))
 205        {
 0206            throw new KeyNotFoundException($"No authored item definition exists for itemDefId '{itemDefId}'.");
 207        }
 208
 9209        return item!;
 210    }
 211
 212    public static Item GetByLegacyName(string name)
 213    {
 432214        if (!TryGetByLegacyName(name, out var item))
 215        {
 0216            throw new KeyNotFoundException($"No authored item definition exists for '{name}'.");
 217        }
 218
 432219        return item!;
 220    }
 221
 222    // Legacy compatibility lookup. New code should prefer TryGetByItemDefId/Create.
 223    public static bool TryGet(string name, out Item? item)
 224    {
 209225        return TryGetByLegacyName(name, out item);
 226    }
 227
 228    public static bool TryGetByLegacyName(string name, out Item? item)
 229    {
 641230        if (string.IsNullOrWhiteSpace(name))
 231        {
 3232            item = null;
 3233            return false;
 234        }
 235
 638236        return LegacyNames.TryGetValue(name, out item);
 237    }
 238
 239    public static bool TryResolveAuthoredItem(int itemDefId, out Item? item)
 240    {
 26241        if (TryGetByItemDefId(itemDefId, out item) && item is not null)
 242        {
 12243            return true;
 244        }
 245
 14246        item = null;
 14247        return false;
 248    }
 249
 250    public static bool TryGetByItemDefId(int itemDefId, out Item? item)
 251    {
 154252        if (itemDefId <= 0)
 253        {
 12254            item = null;
 12255            return false;
 256        }
 257
 142258        return ItemsById.TryGetValue(itemDefId, out item);
 259    }
 260
 261    public static string GetLookupToken(int itemDefId)
 262    {
 243263        return itemDefId switch
 243264        {
 6265            1 => "rusty_knife",
 24266            2 => "makarov",
 21267            3 => "ppsh",
 69268            4 => "ak74",
 16269            5 => "ak47",
 12270            6 => "svds",
 12271            7 => "pkp",
 11272            8 => "6b2_body_armor",
 7273            9 => "bnti_kirasa_n",
 8274            10 => "6b13_assault_armor",
 4275            11 => "fort_defender_2",
 3276            12 => "6b43_zabralo_sh_body_armor",
 3277            13 => "nfm_thor",
 11278            14 => "small_backpack",
 8279            15 => "large_backpack",
 2280            16 => "tactical_backpack",
 3281            17 => "tasmanian_tiger_trooper_35",
 5282            18 => "6sh118",
 11283            19 => "medkit",
 3284            20 => "bandage",
 2285            21 => "ammo_box",
 1286            22 => "scrap_metal",
 1287            23 => "rare_scope",
 0288            24 => "legendary_trigger_group",
 0289            _ => string.Empty
 243290        };
 291    }
 292
 293    public static Item Create(string name)
 294    {
 272295        return CreateLegacy(name);
 296    }
 297
 298    public static Item CreateLegacy(string name)
 299    {
 272300        return GetByLegacyName(name) with { };
 301    }
 302
 303    private static void RegisterAuthored(
 304        int itemDefId,
 305        string displayName,
 306        ItemType itemType,
 307        int weight,
 308        int value,
 309        Rarity rarity,
 310        DisplayRarity displayRarity,
 311        params string[] aliases)
 312    {
 15313        var item = new Item(displayName, itemType, Weight: weight, Value: value, Slots: 1, Rarity: rarity, DisplayRarity
 15314        {
 15315            ItemDefId = itemDefId
 15316        };
 317
 15318        RegisterCanonical(item);
 319
 98320        foreach (var alias in aliases)
 321        {
 34322            RegisterAlias(alias, item);
 323        }
 15324    }
 325
 326    private static void RegisterCanonical(Item item, params string[] aliases)
 327    {
 24328        ItemsById[item.ItemDefId] = item;
 24329        LegacyNames[item.Name] = item;
 330
 66331        foreach (var alias in aliases)
 332        {
 9333            RegisterAlias(alias, item);
 334        }
 24335    }
 336
 337    private static void RegisterAlias(string alias, Item item)
 338    {
 43339        if (LegacyNames.ContainsKey(alias))
 340        {
 9341            return;
 342        }
 343
 34344        LegacyNames[alias] = item with { Name = alias };
 34345    }
 346}