1
0
Fork 0
Workship/Workshoppa/GameData/WorkshopCache.cs

66 lines
2.8 KiB
C#
Raw Normal View History

2023-10-01 20:50:21 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
2023-10-04 22:07:36 +00:00
using Dalamud.Plugin.Services;
2023-10-01 20:50:21 +00:00
using Lumina.Excel.GeneratedSheets;
namespace Workshoppa.GameData;
internal sealed class WorkshopCache
{
2023-10-04 22:07:36 +00:00
public WorkshopCache(IDataManager dataManager, IPluginLog pluginLog)
2023-10-01 20:50:21 +00:00
{
Task.Run(() =>
{
try
{
Dictionary<ushort, Item> itemMapping = dataManager.GetExcelSheet<CompanyCraftSupplyItem>()!
.Where(x => x.RowId > 0)
.ToDictionary(x => (ushort)x.RowId, x => x.Item.Value!);
Crafts = dataManager.GetExcelSheet<CompanyCraftSequence>()!
.Where(x => x.RowId > 0)
.Select(x => new WorkshopCraft
{
WorkshopItemId = x.RowId,
ResultItem = x.ResultItem.Row,
Name = x.ResultItem.Value!.Name.ToString(),
Category = (WorkshopCraftCategory)x.CompanyCraftDraftCategory.Row,
Type = x.CompanyCraftType.Row,
Phases = x.CompanyCraftPart.Where(part => part.Row != 0)
.SelectMany(part =>
part.Value!.CompanyCraftProcess
.Where(y => y.Value!.UnkData0.Any(z => z.SupplyItem > 0))
.Select(y => (Type: part.Value!.CompanyCraftType.Value, Process: y)))
.Select(y => new WorkshopCraftPhase
{
Name = y.Type!.Name.ToString(),
Items = y.Process.Value!.UnkData0
.Where(item => item.SupplyItem > 0)
.Select(item => new WorkshopCraftItem
{
ItemId = itemMapping[item.SupplyItem].RowId,
Name = itemMapping[item.SupplyItem].Name.ToString(),
SetQuantity = item.SetQuantity,
SetsRequired = item.SetsRequired,
})
.ToList()
.AsReadOnly(),
})
.ToList()
.AsReadOnly(),
})
.ToList()
.AsReadOnly();
}
catch (Exception e)
{
2023-10-04 22:07:36 +00:00
pluginLog.Error(e, "Unable to load cached items");
2023-10-01 20:50:21 +00:00
}
});
}
public IReadOnlyList<WorkshopCraft> Crafts { get; private set; } = new List<WorkshopCraft>();
}