71 lines
2.5 KiB
C#
71 lines
2.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using Dalamud.Plugin.Services;
|
|
using Lumina.Excel;
|
|
using Lumina.Excel.Sheets;
|
|
using Microsoft.Extensions.Logging;
|
|
using SmartNav.Model.Navigation;
|
|
|
|
namespace SmartNav.Data;
|
|
|
|
public sealed class TaxiStandDataService
|
|
{
|
|
public sealed record TaxiStandInfo(uint StandRowId, string PlaceName, ushort TerritoryId, Vector3 Position, uint NpcDataId, TaxiRoute[] Routes);
|
|
|
|
public sealed record TaxiRoute(uint DestStandRowId, int Fare, int TimeRequiredSeconds);
|
|
|
|
public IReadOnlyDictionary<uint, TaxiStandInfo> Stands { get; }
|
|
|
|
public IReadOnlyDictionary<uint, TaxiStandInfo> StandsByNpcDataId { get; }
|
|
|
|
public int TotalStands { get; }
|
|
|
|
public int TotalRoutes { get; }
|
|
|
|
public TaxiStandDataService(IDataManager dataManager, SmartNavDataOptions dataOptions, ILogger<TaxiStandDataService> logger)
|
|
{
|
|
IReadOnlyList<TaxiStandEntry> stands = AssemblyTaxiStandLoader.GetStands(dataOptions.DevSourceDirectory?.FullName);
|
|
Dictionary<uint, TaxiStandEntry> dictionary = new Dictionary<uint, TaxiStandEntry>();
|
|
foreach (TaxiStandEntry item in stands)
|
|
{
|
|
dictionary[item.ChocoboTaxiStandId] = item;
|
|
}
|
|
Dictionary<uint, TaxiStandInfo> dictionary2 = new Dictionary<uint, TaxiStandInfo>();
|
|
int num = 0;
|
|
ExcelSheet<ChocoboTaxiStand> excelSheet = dataManager.GetExcelSheet<ChocoboTaxiStand>();
|
|
foreach (var (num3, taxiStandEntry2) in dictionary)
|
|
{
|
|
if (!excelSheet.HasRow(num3))
|
|
{
|
|
continue;
|
|
}
|
|
ChocoboTaxiStand row = excelSheet.GetRow(num3);
|
|
string text = row.PlaceName.ToString();
|
|
if (string.IsNullOrEmpty(text))
|
|
{
|
|
text = $"TaxiStand 0x{num3:X}";
|
|
}
|
|
List<TaxiRoute> list = new List<TaxiRoute>();
|
|
for (int i = 0; i < 8; i++)
|
|
{
|
|
ChocoboTaxi? valueNullable = row.TargetLocations[i].ValueNullable;
|
|
if (valueNullable.HasValue && valueNullable.Value.TimeRequired != 0)
|
|
{
|
|
uint rowId = valueNullable.Value.Location.RowId;
|
|
if (rowId != 0)
|
|
{
|
|
list.Add(new TaxiRoute(rowId, valueNullable.Value.Fare, valueNullable.Value.TimeRequired * 60));
|
|
}
|
|
}
|
|
}
|
|
num += list.Count;
|
|
dictionary2[num3] = new TaxiStandInfo(num3, text, taxiStandEntry2.TerritoryId, taxiStandEntry2.Location, taxiStandEntry2.Id, list.ToArray());
|
|
}
|
|
Stands = dictionary2;
|
|
StandsByNpcDataId = dictionary2.Values.ToDictionary((TaxiStandInfo s) => s.NpcDataId, (TaxiStandInfo s) => s);
|
|
TotalStands = dictionary2.Count;
|
|
TotalRoutes = num;
|
|
logger.LogDebug("TaxiStandDataService: {Stands} stands, {Routes} routes loaded", TotalStands, TotalRoutes);
|
|
}
|
|
}
|