| | | 1 | | namespace RaidLoop.Core; |
| | | 2 | | |
| | | 3 | | public static class ItemCatalog |
| | | 4 | | { |
| | 1 | 5 | | private static readonly Dictionary<int, Item> ItemsById = []; |
| | 1 | 6 | | private static readonly Dictionary<string, Item> ItemsByKey = new(StringComparer.OrdinalIgnoreCase); |
| | | 7 | | // Legacy label aliases stay as a compatibility bridge while the app moves to key-first lookups. |
| | 1 | 8 | | private static readonly Dictionary<string, Item> LegacyNames = new(StringComparer.OrdinalIgnoreCase); |
| | | 9 | | |
| | | 10 | | static ItemCatalog() |
| | | 11 | | { |
| | 1 | 12 | | RegisterCanonical(new Item("Rusty Knife", ItemType.Weapon, Value: 1, Slots: 1, Rarity: Rarity.Common, DisplayRar |
| | 1 | 13 | | { |
| | 1 | 14 | | ItemDefId = 1, |
| | 1 | 15 | | Key = "rusty_knife" |
| | 1 | 16 | | }); |
| | | 17 | | |
| | 1 | 18 | | RegisterAuthored( |
| | 1 | 19 | | itemDefId: 2, |
| | 1 | 20 | | key: "makarov", |
| | 1 | 21 | | displayName: "Makarov", |
| | 1 | 22 | | itemType: ItemType.Weapon, |
| | 1 | 23 | | weight: 2, |
| | 1 | 24 | | value: 60, |
| | 1 | 25 | | rarity: Rarity.Common, |
| | 1 | 26 | | displayRarity: DisplayRarity.Common, |
| | 1 | 27 | | aliases: ["Light Pistol"]); |
| | | 28 | | |
| | 1 | 29 | | RegisterAuthored( |
| | 1 | 30 | | itemDefId: 3, |
| | 1 | 31 | | key: "ppsh", |
| | 1 | 32 | | displayName: "PPSH", |
| | 1 | 33 | | itemType: ItemType.Weapon, |
| | 1 | 34 | | weight: 12, |
| | 1 | 35 | | value: 160, |
| | 1 | 36 | | rarity: Rarity.Uncommon, |
| | 1 | 37 | | displayRarity: DisplayRarity.Uncommon, |
| | 1 | 38 | | aliases: ["Drum SMG"]); |
| | | 39 | | |
| | 1 | 40 | | RegisterAuthored( |
| | 1 | 41 | | itemDefId: 4, |
| | 1 | 42 | | key: "ak74", |
| | 1 | 43 | | displayName: "AK74", |
| | 1 | 44 | | itemType: ItemType.Weapon, |
| | 1 | 45 | | weight: 7, |
| | 1 | 46 | | value: 320, |
| | 1 | 47 | | rarity: Rarity.Rare, |
| | 1 | 48 | | displayRarity: DisplayRarity.Rare, |
| | 1 | 49 | | aliases: ["Field Carbine"]); |
| | | 50 | | |
| | 1 | 51 | | RegisterAuthored( |
| | 1 | 52 | | itemDefId: 5, |
| | 1 | 53 | | key: "ak47", |
| | 1 | 54 | | displayName: "AK47", |
| | 1 | 55 | | itemType: ItemType.Weapon, |
| | 1 | 56 | | weight: 10, |
| | 1 | 57 | | value: 375, |
| | 1 | 58 | | rarity: Rarity.Rare, |
| | 1 | 59 | | displayRarity: DisplayRarity.Rare, |
| | 1 | 60 | | aliases: ["Battle Rifle"]); |
| | | 61 | | |
| | 1 | 62 | | RegisterAuthored( |
| | 1 | 63 | | itemDefId: 6, |
| | 1 | 64 | | key: "svds", |
| | 1 | 65 | | displayName: "SVDS", |
| | 1 | 66 | | itemType: ItemType.Weapon, |
| | 1 | 67 | | weight: 10, |
| | 1 | 68 | | value: 550, |
| | 1 | 69 | | rarity: Rarity.Epic, |
| | 1 | 70 | | displayRarity: DisplayRarity.Epic, |
| | 1 | 71 | | aliases: ["Marksman Rifle"]); |
| | | 72 | | |
| | 1 | 73 | | RegisterAuthored( |
| | 1 | 74 | | itemDefId: 7, |
| | 1 | 75 | | key: "pkp", |
| | 1 | 76 | | displayName: "PKP", |
| | 1 | 77 | | itemType: ItemType.Weapon, |
| | 1 | 78 | | weight: 18, |
| | 1 | 79 | | value: 800, |
| | 1 | 80 | | rarity: Rarity.Legendary, |
| | 1 | 81 | | displayRarity: DisplayRarity.Legendary, |
| | 1 | 82 | | aliases: ["Support Machine Gun"]); |
| | | 83 | | |
| | 1 | 84 | | RegisterAuthored( |
| | 1 | 85 | | itemDefId: 8, |
| | 1 | 86 | | key: "6b2_body_armor", |
| | 1 | 87 | | displayName: "6B2 body armor", |
| | 1 | 88 | | itemType: ItemType.Armor, |
| | 1 | 89 | | weight: 9, |
| | 1 | 90 | | value: 95, |
| | 1 | 91 | | rarity: Rarity.Common, |
| | 1 | 92 | | displayRarity: DisplayRarity.Common, |
| | 1 | 93 | | aliases: ["Soft Armor Vest"]); |
| | | 94 | | |
| | 1 | 95 | | RegisterAuthored( |
| | 1 | 96 | | itemDefId: 9, |
| | 1 | 97 | | key: "bnti_kirasa_n", |
| | 1 | 98 | | displayName: "BNTI Kirasa-N", |
| | 1 | 99 | | itemType: ItemType.Armor, |
| | 1 | 100 | | weight: 7, |
| | 1 | 101 | | value: 160, |
| | 1 | 102 | | rarity: Rarity.Uncommon, |
| | 1 | 103 | | displayRarity: DisplayRarity.Uncommon, |
| | 1 | 104 | | aliases: ["Reinforced Vest"]); |
| | | 105 | | |
| | 1 | 106 | | RegisterAuthored( |
| | 1 | 107 | | itemDefId: 10, |
| | 1 | 108 | | key: "6b13_assault_armor", |
| | 1 | 109 | | displayName: "6B13 assault armor", |
| | 1 | 110 | | itemType: ItemType.Armor, |
| | 1 | 111 | | weight: 7, |
| | 1 | 112 | | value: 225, |
| | 1 | 113 | | rarity: Rarity.Rare, |
| | 1 | 114 | | displayRarity: DisplayRarity.Rare, |
| | 1 | 115 | | aliases: ["Light Plate Carrier"]); |
| | | 116 | | |
| | 1 | 117 | | RegisterAuthored( |
| | 1 | 118 | | itemDefId: 11, |
| | 1 | 119 | | key: "fort_defender_2", |
| | 1 | 120 | | displayName: "FORT Defender-2", |
| | 1 | 121 | | itemType: ItemType.Armor, |
| | 1 | 122 | | weight: 22, |
| | 1 | 123 | | value: 375, |
| | 1 | 124 | | rarity: Rarity.Epic, |
| | 1 | 125 | | displayRarity: DisplayRarity.Epic, |
| | 1 | 126 | | aliases: ["Medium Plate Carrier"]); |
| | | 127 | | |
| | 1 | 128 | | RegisterAuthored( |
| | 1 | 129 | | itemDefId: 12, |
| | 1 | 130 | | key: "6b43_zabralo_sh_body_armor", |
| | 1 | 131 | | displayName: "6B43 Zabralo-Sh body armor", |
| | 1 | 132 | | itemType: ItemType.Armor, |
| | 1 | 133 | | weight: 28, |
| | 1 | 134 | | value: 450, |
| | 1 | 135 | | rarity: Rarity.Legendary, |
| | 1 | 136 | | displayRarity: DisplayRarity.Legendary, |
| | 1 | 137 | | aliases: ["Heavy Plate Carrier"]); |
| | | 138 | | |
| | 1 | 139 | | RegisterAuthored( |
| | 1 | 140 | | itemDefId: 13, |
| | 1 | 141 | | key: "nfm_thor", |
| | 1 | 142 | | displayName: "NFM THOR", |
| | 1 | 143 | | itemType: ItemType.Armor, |
| | 1 | 144 | | weight: 19, |
| | 1 | 145 | | value: 650, |
| | 1 | 146 | | rarity: Rarity.Legendary, |
| | 1 | 147 | | displayRarity: DisplayRarity.Legendary, |
| | 1 | 148 | | aliases: ["Assault Plate Carrier"]); |
| | | 149 | | |
| | 1 | 150 | | RegisterCanonical(new Item("Small Backpack", ItemType.Backpack, Value: 25, Slots: 1, Rarity: Rarity.Common, Disp |
| | 1 | 151 | | { |
| | 1 | 152 | | ItemDefId = 14, |
| | 1 | 153 | | Key = "small_backpack" |
| | 1 | 154 | | }); |
| | 1 | 155 | | RegisterAuthored( |
| | 1 | 156 | | itemDefId: 15, |
| | 1 | 157 | | key: "large_backpack", |
| | 1 | 158 | | displayName: "Large Backpack", |
| | 1 | 159 | | itemType: ItemType.Backpack, |
| | 1 | 160 | | weight: 1, |
| | 1 | 161 | | value: 50, |
| | 1 | 162 | | rarity: Rarity.Uncommon, |
| | 1 | 163 | | displayRarity: DisplayRarity.Uncommon); |
| | 1 | 164 | | RegisterCanonical(new Item("Tactical Backpack", ItemType.Backpack, Value: 75, Slots: 2, Rarity: Rarity.Rare, Dis |
| | 1 | 165 | | { |
| | 1 | 166 | | ItemDefId = 16, |
| | 1 | 167 | | Key = "tactical_backpack" |
| | 1 | 168 | | }); |
| | 1 | 169 | | RegisterAuthored( |
| | 1 | 170 | | itemDefId: 17, |
| | 1 | 171 | | key: "tasmanian_tiger_trooper_35", |
| | 1 | 172 | | displayName: "Tasmanian Tiger Trooper 35", |
| | 1 | 173 | | itemType: ItemType.Backpack, |
| | 1 | 174 | | weight: 2, |
| | 1 | 175 | | value: 400, |
| | 1 | 176 | | rarity: Rarity.Epic, |
| | 1 | 177 | | displayRarity: DisplayRarity.Epic, |
| | 1 | 178 | | aliases: ["Hiking Backpack"]); |
| | 1 | 179 | | RegisterAuthored( |
| | 1 | 180 | | itemDefId: 18, |
| | 1 | 181 | | key: "6sh118", |
| | 1 | 182 | | displayName: "6Sh118", |
| | 1 | 183 | | itemType: ItemType.Backpack, |
| | 1 | 184 | | weight: 8, |
| | 1 | 185 | | value: 600, |
| | 1 | 186 | | rarity: Rarity.Legendary, |
| | 1 | 187 | | displayRarity: DisplayRarity.Legendary, |
| | 1 | 188 | | aliases: ["Raid Backpack"]); |
| | | 189 | | |
| | 1 | 190 | | RegisterCanonical(new Item("Medkit", ItemType.Consumable, Value: 30, Slots: 1, Rarity: Rarity.Common, DisplayRar |
| | 1 | 191 | | { |
| | 1 | 192 | | ItemDefId = 19, |
| | 1 | 193 | | Key = "medkit" |
| | 1 | 194 | | }); |
| | 1 | 195 | | RegisterCanonical(new Item("Bandage", ItemType.Sellable, Value: 15, Slots: 1, Rarity: Rarity.Common, DisplayRari |
| | 1 | 196 | | { |
| | 1 | 197 | | ItemDefId = 20, |
| | 1 | 198 | | Key = "bandage" |
| | 1 | 199 | | }); |
| | 1 | 200 | | RegisterCanonical(new Item("Ammo Box", ItemType.Sellable, Value: 20, Slots: 1, Rarity: Rarity.Common, DisplayRar |
| | 1 | 201 | | { |
| | 1 | 202 | | ItemDefId = 21, |
| | 1 | 203 | | Key = "ammo_box" |
| | 1 | 204 | | }); |
| | 1 | 205 | | RegisterCanonical(new Item("Scrap Metal", ItemType.Material, Value: 18, Slots: 1, Rarity: Rarity.Common, Display |
| | 1 | 206 | | { |
| | 1 | 207 | | ItemDefId = 22, |
| | 1 | 208 | | Key = "scrap_metal" |
| | 1 | 209 | | }); |
| | 1 | 210 | | RegisterCanonical(new Item("Rare Scope", ItemType.Material, Value: 80, Slots: 1, Rarity: Rarity.Rare, DisplayRar |
| | 1 | 211 | | { |
| | 1 | 212 | | ItemDefId = 23, |
| | 1 | 213 | | Key = "rare_scope" |
| | 1 | 214 | | }); |
| | 1 | 215 | | RegisterCanonical(new Item("Legendary Trigger Group", ItemType.Material, Value: 150, Slots: 1, Rarity: Rarity.Le |
| | 1 | 216 | | { |
| | 1 | 217 | | ItemDefId = 24, |
| | 1 | 218 | | Key = "legendary_trigger_group" |
| | 1 | 219 | | }); |
| | 1 | 220 | | } |
| | | 221 | | |
| | | 222 | | public static Item Get(string name) |
| | | 223 | | { |
| | 130 | 224 | | return GetByLegacyName(name); |
| | | 225 | | } |
| | | 226 | | |
| | | 227 | | public static Item GetByKey(string key) |
| | | 228 | | { |
| | 127 | 229 | | if (!TryGetByKey(key, out var item)) |
| | | 230 | | { |
| | 0 | 231 | | throw new KeyNotFoundException($"No authored item definition exists for key '{key}'."); |
| | | 232 | | } |
| | | 233 | | |
| | 127 | 234 | | return item!; |
| | | 235 | | } |
| | | 236 | | |
| | | 237 | | public static Item GetByItemDefId(int itemDefId) |
| | | 238 | | { |
| | 9 | 239 | | if (!TryGetByItemDefId(itemDefId, out var item)) |
| | | 240 | | { |
| | 0 | 241 | | throw new KeyNotFoundException($"No authored item definition exists for itemDefId '{itemDefId}'."); |
| | | 242 | | } |
| | | 243 | | |
| | 9 | 244 | | return item!; |
| | | 245 | | } |
| | | 246 | | |
| | | 247 | | public static Item GetByLegacyName(string name) |
| | | 248 | | { |
| | 290 | 249 | | if (!TryGetByLegacyName(name, out var item)) |
| | | 250 | | { |
| | 0 | 251 | | throw new KeyNotFoundException($"No authored item definition exists for '{name}'."); |
| | | 252 | | } |
| | | 253 | | |
| | 290 | 254 | | return item!; |
| | | 255 | | } |
| | | 256 | | |
| | | 257 | | // Legacy compatibility lookup. New code should prefer TryGetByKey/CreateByKey. |
| | | 258 | | public static bool TryGet(string name, out Item? item) |
| | | 259 | | { |
| | 213 | 260 | | return TryGetByLegacyName(name, out item); |
| | | 261 | | } |
| | | 262 | | |
| | | 263 | | public static bool TryGetByLegacyName(string name, out Item? item) |
| | | 264 | | { |
| | 515 | 265 | | if (string.IsNullOrWhiteSpace(name)) |
| | | 266 | | { |
| | 3 | 267 | | item = null; |
| | 3 | 268 | | return false; |
| | | 269 | | } |
| | | 270 | | |
| | 512 | 271 | | if (TryGetByKey(name, out item)) |
| | | 272 | | { |
| | 347 | 273 | | return true; |
| | | 274 | | } |
| | | 275 | | |
| | 165 | 276 | | return LegacyNames.TryGetValue(name, out item); |
| | | 277 | | } |
| | | 278 | | |
| | | 279 | | public static bool TryResolveAuthoredItem(int itemDefId, string? itemKey, string? legacyName, out Item? item) |
| | | 280 | | { |
| | 27 | 281 | | if (TryGetByItemDefId(itemDefId, out item) && item is not null) |
| | | 282 | | { |
| | 12 | 283 | | return true; |
| | | 284 | | } |
| | | 285 | | |
| | 15 | 286 | | if (!string.IsNullOrWhiteSpace(itemKey) && TryGetByKey(itemKey, out item) && item is not null) |
| | | 287 | | { |
| | 2 | 288 | | return true; |
| | | 289 | | } |
| | | 290 | | |
| | 13 | 291 | | if (itemDefId <= 0 |
| | 13 | 292 | | && string.IsNullOrWhiteSpace(itemKey) |
| | 13 | 293 | | && !string.IsNullOrWhiteSpace(legacyName) |
| | 13 | 294 | | && TryGetByLegacyName(legacyName, out item) |
| | 13 | 295 | | && item is not null) |
| | | 296 | | { |
| | 10 | 297 | | return true; |
| | | 298 | | } |
| | | 299 | | |
| | 3 | 300 | | item = null; |
| | 3 | 301 | | return false; |
| | | 302 | | } |
| | | 303 | | |
| | | 304 | | public static bool TryGetKeyByLegacyName(string name, out string key) |
| | | 305 | | { |
| | 0 | 306 | | if (string.IsNullOrWhiteSpace(name)) |
| | | 307 | | { |
| | 0 | 308 | | key = string.Empty; |
| | 0 | 309 | | return false; |
| | | 310 | | } |
| | | 311 | | |
| | 0 | 312 | | if (TryGetByKey(name, out var item) && item is not null) |
| | | 313 | | { |
| | 0 | 314 | | key = item.Key; |
| | 0 | 315 | | return true; |
| | | 316 | | } |
| | | 317 | | |
| | 0 | 318 | | if (LegacyNames.TryGetValue(name, out item) && item is not null) |
| | | 319 | | { |
| | 0 | 320 | | key = item.Key; |
| | 0 | 321 | | return true; |
| | | 322 | | } |
| | | 323 | | |
| | 0 | 324 | | key = string.Empty; |
| | 0 | 325 | | return false; |
| | | 326 | | } |
| | | 327 | | |
| | | 328 | | public static bool TryGetItemDefIdByLegacyName(string name, out int itemDefId) |
| | | 329 | | { |
| | 0 | 330 | | if (TryGetByLegacyName(name, out var item) && item is not null) |
| | | 331 | | { |
| | 0 | 332 | | itemDefId = item.ItemDefId; |
| | 0 | 333 | | return true; |
| | | 334 | | } |
| | | 335 | | |
| | 0 | 336 | | itemDefId = 0; |
| | 0 | 337 | | return false; |
| | | 338 | | } |
| | | 339 | | |
| | | 340 | | public static bool TryGetItemDefIdByKey(string key, out int itemDefId) |
| | | 341 | | { |
| | 0 | 342 | | if (TryGetByKey(key, out var item) && item is not null) |
| | | 343 | | { |
| | 0 | 344 | | itemDefId = item.ItemDefId; |
| | 0 | 345 | | return true; |
| | | 346 | | } |
| | | 347 | | |
| | 0 | 348 | | itemDefId = 0; |
| | 0 | 349 | | return false; |
| | | 350 | | } |
| | | 351 | | |
| | | 352 | | public static bool TryGetByKey(string key, out Item? item) |
| | | 353 | | { |
| | 641 | 354 | | if (string.IsNullOrWhiteSpace(key)) |
| | | 355 | | { |
| | 0 | 356 | | item = null; |
| | 0 | 357 | | return false; |
| | | 358 | | } |
| | | 359 | | |
| | 641 | 360 | | return ItemsByKey.TryGetValue(key, out item); |
| | | 361 | | } |
| | | 362 | | |
| | | 363 | | public static bool TryGetByItemDefId(int itemDefId, out Item? item) |
| | | 364 | | { |
| | 150 | 365 | | if (itemDefId <= 0) |
| | | 366 | | { |
| | 12 | 367 | | item = null; |
| | 12 | 368 | | return false; |
| | | 369 | | } |
| | | 370 | | |
| | 138 | 371 | | return ItemsById.TryGetValue(itemDefId, out item); |
| | | 372 | | } |
| | | 373 | | |
| | | 374 | | public static Item Create(string name) |
| | | 375 | | { |
| | 160 | 376 | | return CreateLegacy(name); |
| | | 377 | | } |
| | | 378 | | |
| | | 379 | | public static Item CreateByKey(string key) |
| | | 380 | | { |
| | 103 | 381 | | return GetByKey(key) with { }; |
| | | 382 | | } |
| | | 383 | | |
| | | 384 | | public static Item CreateLegacy(string name) |
| | | 385 | | { |
| | 160 | 386 | | return GetByLegacyName(name) with { }; |
| | | 387 | | } |
| | | 388 | | |
| | | 389 | | private static void RegisterAuthored( |
| | | 390 | | int itemDefId, |
| | | 391 | | string key, |
| | | 392 | | string displayName, |
| | | 393 | | ItemType itemType, |
| | | 394 | | int weight, |
| | | 395 | | int value, |
| | | 396 | | Rarity rarity, |
| | | 397 | | DisplayRarity displayRarity, |
| | | 398 | | params string[] aliases) |
| | | 399 | | { |
| | 15 | 400 | | var item = new Item(displayName, itemType, Weight: weight, Value: value, Slots: 1, Rarity: rarity, DisplayRarity |
| | 15 | 401 | | { |
| | 15 | 402 | | ItemDefId = itemDefId, |
| | 15 | 403 | | Key = key |
| | 15 | 404 | | }; |
| | | 405 | | |
| | 15 | 406 | | RegisterCanonical(item); |
| | | 407 | | |
| | 58 | 408 | | foreach (var alias in aliases) |
| | | 409 | | { |
| | 14 | 410 | | RegisterAlias(alias, item); |
| | | 411 | | } |
| | 15 | 412 | | } |
| | | 413 | | |
| | | 414 | | private static void RegisterCanonical(Item item) |
| | | 415 | | { |
| | 24 | 416 | | ItemsById[item.ItemDefId] = item; |
| | 24 | 417 | | ItemsByKey[item.Key] = item; |
| | 24 | 418 | | LegacyNames[item.Name] = item; |
| | 24 | 419 | | } |
| | | 420 | | |
| | | 421 | | private static void RegisterAlias(string alias, Item item) |
| | | 422 | | { |
| | 14 | 423 | | LegacyNames[alias] = item with { Name = alias }; |
| | 14 | 424 | | } |
| | | 425 | | } |