-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStatsManager.cs
More file actions
156 lines (137 loc) · 4.26 KB
/
StatsManager.cs
File metadata and controls
156 lines (137 loc) · 4.26 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
namespace HasteEffects;
/// <summary>
/// Holds a single player stat, including UI and settings
/// </summary>
public class StatHolder
{
private readonly HastyCollapsible _hastyCol;
/// <summary>
/// Initializes a new instance of the <see cref="StatHolder"/> class, creating all associated Hasty settings.
/// </summary>
/// <param name="stat">The stat this holder represents.</param>
/// <param name="cfg">The parent HastySetting configuration.</param>
/// <param name="defaultMinMax">The default minimum and maximum values for the stat.</param>
/// <param name="enabled">Whether the stat is enabled by default.</param>
public StatHolder(Stat stat, HastySetting cfg, Unity.Mathematics.float2 defaultMinMax, bool enabled = true)
{
// Store
Stat = stat;
// Create a new collapsible section for the stat
_hastyCol = new HastyCollapsible(cfg, stat.ToString(), $"Settings for <b>{stat}</b>");
// Create hasty floats for the min and max values
HastyFloatMin = new HastyFloat(_hastyCol, stat.ToString(), "Minimum", new(0, 5, defaultMinMax.x));
HastyFloatMax = new HastyFloat(_hastyCol, stat.ToString(), "Maximum", new(0, 5, defaultMinMax.y));
// Create the hasty bool for enabling/disabling the stat
HastyBoolEnabled = new HastyBool(_hastyCol, stat.ToString(), "Enable or disable this stat", new("Disabled", "Enabled", enabled));
// Reset single stat button
HastyButtonReset = new HastyButton(_hastyCol, "Reset", $"Reset <b>{stat}</b>'s stats", new() { ButtonText = "Reset", OnClicked = Reset });
}
/// <summary>
/// Gets the HastyBool setting for enabling/disabling the stat.
/// </summary>
public HastyBool HastyBoolEnabled { get; private set; }
/// <summary>
/// Gets the HastyButton for resetting the stat.
/// </summary>
public HastyButton HastyButtonReset { get; private set; }
/// <summary>
/// Gets the collapsible group for this stat.
/// </summary>
public HastyCollapsible HastyCol => _hastyCol;
/// <summary>
/// Gets the HastyFloat for the maximum value.
/// </summary>
public HastyFloat HastyFloatMax { get; private set; }
/// <summary>
/// Gets the HastyFloat for the minimum value.
/// </summary>
public HastyFloat HastyFloatMin { get; private set; }
/// <summary>
/// Gets the maximum value, ensuring it is not less than the minimum.
/// </summary>
public float Max
{
get
{
if (HastyFloatMax.Value <= HastyFloatMin.Value)
{
Informer.Inform($"<b>{Stat}</b> max value is less than or equal to min value. Setting max to default value.");
HastyFloatMax.Reset();
return HastyFloatMax.Value;
}
return HastyFloatMax.Value;
}
}
/// <summary>
/// Gets the minimum value, ensuring it is not greater than the maximum.
/// </summary>
public float Min
{
get
{
if (HastyFloatMin.Value >= HastyFloatMax.Value)
{
Informer.Inform($"<b>{Stat}</b> min value is greater than or equal to max value. Setting min to default value.");
HastyFloatMin.Reset();
return HastyFloatMin.Value;
}
return HastyFloatMin.Value;
}
}
/// <summary>
/// Gets the display name for this stat.
/// </summary>
public string Name => Stat.ToString();
/// <summary>
/// Gets the associated PlayerStat instance for this stat.
/// </summary>
public PlayerStat PStat
{
get
{
return (PlayerStat)Player.localPlayer.stats.GetType()
.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)
.Where(f => f.FieldType == typeof(PlayerStat))
.FirstOrDefault(f => f.Name.Contains(Stat.ToString(), StringComparison.OrdinalIgnoreCase))
.GetValue(Player.localPlayer.stats);
}
}
/// <summary>
/// Gets a random value between Min and Max for this stat.
/// </summary>
public float RandomVal => UnityEngine.Random.Range(Min, Max);
/// <summary>
/// Gets the stat type this holder represents.
/// </summary>
public Stat Stat { get; private set; }
/// <summary>
/// Resets all settings for this stat to their default values.
/// </summary>
public void Reset()
{
HastyFloatMax.Reset();
HastyFloatMin.Reset();
HastyBoolEnabled.Reset();
}
}
/// <summary>
/// All supported player stats.
/// </summary>
public enum Stat
{
MaxHealth,
RunSpeed,
AirSpeed,
TurnSpeed,
Drag,
Gravity,
FastFall,
Dashes,
Boost,
Luck,
MaxEnergy,
SparkMulti,
EnergyGain,
DamageMulti,
PickupRange
}