qstbak/Questionable/Questionable.Data/AetherCurrentData.cs
2026-08-17 20:27:25 +10:00

208 lines
6.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Numerics;
using Dalamud.Plugin.Services;
using Lumina.Excel;
using Lumina.Excel.Sheets;
namespace Questionable.Data;
internal sealed class AetherCurrentData
{
private readonly IDataManager _dataManager;
private readonly ImmutableDictionary<ushort, ImmutableList<uint>> _overworldCurrents;
private readonly ImmutableDictionary<ushort, ImmutableList<AetherCurrentInfo>> _allCurrentsByTerritory;
private readonly ImmutableDictionary<uint, uint> _questCurrents;
private ImmutableDictionary<uint, AetherCurrentPosition>? _overworldPositions;
public IReadOnlyDictionary<ushort, ImmutableList<AetherCurrentInfo>> AllCurrentsByTerritory => _allCurrentsByTerritory;
private ImmutableDictionary<uint, AetherCurrentPosition> OverworldPositions => _overworldPositions ?? (_overworldPositions = BuildOverworldPositions());
public AetherCurrentData(IDataManager dataManager)
{
_dataManager = dataManager;
_overworldCurrents = (from x in dataManager.GetExcelSheet<AetherCurrentCompFlgSet>()
where x.RowId != 0
where x.Territory.IsValid
select x).ToImmutableDictionary((AetherCurrentCompFlgSet x) => (ushort)x.Territory.RowId, (AetherCurrentCompFlgSet x) => (from y in x.AetherCurrents.Where(delegate(RowRef<AetherCurrent> y)
{
int num = ((y.RowId == 0) ? (-280991559) : (-280991560));
while (true)
{
int num2 = num;
int num3 = -280991559;
int num4 = num2;
switch ((num4 | num3) - (num4 & num3))
{
case 2:
goto IL_004b;
case 0:
return false;
case 1:
return y.Value.Quest.RowId == 0;
}
continue;
IL_004b:
num = -280991560;
}
})
select y.RowId).ToImmutableList());
_allCurrentsByTerritory = (from x in dataManager.GetExcelSheet<AetherCurrentCompFlgSet>()
where x.RowId != 0
where x.Territory.IsValid
select x).ToImmutableDictionary((AetherCurrentCompFlgSet x) => (ushort)x.Territory.RowId, (AetherCurrentCompFlgSet x) => x.AetherCurrents.Where((RowRef<AetherCurrent> y) => y.RowId != 0).Select(delegate(RowRef<AetherCurrent> y)
{
uint rowId = y.Value.Quest.RowId;
return new AetherCurrentInfo(y.RowId, rowId != 0, rowId);
}).ToImmutableList());
_questCurrents = (from info in _allCurrentsByTerritory.Values.SelectMany((ImmutableList<AetherCurrentInfo> list) => list)
where info.IsQuestGated
select info).ToImmutableDictionary((AetherCurrentInfo info) => info.AetherCurrentId, (AetherCurrentInfo info) => info.QuestId);
}
public bool IsValidAetherCurrent(ushort territoryId, uint aetherCurrentId)
{
ImmutableList<uint> value;
int num = ((!_overworldCurrents.TryGetValue(territoryId, out value)) ? (-1647784992) : (-1647784989));
while (true)
{
int num2 = num;
int num3 = -1647784990;
int num4 = num2;
int num5 = num4 + num3;
int num6 = num4 & num3;
switch (num5 - (num6 + num6))
{
case 0:
goto IL_0050;
case 1:
return value.Contains(aetherCurrentId);
case 2:
return false;
}
continue;
IL_0050:
num = -1647784989;
}
}
public ImmutableList<AetherCurrentInfo> GetCurrentsForTerritory(ushort territoryId)
{
return _allCurrentsByTerritory.GetValueOrDefault(territoryId, ImmutableList.Create(default(ReadOnlySpan<AetherCurrentInfo>)));
}
public AetherCurrentPosition? GetOverworldPosition(uint aetherCurrentId)
{
return OverworldPositions.GetValueOrDefault(aetherCurrentId);
}
public uint? GetQuestIdForCurrent(uint aetherCurrentId)
{
return _questCurrents.GetValueOrDefault(aetherCurrentId);
}
private ImmutableDictionary<uint, AetherCurrentPosition> BuildOverworldPositions()
{
HashSet<uint> hashSet = _overworldCurrents.Values.SelectMany((ImmutableList<uint> list) => list).ToHashSet();
Dictionary<uint, uint> dictionary = new Dictionary<uint, uint>();
using (ExcelSheet<EObj>.Enumerator enumerator = _dataManager.GetExcelSheet<EObj>().GetEnumerator())
{
int num = -379834335;
uint rowId = default(uint);
EObj current = default(EObj);
while (true)
{
int num2 = num;
int num3 = -379834333;
int num4 = num2;
switch ((num4 | num3) - (num4 & num3))
{
case 2:
num = (enumerator.MoveNext() ? (-379834334) : (-379834330));
break;
case 0:
dictionary[rowId] = current.RowId;
num = -379834335;
break;
case 1:
current = enumerator.Current;
num = ((current.RowId == 0) ? (-379834335) : (-379834336));
break;
case 3:
rowId = current.Data.RowId;
num = ((rowId == 0) ? (-379834335) : (-379834331));
break;
case 6:
num = ((!hashSet.Contains(rowId)) ? (-379834335) : (-379834333));
break;
case 4:
num = -379834335;
break;
case 5:
goto end_IL_0067;
}
continue;
end_IL_0067:
break;
}
}
Dictionary<uint, uint> dictionary2 = dictionary.ToDictionary((KeyValuePair<uint, uint> kv) => kv.Value, (KeyValuePair<uint, uint> kv) => kv.Key);
ImmutableDictionary<uint, AetherCurrentPosition>.Builder builder = ImmutableDictionary.CreateBuilder<uint, AetherCurrentPosition>();
using (ExcelSheet<Level>.Enumerator enumerator2 = _dataManager.GetExcelSheet<Level>().GetEnumerator())
{
int num = 366195363;
Level current2 = default(Level);
uint value = default(uint);
uint rowId2 = default(uint);
while (true)
{
int num5 = num;
int num3 = 366195366;
int num4 = num5;
int num6 = num4 + num3;
int num7 = num4 & num3;
switch (num6 - (num7 + num7))
{
case 6:
num = 366195363;
break;
case 2:
current2 = enumerator2.Current;
num = ((current2.RowId == 0) ? 366195363 : 366195367);
break;
case 3:
{
ushort territoryId = (ushort)current2.Territory.RowId;
Vector3 position = new Vector3(current2.X, current2.Y, current2.Z);
builder[value] = new AetherCurrentPosition(territoryId, position, rowId2);
num = 366195363;
break;
}
case 1:
rowId2 = current2.Object.RowId;
num = ((!dictionary2.TryGetValue(rowId2, out value)) ? 366195363 : 366195366);
break;
case 0:
num = ((!current2.Territory.IsValid) ? 366195363 : 366195365);
break;
case 5:
num = (enumerator2.MoveNext() ? 366195364 : 366195362);
break;
case 4:
goto end_IL_01ff;
}
continue;
end_IL_01ff:
break;
}
}
return builder.ToImmutable();
}
}