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 Search(uint itemId) { List list = new List(); ExcelSheet excelSheet = _dataManager.GetExcelSheet(); SubrowExcelSheet subrowExcelSheet = _dataManager.GetSubrowExcelSheet(); if (!_dataManager.GetExcelSheet().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; } }