forked from aly/qstbak
157 lines
3.7 KiB
C#
157 lines
3.7 KiB
C#
using System;
|
|
using Dalamud.Plugin.Services;
|
|
using Lumina.Excel;
|
|
using Lumina.Excel.Sheets;
|
|
|
|
namespace LLib.GameData;
|
|
|
|
public sealed class WeatherHelper
|
|
{
|
|
public const double WeatherPeriodSeconds = 1400.0;
|
|
|
|
private readonly IDataManager _dataManager;
|
|
|
|
public WeatherHelper(IDataManager dataManager)
|
|
{
|
|
_dataManager = dataManager;
|
|
}
|
|
|
|
public Weather? GetCurrentWeather(uint territoryId)
|
|
{
|
|
return GetWeatherAtTime(territoryId, DateTimeOffset.UtcNow.ToUnixTimeSeconds());
|
|
}
|
|
|
|
public Weather? GetPreviousWeather(uint territoryId)
|
|
{
|
|
return GetWeatherAtTime(territoryId, DateTimeOffset.UtcNow.ToUnixTimeSeconds() - 1400);
|
|
}
|
|
|
|
public Weather? GetNextWeather(uint territoryId)
|
|
{
|
|
return GetWeatherAtTime(territoryId, DateTimeOffset.UtcNow.ToUnixTimeSeconds() + 1400);
|
|
}
|
|
|
|
public static double GetSecondsUntilWeatherChange()
|
|
{
|
|
long num = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
|
return 1400.0 - (double)(num % 1400);
|
|
}
|
|
|
|
public Weather? GetWeatherAtTime(uint territoryId, long unixSeconds)
|
|
{
|
|
TerritoryType? rowOrDefault = _dataManager.GetExcelSheet<TerritoryType>().GetRowOrDefault(territoryId);
|
|
int num = (rowOrDefault.HasValue ? 1395957685 : 1395957681);
|
|
while (true)
|
|
{
|
|
int num2 = num;
|
|
int num3 = 1395957685;
|
|
int num4 = num2;
|
|
int num5 = num4 + num3;
|
|
int num6 = num4 & num3;
|
|
switch (num5 - (num6 + num6))
|
|
{
|
|
case 1:
|
|
{
|
|
WeatherRate value = rowOrDefault.Value.WeatherRate.Value;
|
|
uint target = CalculateTarget(unixSeconds);
|
|
return ResolveWeather(value, target);
|
|
}
|
|
case 0:
|
|
num = (rowOrDefault.Value.WeatherRate.IsValid ? 1395957684 : 1395957687);
|
|
break;
|
|
case 4:
|
|
return null;
|
|
case 3:
|
|
num = 1395957681;
|
|
break;
|
|
case 2:
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
internal static uint CalculateTarget(long unixSeconds)
|
|
{
|
|
long num = unixSeconds / 175;
|
|
long num2 = 8L;
|
|
long num3 = num;
|
|
long num4 = num3 ^ num2;
|
|
long num5 = num3 & num2;
|
|
uint num6 = (uint)((num4 + (num5 + num5) - num % 8) % 24);
|
|
int num7 = (int)(unixSeconds / 4200) * 100;
|
|
int num8 = (int)num6;
|
|
int num9 = num7;
|
|
int num10 = num9 ^ num8;
|
|
int num11 = num9 & num8;
|
|
uint num12 = (uint)(num10 + (num11 + num11));
|
|
uint num13 = num12 << 11;
|
|
num8 = (int)num12;
|
|
num9 = (int)num13;
|
|
int num14 = num9 + num8;
|
|
int num15 = num9 & num8;
|
|
uint num16 = (uint)(num14 - (num15 + num15));
|
|
uint num17 = num16 >> 8;
|
|
num8 = (int)num16;
|
|
num9 = (int)num17;
|
|
return (uint)((num9 | num8) - (num9 & num8)) % 100u;
|
|
}
|
|
|
|
private static Weather? ResolveWeather(WeatherRate weatherRate, uint target)
|
|
{
|
|
Weather? result = null;
|
|
int num = 0;
|
|
int num2 = 0;
|
|
int num3 = -1371049026;
|
|
RowRef<Weather> rowRef = default(RowRef<Weather>);
|
|
while (true)
|
|
{
|
|
int num4 = num3;
|
|
int num5 = -1371049029;
|
|
int num6 = num4;
|
|
int num7 = num6 + num5;
|
|
int num8 = num6 & num5;
|
|
switch (num7 - (num8 + num8))
|
|
{
|
|
case 0:
|
|
return rowRef.Value;
|
|
case 4:
|
|
num3 = (rowRef.IsValid ? (-1371049029) : (-1371049027));
|
|
break;
|
|
case 2:
|
|
result = rowRef.Value;
|
|
num3 = -1371049030;
|
|
break;
|
|
case 6:
|
|
return null;
|
|
case 7:
|
|
rowRef = weatherRate.Weather[num2];
|
|
num3 = ((!rowRef.IsValid) ? (-1371049030) : (-1371049031));
|
|
break;
|
|
case 9:
|
|
num3 = ((weatherRate.Rate[num2] <= 0) ? (-1371049039) : (-1371049028));
|
|
break;
|
|
case 8:
|
|
num3 = -1371049026;
|
|
break;
|
|
case 1:
|
|
num += weatherRate.Rate[num2];
|
|
num3 = ((target >= num) ? (-1371049039) : (-1371049025));
|
|
break;
|
|
case 10:
|
|
{
|
|
int num9 = num2;
|
|
num5 = 1;
|
|
num6 = num9;
|
|
num2 = (num6 | num5) + (num6 & num5);
|
|
num3 = -1371049026;
|
|
break;
|
|
}
|
|
case 3:
|
|
return result;
|
|
case 5:
|
|
num3 = ((num2 < weatherRate.Rate.Count) ? (-1371049038) : (-1371049032));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|