-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSpellTest.cs
313 lines (276 loc) · 9.98 KB
/
SpellTest.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using swlSimulator.api;
using swlSimulator.api.Combat;
using swlSimulator.api.Models;
using swlSimulator.api.Spells;
using swlSimulator.api.Spells.Hammer;
using swlSimulator.api.Weapons;
using swlSimulator.Models;
namespace swlSimulator.Tests
{
[TestClass]
public class SpellTest
{
[TestMethod]
public void TestIterationGcd()
{
var setting = TestSettingsHammerFist();
setting.Apl = "Hammer.Smash";
setting.Iterations = 2;
setting.FightLength = 10;
setting.TargetType = TargetType.Champion;
var engine = new Engine(setting);
var iterations = engine.StartIterations();
var fight1 = iterations.FirstOrDefault();
var fight2 = iterations.LastOrDefault();
var iterationCount = iterations.Count;
var endTime1 = fight1.RoundResults.Last().TimeSec;
var rounds1 = fight1.RoundResults.Count;
var endTime2 = fight2.RoundResults.Last().TimeSec;
var rounds2 = fight2.RoundResults.Count;
var spellCount = fight1.RoundResults
.SelectMany(r => r.Attacks.Where(a => a.Spell.GetType() == typeof(Smash))).Count();
spellCount += fight2.RoundResults
.SelectMany(r => r.Attacks.Where(a => a.Spell.GetType() == typeof(Smash))).Count();
Assert.AreEqual(iterationCount, 2);
Assert.AreEqual(endTime1, 10.0m);
Assert.AreEqual(rounds1, 11);
Assert.AreEqual(endTime2, 10.0m);
Assert.AreEqual(rounds2, 11);
Assert.IsTrue(spellCount == 22);
}
[TestMethod]
public void TestCastSpell()
{
var setting = new Settings
{
PrimaryWeapon = WeaponType.Elemental,
SecondaryWeapon = WeaponType.Fist,
FightLength = 10,
TargetType = TargetType.Champion,
Apl = "Elemental.TestCastSpell"
};
var spell = new CastSpell();
var player = new Player(setting);
player.Spells.Add(spell);
var engine = new Engine(setting);
var fight = engine.StartFight(player);
var endTime = fight.RoundResults.Last().TimeSec;
var rounds = fight.RoundResults.Count;
var castCount = fight.RoundResults
.SelectMany(r => r.Attacks.Where(a => a.Spell is CastSpell)).Count();
// 0.0, start cast
// 2.5, finish cast
// 2.5, start next cast
// 5.0, finish cast
// 5.0, start next cast
// 7.5, finish cast
// 7.5, start next cast
// 10.0, finish cast
Assert.AreEqual(rounds, 4);
Assert.AreEqual(endTime, 10.0m);
Assert.IsTrue(castCount == 4);
}
[TestMethod]
public void TestChannelSpell()
{
var setting = new Settings
{
PrimaryWeapon = WeaponType.Blood,
SecondaryWeapon = WeaponType.Fist,
FightLength = 10,
TargetType = TargetType.Champion,
Apl = "Blood.ChannelSpell"
};
var spell = new ChannelSpell();
var player = new Player(setting);
player.Spells.Add(spell);
var engine = new Engine(setting);
var fight = engine.StartFight(player);
var endTime = fight.RoundResults.Last().TimeSec;
var rounds = fight.RoundResults.Count;
var channelTickCount = fight.RoundResults
.SelectMany(r => r.Attacks.Where(a => a.Spell is ChannelSpell)).Count();
// 0.0, start channel
// 0.5, channel tick
// 1.0, channel tick
// 1.5, channel tick
// 2.0, channel tick
// 2.5, channel tick
// 2.5, finish channel
// 2.5, start next channel
// 3.0, channel tick
// 3.5, channel tick
// 4.0, channel tick
// 4.5, channel tick
// 5.0, channel tick
// 5.0, finish channel
// 5.0, start next channel
// 5.5, channel tick
// 6.0, channel tick
// 6.5, channel tick
// 7.0, channel tick
// 7.5, channel tick
// 7.5, finish channel
// 7.5, start next channel
// 8.0, channel tick
// 8.5, channel tick
// 9.0, channel tick
// 9.5, channel tick
// 10.0, channel tick
// 10.0, finish channel
Assert.AreEqual(rounds, 20);
Assert.AreEqual(endTime, 10.0m);
Assert.IsTrue(channelTickCount == 20);
}
//[TestMethod]
//public void TestDotSpell()
//{
// var setting = new Settings
// {
// PrimaryWeapon = WeaponType.Blood,
// SecondaryWeapon = WeaponType.Fist,
// FightLength = 10,
// TargetType = TargetType.Champion,
// Apl = "Blood.DotSpell"
// };
// var spell = new DotSpell();
// var player = new Player(setting);
// player.Spells.Add(spell);
// var engine = new Engine(setting);
// var fight = engine.StartFight(player);
// var endTime = fight.RoundResults.Last().TimeSec;
// var rounds = fight.RoundResults.Count;
// var dotTickCount = fight.RoundResults
// .SelectMany(r => r.Attacks.Where(a => a.Spell is DotSpell)).Count();
// // TODO: Dot ticks should NOT add any kind of bonus attacks?
// // 0.0, start dot
// // 0.5, dot tick
// // 1.0, dot tick
// // 1.5, dot tick
// // 2.0, dot tick
// // 2.5, dot tick
// // 2.5, finish dot
// // 2.5, start next dot
// // 3.0, dot tick
// // 3.5, dot tick
// // 4.0, dot tick
// // 4.5, dot tick
// // 5.0, dot tick
// // 5.0, finish dot
// // 5.0, start next dot
// // 5.5, dot tick
// // 6.0, dot tick
// // 6.5, dot tick
// // 7.0, dot tick
// // 7.5, dot tick
// // 7.5, finish dot
// // 7.5, start next dot
// // 8.0, dot tick
// // 8.5, dot tick
// // 9.0, dot tick
// // 9.5, dot tick
// // 10.0, dot tick
// // 10.0, finish dot
// Assert.AreEqual(rounds, 20);
// Assert.AreEqual(endTime, 10.0m);
// Assert.IsTrue(dotTickCount == 20);
//}
[TestMethod]
public void TestGadgetSpell()
{
var setting = new Settings
{
PrimaryWeapon = WeaponType.Elemental,
SecondaryWeapon = WeaponType.Fist,
Gadget = Gadget.Test,
FightLength = 10,
TargetType = TargetType.Champion,
Apl = "Elemental.TestCastSpell"
};
var spell = new CastSpell();
var gadgetSpell = new GadgetSpell();
var player = new Player(setting);
player.Spells.Add(spell);
player.Item.Spells.Add(gadgetSpell);
var engine = new Engine(setting);
var fight = engine.StartFight(player);
var endTime = fight.RoundResults.Last().TimeSec;
var rounds = fight.RoundResults.Count;
var gadgetCount = fight.RoundResults
.SelectMany(r => r.Attacks.Where(a => a.Spell is GadgetSpell)).Count();
var castCount = fight.RoundResults
.SelectMany(r => r.Attacks.Where(a => a.Spell is CastSpell)).Count();
// 0.0, gadget
// 0.0, start cast
// 2.5, finish cast
// 2.5, gadget
// 2.5, start next cast
// 5.0, finish cast
// 5.0, gadget
// 5.0, start next cast
// 7.5, finish cast
// 7.5, gadget
// 7.5, start next cast
// 10.0, finish cast
// 10.0, gadget
Assert.AreEqual(rounds, 5);
Assert.AreEqual(endTime, 10.0m);
Assert.IsTrue(gadgetCount == 5);
Assert.IsTrue(castCount == 4);
}
private Settings TestSettingsHammerFist()
{
return new Settings
{
PrimaryWeapon = WeaponType.Hammer,
SecondaryWeapon = WeaponType.Fist,
};
}
private sealed class CastSpell : Spell
{
public CastSpell()
{
WeaponType = WeaponType.Elemental;
SpellType = SpellType.Cast;
CastTime = 2.5m;
BaseDamage = 1;
}
}
private sealed class ChannelSpell : Spell
{
public ChannelSpell()
{
WeaponType = WeaponType.Blood;
SpellType = SpellType.Channel;
CastTime = 2.5m;
ChannelTicks = 5;
BaseDamage = 1;
}
}
private sealed class DotSpell : Spell
{
public DotSpell()
{
WeaponType = WeaponType.Blood;
SpellType = SpellType.Dot;
CastTime = 0;
DotDuration = 2.5m;
DotTicks = 5;
BaseDamage = 1;
// TODO: Add ability debuff
}
}
private sealed class GadgetSpell : Spell
{
public GadgetSpell()
{
WeaponType = WeaponType.None;
AbilityType = AbilityType.Gadget;
SpellType = SpellType.Instant;
MaxCooldown = 2.5m;
}
}
}
}