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> _overworldCurrents; private readonly ImmutableDictionary> _allCurrentsByTerritory; private readonly ImmutableDictionary _questCurrents; private ImmutableDictionary? _overworldPositions; public IReadOnlyDictionary> AllCurrentsByTerritory => _allCurrentsByTerritory; private ImmutableDictionary OverworldPositions => _overworldPositions ?? (_overworldPositions = BuildOverworldPositions()); public AetherCurrentData(IDataManager dataManager) { _dataManager = dataManager; _overworldCurrents = (from x in dataManager.GetExcelSheet() 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 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() where x.RowId != 0 where x.Territory.IsValid select x).ToImmutableDictionary((AetherCurrentCompFlgSet x) => (ushort)x.Territory.RowId, (AetherCurrentCompFlgSet x) => x.AetherCurrents.Where((RowRef y) => y.RowId != 0).Select(delegate(RowRef y) { uint rowId = y.Value.Quest.RowId; return new AetherCurrentInfo(y.RowId, rowId != 0, rowId); }).ToImmutableList()); _questCurrents = (from info in _allCurrentsByTerritory.Values.SelectMany((ImmutableList list) => list) where info.IsQuestGated select info).ToImmutableDictionary((AetherCurrentInfo info) => info.AetherCurrentId, (AetherCurrentInfo info) => info.QuestId); } public bool IsValidAetherCurrent(ushort territoryId, uint aetherCurrentId) { ImmutableList 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 GetCurrentsForTerritory(ushort territoryId) { return _allCurrentsByTerritory.GetValueOrDefault(territoryId, ImmutableList.Create(default(ReadOnlySpan))); } public AetherCurrentPosition? GetOverworldPosition(uint aetherCurrentId) { return OverworldPositions.GetValueOrDefault(aetherCurrentId); } public uint? GetQuestIdForCurrent(uint aetherCurrentId) { return _questCurrents.GetValueOrDefault(aetherCurrentId); } private ImmutableDictionary BuildOverworldPositions() { HashSet hashSet = _overworldCurrents.Values.SelectMany((ImmutableList list) => list).ToHashSet(); Dictionary dictionary = new Dictionary(); using (ExcelSheet.Enumerator enumerator = _dataManager.GetExcelSheet().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 dictionary2 = dictionary.ToDictionary((KeyValuePair kv) => kv.Value, (KeyValuePair kv) => kv.Key); ImmutableDictionary.Builder builder = ImmutableDictionary.CreateBuilder(); using (ExcelSheet.Enumerator enumerator2 = _dataManager.GetExcelSheet().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(); } }