-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
LootUnifiedRandom.cs
63 lines (54 loc) · 1.55 KB
/
LootUnifiedRandom.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using Terraria;
using Terraria.Utilities;
namespace RecipeBrowser
{
internal class LootUnifiedRandom : UnifiedRandom
{
//internal static int entropy;
internal static int loop;
//internal static bool zero;
private int[] returns;
// realRandom avoids deadlock caused by re-rolling prefixes
internal UnifiedRandom realRandom;
public LootUnifiedRandom()
{
returns = new int[5000];
}
public override int Next(int maxValue)
{
if (loop == 0 && !realRandom.NextBool(100)) return 0;
int index = Math.Abs(maxValue) % 5000;
returns[index]++;
return (maxValue + returns[index]) % maxValue;
}
public override int Next(int minValue, int maxValue)
{
if (loop == 0) return minValue;
if (minValue == maxValue) return minValue;
int index = Math.Abs(maxValue) % 5000;
returns[index]++;
return minValue + ((maxValue + returns[index]) % (maxValue - minValue));
}
public override double NextDouble()
{
if (loop == 0) return 0.0;
return base.NextDouble();
}
// public override int Next(int maxValue)
// {
//if (loop == 0) return 0;
//entropy += 257;
//if (loop % 7 == 0 && maxValue > 20 && entropy % 13 == 0) return 0;
//entropy += loop + maxValue;
//entropy = entropy < 0 ? 0 : entropy;
// return (maxValue + entropy) % maxValue;
// }
// public override int Next(int minValue, int maxValue)
// {
//if (loop == 0) return minValue;
//entropy += loop + maxValue;
// return minValue + ((maxValue + entropy) % (maxValue - minValue));
// }
}
}