96 lines
2.4 KiB
C#
96 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Dalamud.Plugin.Services;
|
|
using Lumina.Excel.Sheets;
|
|
|
|
namespace LLib.GameData;
|
|
|
|
public sealed class SatisfactionSupplyHelper
|
|
{
|
|
private readonly IDataManager _dataManager;
|
|
|
|
public SatisfactionSupplyHelper(IDataManager dataManager)
|
|
{
|
|
_dataManager = dataManager;
|
|
}
|
|
|
|
public uint[] CalculateRequestedItems(uint supplyIndex, uint seed)
|
|
{
|
|
List<SatisfactionSupply> list = new List<SatisfactionSupply>();
|
|
foreach (SatisfactionSupply item in _dataManager.GetSubrowExcelSheet<SatisfactionSupply>().Flatten())
|
|
{
|
|
if (item.RowId == supplyIndex)
|
|
{
|
|
list.Add(item);
|
|
}
|
|
}
|
|
uint num = (63874652 * supplyIndex) ^ (437113358 * seed);
|
|
uint num2 = (uint)(-547857059 * (int)supplyIndex) ^ (811033966 * seed);
|
|
uint num3 = (uint)(-311827390 * (int)supplyIndex) ^ (570616410 * seed);
|
|
uint num4 = (uint)((-1359202047 * (int)supplyIndex) ^ (-418962442 * (int)seed));
|
|
uint[] array = new uint[3] { 4294967295u, 4294967295u, 4294967295u };
|
|
uint num5 = num;
|
|
for (int i = 1; i < 4; i++)
|
|
{
|
|
int num6 = 0;
|
|
for (int j = 0; j < list.Count; j++)
|
|
{
|
|
SatisfactionSupply satisfactionSupply = list[j];
|
|
if (satisfactionSupply.Slot == i)
|
|
{
|
|
num6 += satisfactionSupply.ProbabilityPercent;
|
|
}
|
|
}
|
|
uint num7 = num5 ^ (num5 << 11);
|
|
num = num3;
|
|
num3 = num4;
|
|
num5 = num2;
|
|
num4 ^= num7 ^ ((num7 ^ (num4 >> 11)) >> 8);
|
|
num2 = num;
|
|
if (num6 <= 0)
|
|
{
|
|
continue;
|
|
}
|
|
long num8 = num4 % num6;
|
|
for (int k = 0; k < list.Count; k++)
|
|
{
|
|
SatisfactionSupply satisfactionSupply2 = list[k];
|
|
if (satisfactionSupply2.Slot == i)
|
|
{
|
|
if (num8 < satisfactionSupply2.ProbabilityPercent)
|
|
{
|
|
array[i - 1] = (uint)k;
|
|
break;
|
|
}
|
|
num8 -= satisfactionSupply2.ProbabilityPercent;
|
|
}
|
|
}
|
|
}
|
|
return array;
|
|
}
|
|
|
|
public int CalculateBonusGuaranteeIndex(int timestamp)
|
|
{
|
|
int count = _dataManager.GetExcelSheet<SatisfactionBonusGuarantee>().Count;
|
|
if (count == 0)
|
|
{
|
|
return -1;
|
|
}
|
|
return (timestamp - 1657008000) / 604800 % count;
|
|
}
|
|
|
|
public static int CalculateTurnInsToNextRank(ushort currentSatisfaction, ushort maxSatisfaction, int maxTurnIns)
|
|
{
|
|
if (currentSatisfaction >= maxSatisfaction)
|
|
{
|
|
return maxTurnIns;
|
|
}
|
|
int num = maxSatisfaction - currentSatisfaction;
|
|
int num2 = maxSatisfaction / maxTurnIns;
|
|
if (num2 == 0)
|
|
{
|
|
return maxTurnIns;
|
|
}
|
|
return Math.Min((int)Math.Ceiling((double)num / (double)num2), maxTurnIns);
|
|
}
|
|
}
|