using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using Dalamud.Plugin.Services; using Lumina.Excel; using Lumina.Excel.Sheets; using Questionable.Model.Gathering; namespace Questionable.Data; internal sealed class GatheringData { private readonly Dictionary _minerGatheringPoints = new Dictionary(); private readonly Dictionary _botanistGatheringPoints = new Dictionary(); private readonly Dictionary _itemIdToCollectability; private readonly Dictionary _npcForCustomDeliveries; public IEnumerable MinerGatheringPoints => _minerGatheringPoints.Values; public IEnumerable BotanistGatheringPoints => _botanistGatheringPoints.Values; public GatheringData(IDataManager dataManager) { Dictionary dictionary = (from x in dataManager.GetExcelSheet() where x.RowId != 0 && x.Item.RowId != 0 select x).ToDictionary((GatheringItem x) => x.RowId, (GatheringItem x) => x.Item.RowId); foreach (GatheringPointBase item in dataManager.GetExcelSheet()) { foreach (RowRef item2 in item.Item.Where((RowRef x) => x.RowId != 0)) { if (!dictionary.TryGetValue(item2.RowId, out var value)) { continue; } uint rowId = item.GatheringType.RowId; if (rowId <= 1) { _minerGatheringPoints[value] = new GatheringPointId((ushort)item.RowId); continue; } rowId = item.GatheringType.RowId; if (rowId - 2 <= 1) { _botanistGatheringPoints[value] = new GatheringPointId((ushort)item.RowId); } } } _itemIdToCollectability = (from x in dataManager.GetSubrowExcelSheet().Flatten() where x.RowId != 0 where x.Slot == 2 select new { ItemId = x.Item.RowId, Collectability = x.CollectabilityHigh }).Distinct().ToDictionary(x => x.ItemId, x => x.Collectability); _npcForCustomDeliveries = (from x in (from x in dataManager.GetExcelSheet() where x.RowId != 0 select x).SelectMany((SatisfactionNpc x) => from y in dataManager.GetSubrowExcelSheet().Flatten() where y.RowId == x.SatisfactionNpcParams.Last().SupplyIndex select new { ItemId = y.Item.RowId, NpcId = x.Npc.RowId }) where x.ItemId != 0 select x).Distinct().ToDictionary(x => x.ItemId, x => x.NpcId); } public bool TryGetMinerGatheringPointByItemId(uint itemId, [NotNullWhen(true)] out GatheringPointId? gatheringPointId) { return _minerGatheringPoints.TryGetValue(itemId, out gatheringPointId); } public bool TryGetBotanistGatheringPointByItemId(uint itemId, [NotNullWhen(true)] out GatheringPointId? gatheringPointId) { return _botanistGatheringPoints.TryGetValue(itemId, out gatheringPointId); } public ushort GetRecommendedCollectability(uint itemId) { return _itemIdToCollectability.GetValueOrDefault(itemId); } public bool TryGetCustomDeliveryNpc(uint itemId, out uint npcId) { return _npcForCustomDeliveries.TryGetValue(itemId, out npcId); } }