forked from aly/qstbak
45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using Dalamud.Plugin.Services;
|
|
using Lumina.Excel;
|
|
using Lumina.Excel.Sheets;
|
|
|
|
namespace Questionable.Data;
|
|
|
|
internal sealed class FishingData
|
|
{
|
|
private readonly Dictionary<uint, FishingSpotInfo> _itemToSpot;
|
|
|
|
public FishingData(IDataManager dataManager)
|
|
{
|
|
ExcelSheet<FishingSpot> excelSheet = dataManager.GetExcelSheet<FishingSpot>();
|
|
Dictionary<uint, FishingSpotInfo> dictionary = new Dictionary<uint, FishingSpotInfo>();
|
|
foreach (FishingSpot item in excelSheet)
|
|
{
|
|
if (item.RowId == 0 || item.TerritoryType.RowId == 0)
|
|
{
|
|
continue;
|
|
}
|
|
FishingSpotInfo value = new FishingSpotInfo(item.RowId, (ushort)item.TerritoryType.RowId, item.X, item.Z, item.GatheringLevel);
|
|
foreach (RowRef<Item> item2 in item.Item)
|
|
{
|
|
if (item2.RowId != 0 && (!dictionary.TryGetValue(item2.RowId, out var value2) || value2.GatheringLevel > value.GatheringLevel))
|
|
{
|
|
dictionary[item2.RowId] = value;
|
|
}
|
|
}
|
|
}
|
|
_itemToSpot = dictionary;
|
|
}
|
|
|
|
public bool TryGetFishingSpot(uint itemId, [NotNullWhen(true)] out FishingSpotInfo? spot)
|
|
{
|
|
if (_itemToSpot.TryGetValue(itemId, out var value))
|
|
{
|
|
spot = value;
|
|
return true;
|
|
}
|
|
spot = null;
|
|
return false;
|
|
}
|
|
}
|