75 lines
1.8 KiB
C#
75 lines
1.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Numerics;
|
|
using Dalamud.Plugin.Services;
|
|
using LLib.Shop.Model;
|
|
using Lumina.Excel;
|
|
using Lumina.Excel.Sheets;
|
|
|
|
namespace LLib.Shop.Searchers;
|
|
|
|
internal sealed class GilShopSearcher
|
|
{
|
|
private readonly IDataManager _dataManager;
|
|
|
|
private readonly NpcPositionCache _positionCache;
|
|
|
|
public GilShopSearcher(IDataManager dataManager, NpcPositionCache positionCache)
|
|
{
|
|
_dataManager = dataManager;
|
|
_positionCache = positionCache;
|
|
}
|
|
|
|
public List<ShopSearchResult> Search(uint itemId)
|
|
{
|
|
List<ShopSearchResult> list = new List<ShopSearchResult>();
|
|
ExcelSheet<ENpcBase> excelSheet = _dataManager.GetExcelSheet<ENpcBase>();
|
|
SubrowExcelSheet<GilShopItem> subrowExcelSheet = _dataManager.GetSubrowExcelSheet<GilShopItem>();
|
|
if (!_dataManager.GetExcelSheet<Item>().TryGetRow(itemId, out var row))
|
|
{
|
|
return list;
|
|
}
|
|
uint priceMid = row.PriceMid;
|
|
foreach (ENpcBase item in excelSheet)
|
|
{
|
|
if (item.RowId == 0)
|
|
{
|
|
continue;
|
|
}
|
|
(ushort, Vector3)? position = _positionCache.GetPosition(item.RowId);
|
|
if (!position.HasValue)
|
|
{
|
|
continue;
|
|
}
|
|
(ushort, Vector3) valueOrDefault = position.GetValueOrDefault();
|
|
int num = 0;
|
|
foreach (RowRef eNpcDatum in item.ENpcData)
|
|
{
|
|
if (eNpcDatum.RowId >> 16 != 4)
|
|
{
|
|
continue;
|
|
}
|
|
uint rowId = eNpcDatum.RowId;
|
|
if (!subrowExcelSheet.TryGetRow(rowId, out var row2))
|
|
{
|
|
num++;
|
|
continue;
|
|
}
|
|
bool flag = false;
|
|
for (int i = 0; i < row2.Count; i++)
|
|
{
|
|
if (row2[i].Item.RowId == itemId)
|
|
{
|
|
flag = true;
|
|
break;
|
|
}
|
|
}
|
|
if (flag)
|
|
{
|
|
list.Add(new ShopSearchResult(rowId, item.RowId, valueOrDefault.Item1, valueOrDefault.Item2, EShopType.GilShop, priceMid, 1u, num));
|
|
}
|
|
num++;
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
}
|