// // ItemParser.cs // // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using NosSmooth.Data.Abstractions.Enums; using NosSmooth.Data.Abstractions.Infos; using NosSmooth.Data.Abstractions.Language; using NosSmooth.Data.NOSFiles.Parsers.Dat; using Remora.Results; namespace NosSmooth.Data.NOSFiles.Parsers; /// public class ItemParser : IInfoParser { /// public Result> Parse(NostaleFiles files) { var itemDatResult = files.DatFiles.FindFile("Item.dat"); if (!itemDatResult.IsSuccess) { return Result>.FromError(itemDatResult); } var reader = new DatReader(itemDatResult.Entity); var result = new Dictionary(); while (reader.ReadItem(out var itemNullable)) { var item = itemNullable.Value; var indexEntry = item.GetEntry("INDEX"); var vnum = item.GetEntry("VNUM").Read(1); var nameKey = item.GetEntry("NAME").Read(1); var bagTypeData = item.GetEntry("INDEX").Read(1); var bagType = bagTypeData switch { 4 or 8 => BagType.Equipment, 9 => BagType.Main, 10 => BagType.Etc, _ => (BagType)bagTypeData }; var itemTypeData = indexEntry.Read(2); var itemType = itemTypeData switch { -1 => ItemType.None, _ => Enum.Parse($"{(int)bagType}{itemTypeData}") }; var equipmentSlotData = indexEntry.Read(4); EquipmentSlot? equipmentSlot = null; if (bagType is BagType.Equipment && equipmentSlotData != -1) { equipmentSlot = (EquipmentSlot)equipmentSlotData; } else if (bagType is BagType.Specialist) { equipmentSlot = EquipmentSlot.Sp; } result.Add ( vnum, new ItemInfo ( vnum, new TranslatableString(TranslationRoot.Item, nameKey), itemType, indexEntry.Read(3), equipmentSlot, bagType, item.GetEntry("DATA").GetValues() ) ); } return result; } private record ItemInfo ( int VNum, TranslatableString Name, ItemType Type, int SubType, EquipmentSlot? EquipmentSlot, BagType BagType, string[] Data ) : IItemInfo; }