100 lines
2.9 KiB
C#
100 lines
2.9 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 GCShopSearcher
|
|
{
|
|
private static readonly uint[] SealItemIds = new uint[4] { 0u, 20u, 21u, 22u };
|
|
|
|
private static readonly uint[] QuartermasterNpcIds = new uint[4] { 0u, 1003251u, 1000394u, 1004416u };
|
|
|
|
private readonly IDataManager _dataManager;
|
|
|
|
private readonly NpcPositionCache _positionCache;
|
|
|
|
public GCShopSearcher(IDataManager dataManager, NpcPositionCache positionCache)
|
|
{
|
|
_dataManager = dataManager;
|
|
_positionCache = positionCache;
|
|
}
|
|
|
|
public List<ShopSearchResult> Search(uint itemId)
|
|
{
|
|
List<ShopSearchResult> list = new List<ShopSearchResult>();
|
|
SubrowExcelSheet<GCScripShopItem> subrowExcelSheet = _dataManager.GetSubrowExcelSheet<GCScripShopItem>();
|
|
ExcelSheet<GCScripShopCategory> excelSheet = _dataManager.GetExcelSheet<GCScripShopCategory>();
|
|
ExcelSheet<GCShop> excelSheet2 = _dataManager.GetExcelSheet<GCShop>();
|
|
Dictionary<uint, uint> dictionary = new Dictionary<uint, uint>();
|
|
foreach (GCShop item in excelSheet2)
|
|
{
|
|
uint rowId = item.GrandCompany.RowId;
|
|
if (rowId != 0)
|
|
{
|
|
dictionary.TryAdd(rowId, item.RowId);
|
|
}
|
|
}
|
|
Dictionary<uint, uint> dictionary2 = new Dictionary<uint, uint>();
|
|
foreach (SubrowCollection<GCScripShopItem> item2 in subrowExcelSheet)
|
|
{
|
|
uint rowId2 = item2.RowId;
|
|
for (int i = 0; i < item2.Count; i++)
|
|
{
|
|
GCScripShopItem gCScripShopItem = item2[i];
|
|
if (gCScripShopItem.Item.RowId != itemId)
|
|
{
|
|
continue;
|
|
}
|
|
uint costGCSeals = gCScripShopItem.CostGCSeals;
|
|
if (!excelSheet.TryGetRow(rowId2, out var row))
|
|
{
|
|
continue;
|
|
}
|
|
uint rowId3 = row.GrandCompany.RowId;
|
|
uint value2;
|
|
if (rowId3 == 0)
|
|
{
|
|
for (uint num = 1u; num < (uint)QuartermasterNpcIds.Length; num++)
|
|
{
|
|
if (!dictionary2.TryGetValue(num, out var value) || costGCSeals < value)
|
|
{
|
|
dictionary2[num] = costGCSeals;
|
|
}
|
|
}
|
|
}
|
|
else if (!dictionary2.TryGetValue(rowId3, out value2) || costGCSeals < value2)
|
|
{
|
|
dictionary2[rowId3] = costGCSeals;
|
|
}
|
|
}
|
|
}
|
|
if (dictionary2.Count == 0)
|
|
{
|
|
return list;
|
|
}
|
|
foreach (var (num4, price) in dictionary2)
|
|
{
|
|
if (num4 >= (uint)QuartermasterNpcIds.Length)
|
|
{
|
|
continue;
|
|
}
|
|
uint num5 = QuartermasterNpcIds[num4];
|
|
if (num5 != 0)
|
|
{
|
|
uint currencyItemId = ((num4 < (uint)SealItemIds.Length) ? SealItemIds[num4] : 0u);
|
|
(ushort, Vector3)? position = _positionCache.GetPosition(num5);
|
|
if (position.HasValue)
|
|
{
|
|
(ushort, Vector3) valueOrDefault = position.GetValueOrDefault();
|
|
dictionary.TryGetValue(num4, out var value3);
|
|
list.Add(new ShopSearchResult(value3, num5, valueOrDefault.Item1, valueOrDefault.Item2, EShopType.GCShop, price, currencyItemId));
|
|
}
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
}
|