| | | 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> LegacyNames = new(StringComparer.OrdinalIgnoreCase); |
| | | 7 | | |
| | | 8 | | static ItemCatalog() |
| | | 9 | | { |
| | 1 | 10 | | RegisterCanonical(new Item("Rusty Knife", ItemType.Weapon, Value: 1, Slots: 1, Rarity: Rarity.Common, DisplayRar |
| | 1 | 11 | | { |
| | 1 | 12 | | ItemDefId = 1 |
| | 1 | 13 | | }, "rusty_knife"); |
| | | 14 | | |
| | 1 | 15 | | RegisterAuthored( |
| | 1 | 16 | | itemDefId: 2, |
| | 1 | 17 | | displayName: "Makarov", |
| | 1 | 18 | | itemType: ItemType.Weapon, |
| | 1 | 19 | | weight: 2, |
| | 1 | 20 | | value: 60, |
| | 1 | 21 | | rarity: Rarity.Common, |
| | 1 | 22 | | displayRarity: DisplayRarity.Common, |
| | 1 | 23 | | aliases: ["makarov", "Light Pistol"]); |
| | | 24 | | |
| | 1 | 25 | | RegisterAuthored( |
| | 1 | 26 | | itemDefId: 3, |
| | 1 | 27 | | displayName: "PPSH", |
| | 1 | 28 | | itemType: ItemType.Weapon, |
| | 1 | 29 | | weight: 12, |
| | 1 | 30 | | value: 160, |
| | 1 | 31 | | rarity: Rarity.Uncommon, |
| | 1 | 32 | | displayRarity: DisplayRarity.Uncommon, |
| | 1 | 33 | | aliases: ["ppsh", "Drum SMG"]); |
| | | 34 | | |
| | 1 | 35 | | RegisterAuthored( |
| | 1 | 36 | | itemDefId: 4, |
| | 1 | 37 | | displayName: "AK74", |
| | 1 | 38 | | itemType: ItemType.Weapon, |
| | 1 | 39 | | weight: 7, |
| | 1 | 40 | | value: 320, |
| | 1 | 41 | | rarity: Rarity.Rare, |
| | 1 | 42 | | displayRarity: DisplayRarity.Rare, |
| | 1 | 43 | | aliases: ["ak74", "Field Carbine", "Hunting Rifle", "Compact Carbine"]); |
| | | 44 | | |
| | 1 | 45 | | RegisterAuthored( |
| | 1 | 46 | | itemDefId: 5, |
| | 1 | 47 | | displayName: "AK47", |
| | 1 | 48 | | itemType: ItemType.Weapon, |
| | 1 | 49 | | weight: 10, |
| | 1 | 50 | | value: 375, |
| | 1 | 51 | | rarity: Rarity.Rare, |
| | 1 | 52 | | displayRarity: DisplayRarity.Rare, |
| | 1 | 53 | | aliases: ["ak47", "Battle Rifle", "Sawed Shotgun"]); |
| | | 54 | | |
| | 1 | 55 | | RegisterAuthored( |
| | 1 | 56 | | itemDefId: 6, |
| | 1 | 57 | | displayName: "SVDS", |
| | 1 | 58 | | itemType: ItemType.Weapon, |
| | 1 | 59 | | weight: 10, |
| | 1 | 60 | | value: 550, |
| | 1 | 61 | | rarity: Rarity.Epic, |
| | 1 | 62 | | displayRarity: DisplayRarity.Epic, |
| | 1 | 63 | | aliases: ["svds", "Marksman Rifle"]); |
| | | 64 | | |
| | 1 | 65 | | RegisterAuthored( |
| | 1 | 66 | | itemDefId: 7, |
| | 1 | 67 | | displayName: "PKP", |
| | 1 | 68 | | itemType: ItemType.Weapon, |
| | 1 | 69 | | weight: 18, |
| | 1 | 70 | | value: 800, |
| | 1 | 71 | | rarity: Rarity.Legendary, |
| | 1 | 72 | | displayRarity: DisplayRarity.Legendary, |
| | 1 | 73 | | aliases: ["pkp", "Support Machine Gun"]); |
| | | 74 | | |
| | 1 | 75 | | RegisterAuthored( |
| | 1 | 76 | | itemDefId: 8, |
| | 1 | 77 | | displayName: "6B2 body armor", |
| | 1 | 78 | | itemType: ItemType.Armor, |
| | 1 | 79 | | weight: 9, |
| | 1 | 80 | | value: 95, |
| | 1 | 81 | | rarity: Rarity.Common, |
| | 1 | 82 | | displayRarity: DisplayRarity.Common, |
| | 1 | 83 | | aliases: ["6b2_body_armor", "Soft Armor Vest", "Soft Vest"]); |
| | | 84 | | |
| | 1 | 85 | | RegisterAuthored( |
| | 1 | 86 | | itemDefId: 9, |
| | 1 | 87 | | displayName: "BNTI Kirasa-N", |
| | 1 | 88 | | itemType: ItemType.Armor, |
| | 1 | 89 | | weight: 7, |
| | 1 | 90 | | value: 160, |
| | 1 | 91 | | rarity: Rarity.Uncommon, |
| | 1 | 92 | | displayRarity: DisplayRarity.Uncommon, |
| | 1 | 93 | | aliases: ["bnti_kirasa_n", "Reinforced Vest"]); |
| | | 94 | | |
| | 1 | 95 | | RegisterAuthored( |
| | 1 | 96 | | itemDefId: 10, |
| | 1 | 97 | | displayName: "6B13 assault armor", |
| | 1 | 98 | | itemType: ItemType.Armor, |
| | 1 | 99 | | weight: 7, |
| | 1 | 100 | | value: 225, |
| | 1 | 101 | | rarity: Rarity.Rare, |
| | 1 | 102 | | displayRarity: DisplayRarity.Rare, |
| | 1 | 103 | | aliases: ["6b13_assault_armor", "Light Plate Carrier", "Plate Carrier"]); |
| | | 104 | | |
| | 1 | 105 | | RegisterAuthored( |
| | 1 | 106 | | itemDefId: 11, |
| | 1 | 107 | | displayName: "FORT Defender-2", |
| | 1 | 108 | | itemType: ItemType.Armor, |
| | 1 | 109 | | weight: 22, |
| | 1 | 110 | | value: 375, |
| | 1 | 111 | | rarity: Rarity.Epic, |
| | 1 | 112 | | displayRarity: DisplayRarity.Epic, |
| | 1 | 113 | | aliases: ["fort_defender_2", "Medium Plate Carrier"]); |
| | | 114 | | |
| | 1 | 115 | | RegisterAuthored( |
| | 1 | 116 | | itemDefId: 12, |
| | 1 | 117 | | displayName: "6B43 Zabralo-Sh body armor", |
| | 1 | 118 | | itemType: ItemType.Armor, |
| | 1 | 119 | | weight: 28, |
| | 1 | 120 | | value: 450, |
| | 1 | 121 | | rarity: Rarity.Legendary, |
| | 1 | 122 | | displayRarity: DisplayRarity.Legendary, |
| | 1 | 123 | | aliases: ["6b43_zabralo_sh_body_armor", "Heavy Plate Carrier"]); |
| | | 124 | | |
| | 1 | 125 | | RegisterAuthored( |
| | 1 | 126 | | itemDefId: 13, |
| | 1 | 127 | | displayName: "NFM THOR", |
| | 1 | 128 | | itemType: ItemType.Armor, |
| | 1 | 129 | | weight: 19, |
| | 1 | 130 | | value: 650, |
| | 1 | 131 | | rarity: Rarity.Legendary, |
| | 1 | 132 | | displayRarity: DisplayRarity.Legendary, |
| | 1 | 133 | | aliases: ["nfm_thor", "Assault Plate Carrier"]); |
| | | 134 | | |
| | 1 | 135 | | RegisterCanonical(new Item("Small Backpack", ItemType.Backpack, Value: 25, Slots: 1, Rarity: Rarity.Common, Disp |
| | 1 | 136 | | { |
| | 1 | 137 | | ItemDefId = 14 |
| | 1 | 138 | | }, "small_backpack"); |
| | 1 | 139 | | RegisterAuthored( |
| | 1 | 140 | | itemDefId: 15, |
| | 1 | 141 | | displayName: "Large Backpack", |
| | 1 | 142 | | itemType: ItemType.Backpack, |
| | 1 | 143 | | weight: 1, |
| | 1 | 144 | | value: 50, |
| | 1 | 145 | | rarity: Rarity.Uncommon, |
| | 1 | 146 | | displayRarity: DisplayRarity.Uncommon, |
| | 1 | 147 | | aliases: ["large_backpack"]); |
| | 1 | 148 | | RegisterCanonical(new Item("Tactical Backpack", ItemType.Backpack, Value: 75, Slots: 2, Rarity: Rarity.Rare, Dis |
| | 1 | 149 | | { |
| | 1 | 150 | | ItemDefId = 16 |
| | 1 | 151 | | }, "tactical_backpack"); |
| | 1 | 152 | | RegisterAuthored( |
| | 1 | 153 | | itemDefId: 17, |
| | 1 | 154 | | displayName: "Tasmanian Tiger Trooper 35", |
| | 1 | 155 | | itemType: ItemType.Backpack, |
| | 1 | 156 | | weight: 2, |
| | 1 | 157 | | value: 400, |
| | 1 | 158 | | rarity: Rarity.Epic, |
| | 1 | 159 | | displayRarity: DisplayRarity.Epic, |
| | 1 | 160 | | aliases: ["tasmanian_tiger_trooper_35", "Hiking Backpack"]); |
| | 1 | 161 | | RegisterAuthored( |
| | 1 | 162 | | itemDefId: 18, |
| | 1 | 163 | | displayName: "6Sh118", |
| | 1 | 164 | | itemType: ItemType.Backpack, |
| | 1 | 165 | | weight: 8, |
| | 1 | 166 | | value: 600, |
| | 1 | 167 | | rarity: Rarity.Legendary, |
| | 1 | 168 | | displayRarity: DisplayRarity.Legendary, |
| | 1 | 169 | | aliases: ["6sh118", "Raid Backpack"]); |
| | | 170 | | |
| | 1 | 171 | | RegisterCanonical(new Item("Medkit", ItemType.Consumable, Value: 30, Slots: 1, Rarity: Rarity.Common, DisplayRar |
| | 1 | 172 | | { |
| | 1 | 173 | | ItemDefId = 19 |
| | 1 | 174 | | }, "medkit"); |
| | 1 | 175 | | RegisterCanonical(new Item("Bandage", ItemType.Sellable, Value: 15, Slots: 1, Rarity: Rarity.Common, DisplayRari |
| | 1 | 176 | | { |
| | 1 | 177 | | ItemDefId = 20 |
| | 1 | 178 | | }, "bandage"); |
| | 1 | 179 | | RegisterCanonical(new Item("Ammo Box", ItemType.Sellable, Value: 20, Slots: 1, Rarity: Rarity.Common, DisplayRar |
| | 1 | 180 | | { |
| | 1 | 181 | | ItemDefId = 21 |
| | 1 | 182 | | }, "ammo_box"); |
| | 1 | 183 | | RegisterCanonical(new Item("Scrap Metal", ItemType.Material, Value: 18, Slots: 1, Rarity: Rarity.Common, Display |
| | 1 | 184 | | { |
| | 1 | 185 | | ItemDefId = 22 |
| | 1 | 186 | | }, "scrap_metal"); |
| | 1 | 187 | | RegisterCanonical(new Item("Rare Scope", ItemType.Material, Value: 80, Slots: 1, Rarity: Rarity.Rare, DisplayRar |
| | 1 | 188 | | { |
| | 1 | 189 | | ItemDefId = 23 |
| | 1 | 190 | | }, "rare_scope"); |
| | 1 | 191 | | RegisterCanonical(new Item("Legendary Trigger Group", ItemType.Material, Value: 150, Slots: 1, Rarity: Rarity.Le |
| | 1 | 192 | | { |
| | 1 | 193 | | ItemDefId = 24 |
| | 1 | 194 | | }, "legendary_trigger_group"); |
| | 1 | 195 | | } |
| | | 196 | | |
| | | 197 | | public static Item Get(string name) |
| | | 198 | | { |
| | 160 | 199 | | return GetByLegacyName(name); |
| | | 200 | | } |
| | | 201 | | |
| | | 202 | | public static Item GetByItemDefId(int itemDefId) |
| | | 203 | | { |
| | 9 | 204 | | if (!TryGetByItemDefId(itemDefId, out var item)) |
| | | 205 | | { |
| | 0 | 206 | | throw new KeyNotFoundException($"No authored item definition exists for itemDefId '{itemDefId}'."); |
| | | 207 | | } |
| | | 208 | | |
| | 9 | 209 | | return item!; |
| | | 210 | | } |
| | | 211 | | |
| | | 212 | | public static Item GetByLegacyName(string name) |
| | | 213 | | { |
| | 432 | 214 | | if (!TryGetByLegacyName(name, out var item)) |
| | | 215 | | { |
| | 0 | 216 | | throw new KeyNotFoundException($"No authored item definition exists for '{name}'."); |
| | | 217 | | } |
| | | 218 | | |
| | 432 | 219 | | 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 | | { |
| | 209 | 225 | | return TryGetByLegacyName(name, out item); |
| | | 226 | | } |
| | | 227 | | |
| | | 228 | | public static bool TryGetByLegacyName(string name, out Item? item) |
| | | 229 | | { |
| | 641 | 230 | | if (string.IsNullOrWhiteSpace(name)) |
| | | 231 | | { |
| | 3 | 232 | | item = null; |
| | 3 | 233 | | return false; |
| | | 234 | | } |
| | | 235 | | |
| | 638 | 236 | | return LegacyNames.TryGetValue(name, out item); |
| | | 237 | | } |
| | | 238 | | |
| | | 239 | | public static bool TryResolveAuthoredItem(int itemDefId, out Item? item) |
| | | 240 | | { |
| | 26 | 241 | | if (TryGetByItemDefId(itemDefId, out item) && item is not null) |
| | | 242 | | { |
| | 12 | 243 | | return true; |
| | | 244 | | } |
| | | 245 | | |
| | 14 | 246 | | item = null; |
| | 14 | 247 | | return false; |
| | | 248 | | } |
| | | 249 | | |
| | | 250 | | public static bool TryGetByItemDefId(int itemDefId, out Item? item) |
| | | 251 | | { |
| | 154 | 252 | | if (itemDefId <= 0) |
| | | 253 | | { |
| | 12 | 254 | | item = null; |
| | 12 | 255 | | return false; |
| | | 256 | | } |
| | | 257 | | |
| | 142 | 258 | | return ItemsById.TryGetValue(itemDefId, out item); |
| | | 259 | | } |
| | | 260 | | |
| | | 261 | | public static string GetLookupToken(int itemDefId) |
| | | 262 | | { |
| | 243 | 263 | | return itemDefId switch |
| | 243 | 264 | | { |
| | 6 | 265 | | 1 => "rusty_knife", |
| | 24 | 266 | | 2 => "makarov", |
| | 21 | 267 | | 3 => "ppsh", |
| | 69 | 268 | | 4 => "ak74", |
| | 16 | 269 | | 5 => "ak47", |
| | 12 | 270 | | 6 => "svds", |
| | 12 | 271 | | 7 => "pkp", |
| | 11 | 272 | | 8 => "6b2_body_armor", |
| | 7 | 273 | | 9 => "bnti_kirasa_n", |
| | 8 | 274 | | 10 => "6b13_assault_armor", |
| | 4 | 275 | | 11 => "fort_defender_2", |
| | 3 | 276 | | 12 => "6b43_zabralo_sh_body_armor", |
| | 3 | 277 | | 13 => "nfm_thor", |
| | 11 | 278 | | 14 => "small_backpack", |
| | 8 | 279 | | 15 => "large_backpack", |
| | 2 | 280 | | 16 => "tactical_backpack", |
| | 3 | 281 | | 17 => "tasmanian_tiger_trooper_35", |
| | 5 | 282 | | 18 => "6sh118", |
| | 11 | 283 | | 19 => "medkit", |
| | 3 | 284 | | 20 => "bandage", |
| | 2 | 285 | | 21 => "ammo_box", |
| | 1 | 286 | | 22 => "scrap_metal", |
| | 1 | 287 | | 23 => "rare_scope", |
| | 0 | 288 | | 24 => "legendary_trigger_group", |
| | 0 | 289 | | _ => string.Empty |
| | 243 | 290 | | }; |
| | | 291 | | } |
| | | 292 | | |
| | | 293 | | public static Item Create(string name) |
| | | 294 | | { |
| | 272 | 295 | | return CreateLegacy(name); |
| | | 296 | | } |
| | | 297 | | |
| | | 298 | | public static Item CreateLegacy(string name) |
| | | 299 | | { |
| | 272 | 300 | | 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 | | { |
| | 15 | 313 | | var item = new Item(displayName, itemType, Weight: weight, Value: value, Slots: 1, Rarity: rarity, DisplayRarity |
| | 15 | 314 | | { |
| | 15 | 315 | | ItemDefId = itemDefId |
| | 15 | 316 | | }; |
| | | 317 | | |
| | 15 | 318 | | RegisterCanonical(item); |
| | | 319 | | |
| | 98 | 320 | | foreach (var alias in aliases) |
| | | 321 | | { |
| | 34 | 322 | | RegisterAlias(alias, item); |
| | | 323 | | } |
| | 15 | 324 | | } |
| | | 325 | | |
| | | 326 | | private static void RegisterCanonical(Item item, params string[] aliases) |
| | | 327 | | { |
| | 24 | 328 | | ItemsById[item.ItemDefId] = item; |
| | 24 | 329 | | LegacyNames[item.Name] = item; |
| | | 330 | | |
| | 66 | 331 | | foreach (var alias in aliases) |
| | | 332 | | { |
| | 9 | 333 | | RegisterAlias(alias, item); |
| | | 334 | | } |
| | 24 | 335 | | } |
| | | 336 | | |
| | | 337 | | private static void RegisterAlias(string alias, Item item) |
| | | 338 | | { |
| | 43 | 339 | | if (LegacyNames.ContainsKey(alias)) |
| | | 340 | | { |
| | 9 | 341 | | return; |
| | | 342 | | } |
| | | 343 | | |
| | 34 | 344 | | LegacyNames[alias] = item with { Name = alias }; |
| | 34 | 345 | | } |
| | | 346 | | } |