-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCharacter.cs
180 lines (150 loc) · 8.85 KB
/
Character.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
using UnityEngine;
using static StatSystem.ModifierType;
namespace StatSystem.Example
{
public class Character : MonoBehaviour
{
[SerializeField] private Stat strength;
[SerializeField] private Stat dexterity;
private readonly BootsOfSpeed _bootsOfSpeed = new();
private readonly GlovesOfStrength _glovesOfStrength = new();
private readonly EnchantedArmor _enchantedArmor = new();
private readonly AmazingSword _amazingSword = new();
private readonly WitchKillerAxe _witchKillerAxe = new();
private ModifierType _baseAbsoluteReduction;
private class BootsOfSpeed
{
public readonly Modifier DexterityModFlat;
public readonly Modifier DexterityModAdditive;
public readonly Modifier StrengthModAdditive;
public readonly Modifier DexterityModMulti;
public BootsOfSpeed()
{
DexterityModFlat = new Modifier(10f, Flat, this);
DexterityModAdditive = new Modifier(0.2f, Additive, this);
StrengthModAdditive = new Modifier(-0.1f, Additive, this);
DexterityModMulti = new Modifier(0.1f, Multiplicative, this);
}
}
private class GlovesOfStrength
{
public readonly Modifier StrengthModAdditive;
public GlovesOfStrength()
=> StrengthModAdditive = new Modifier(0.3f, Additive, this);
}
private class EnchantedArmor
{
public readonly Modifier StrengthModMulti;
public readonly Modifier DexterityModMulti;
public EnchantedArmor()
{
StrengthModMulti = new Modifier(0.1f, Multiplicative, this);
DexterityModMulti = new Modifier(0.3f, Multiplicative, this);
}
}
private class AmazingSword
{
public readonly Modifier StrengthModMulti;
public readonly Modifier StrengthModFlat;
public AmazingSword()
{
StrengthModMulti = new Modifier(0.2f, Multiplicative, this);
StrengthModFlat = new Modifier(20f, Flat, this);
}
}
private class WitchKillerAxe
{
public readonly Modifier StrengthModMulti;
public readonly Modifier DexterityModMulti;
public WitchKillerAxe()
{
StrengthModMulti = new Modifier(-0.1f,Multiplicative, this);
DexterityModMulti = new Modifier(0.5f, Multiplicative, this);
}
}
private void Awake()
{
_baseAbsoluteReduction = Stat.NewModifierType(400, () => new ModifierOperationsBaseAbsoluteReduction());
}
void Start()
{
strength = new Stat(100);
dexterity = new Stat(50);
Modifier strengthCurse = new Modifier(0.2f, _baseAbsoluteReduction);
Modifier witchCurse = new Modifier(0.4f, _baseAbsoluteReduction);
Debug.Log($"Initial Strength: {strength.Value} and Dexterity: {dexterity.Value}");
// strength = 100 - 0.1*100 = 90, dexterity = (50 + 10 + 0.2 * 50) * 1.1 = 77
Debug.Log("Equipping boots of speed (-10% strength additive, 10 flat dexterity, 20% additive dexterity, 10% multiplicative dexterity)");
strength.AddModifier(_bootsOfSpeed.StrengthModAdditive);
dexterity.AddModifier(_bootsOfSpeed.DexterityModFlat);
dexterity.AddModifier(_bootsOfSpeed.DexterityModAdditive);
dexterity.AddModifier(_bootsOfSpeed.DexterityModMulti);
Debug.Log($"Stats are now, Strength {strength.Value} and Dexterity {dexterity.Value}");
// strength = 100 - 0.1 * 100 + 0.3 * 100 = 120
Debug.Log("Equipping Gloves Of Strength (30% strength additive)");
strength.AddModifier(_glovesOfStrength.StrengthModAdditive);
Debug.Log($"Stats are now, Strength {strength.Value} and Dexterity {dexterity.Value}");
// strength = (100 - 0.1 * 100 + 0.3 * 100) * 1.1 = 132, dexterity = (50 + 10 + 0.2 * 50) * 1.1 * 1.3 = 100.1
Debug.Log("Equipping Enchanted Armor (10% strength multiplicative, 30% dexterity multiplicative)");
strength.AddModifier(_enchantedArmor.StrengthModMulti);
dexterity.AddModifier(_enchantedArmor.DexterityModMulti);
Debug.Log($"Stats are now, Strength {strength.Value} and Dexterity {dexterity.Value}");
// strength = (100 + 0.3 * 100) * 1.1 = 143,
// dexterity = 50 * 1.3 = 65
Debug.Log("Removing boots of speed (-10% strength additive, 10 flat dexterity, 20% additive dexterity, 10% multiplicative dexterity)");
strength.TryRemoveAllModifiersOf(_bootsOfSpeed);
dexterity.TryRemoveAllModifiersOf(_bootsOfSpeed);
Debug.Log($"Stats are now, Strength {strength.Value} and Dexterity {dexterity.Value}");
// strength = (100 + 0.3 * 100 - 0.1 * 100) * 1.1 = 132,
// dexterity = (50 + 10 + 0.2 * 50) * 1.1 * 1.3 = 100.1
Debug.Log("Equipping boots of Speed again (-10% strength additive, 10 flat dexterity, 20% additive dexterity, 10% multiplicative dexterity)");
strength.AddModifier(_bootsOfSpeed.StrengthModAdditive);
dexterity.AddModifier(_bootsOfSpeed.DexterityModFlat);
dexterity.AddModifier(_bootsOfSpeed.DexterityModAdditive);
dexterity.AddModifier(_bootsOfSpeed.DexterityModMulti);
Debug.Log($"Stats are now, Strength {strength.Value} and Dexterity {dexterity.Value}");
// strength = (100 + 20 + 0.3 * 100 - 0.1 * 100) * 1.1 * 1.2 = 184.8
Debug.Log("Equipping Amazing Sword (20 flat strength, 20% multiplicative strength)");
strength.AddModifier(_amazingSword.StrengthModFlat);
strength.AddModifier(_amazingSword.StrengthModMulti);
Debug.Log($"Stats are now, Strength {strength.Value} and Dexterity {dexterity.Value}");
// strength suppressed((100 + 20 + 0.3 * 100 - 0.1 * 100) * 1.1 * 1.2 = 184.8) = base value (100) * 0.8 = 80
Debug.Log("The player drinks a curse potion! (20% strength absolute reduction and suppresses all modifiers)");
strength.AddModifier(strengthCurse);
Debug.Log($"Stats are now, Strength {strength.Value} and Dexterity {dexterity.Value}");
// strength suppressed((100 + 0.3 * 100 - 0.1 * 100) * 1.1 = 132) = base value (100) * 0.8 = 80
Debug.Log("A witch appears and makes the player drop the Amazing Sword (20 flat strength, 20% multiplicative strength)");
strength.TryRemoveAllModifiersOf(_amazingSword);
Debug.Log($"Stats are now, Strength {strength.Value} and Dexterity {dexterity.Value}");
// strength suppressed((100 + 0.3 * 100 - 0.1 * 100) * 1.1 = 132) = base value (100) * 0.6 = 60
Debug.Log("The witch casts a witch curse! (40% strength absolute reduction and suppresses all modifiers)");
strength.AddModifier(witchCurse);
Debug.Log($"Stats are now, Strength {strength.Value} and Dexterity {dexterity.Value}");
// strength suppressed((100 + 0.3 * 100 - 0.1 * 100) * 1.1 * 0.9 = 118.8) = base value (100) * 0.6 = 60,
// dexterity = (50 + 10 + 0.2 * 50) * 1.1 * 1.3 * 1.5 = 150.15
Debug.Log("The player equips the WitchKillerAxe (-10% strength multiplicative, 50% dexterity multiplicative)");
strength.AddModifier(_witchKillerAxe.StrengthModMulti);
dexterity.AddModifier(_witchKillerAxe.DexterityModMulti);
Debug.Log($"Stats are now, Strength {strength.Value} and Dexterity {dexterity.Value}");
// strength suppressed((100 + 0.3 * 100 - 0.1 * 100) * 1.1 * 0.9 = 118.8) = base value (100) * 0.6 = 60,
Debug.Log("The curse potion effect wears off! (20% strength absolute reduction and suppresses all modifiers)");
strength.TryRemoveModifier(strengthCurse);
Debug.Log($"Stats are now, Strength {strength.Value} and Dexterity {dexterity.Value}");
// strength = (100 + 0.3 * 100 - 0.1 * 100) * 1.1 * 0.9 = 118.8
Debug.Log("The witch curse wears off! (40% strength absolute reduction and suppresses all modifiers)");
strength.TryRemoveModifier(witchCurse);
Debug.Log($"Stats are now, Strength {strength.Value} and Dexterity {dexterity.Value}");
// strength = (100 + 0.3 * 100 - 0.1 * 100) * 1.1 = 132,
// dexterity = (50 + 10 + 0.2 * 50) * 1.1 * 1.3 = 100.1
Debug.Log("The player kills the witch, removes the WitchKillerAxe (-10% strength multiplicative, 50% dexterity multiplicative)");
strength.TryRemoveAllModifiersOf(_witchKillerAxe);
dexterity.TryRemoveAllModifiersOf(_witchKillerAxe);
Debug.Log($"Stats are now, Strength {strength.Value} and Dexterity {dexterity.Value}");
// strength = (100 + 20 + 0.3 * 100 - 0.1 * 100) * 1.1 * 1.2 = 184.8
Debug.Log("The player equips his Amazing Sword again (20 flat strength, 20% multiplicative strength)");
strength.AddModifier(_amazingSword.StrengthModFlat);
strength.AddModifier(_amazingSword.StrengthModMulti);
Debug.Log($"Stats are now, Strength {strength.Value} and Dexterity {dexterity.Value}");
}
}
}