-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulator.go
285 lines (258 loc) · 8.74 KB
/
simulator.go
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
package main
import (
"fmt"
"os"
"strconv"
)
const timeIncrement float64 = 0.01
type simulator struct {
Players []*playerCharacter
Enemies []*enemy
}
type simResult struct {
skillCount int
critCount int
directCount int
critDirectCount int
totalDamageDone int
timeEllapsed float64
skillsPerformed []int
autoAttacks int
dotTicks int
totalHits int
}
type simResultCollection struct {
results []simResult
}
func (s *simulator) RunSkillQueue(SkillQueue []string) simResult {
currentSkillIndex := 0
var totalResult simResult
totalResult.skillsPerformed = make([]int, len(s.Players[0].Skills))
for currentSkillIndex < len(SkillQueue) {
for i := range s.Players {
results := enemies[0].advanceTime(timeIncrement)
if results != nil {
totalResult.dotTicks += len(results)
}
// First advance time to take care of Dots, Cooldowns, and Autos
timeResult := s.Players[i].advanceTime(timeIncrement, enemies[0])
if timeResult != nil {
totalResult.autoAttacks++
if results != nil {
results = append(results, *timeResult)
} else {
results = []skillResult{*timeResult}
}
}
for _, result := range results {
enemies[0].applyDamage(&result)
result.Log()
result.ApplyBuffs(*s.Players[i])
totalResult.totalDamageDone += result.DamageDone
totalResult.totalHits++
if result.DidCrit {
totalResult.critCount++
}
if result.DidDirect {
totalResult.directCount++
}
if result.DidCrit && result.DidDirect {
totalResult.critDirectCount++
}
}
totalResult.timeEllapsed += timeIncrement
// Next attempt to perform the next action in the queue
actionResult := s.Players[i].performAction(SkillQueue[currentSkillIndex], enemies[0])
if actionResult != nil {
enemies[0].applyDamage(actionResult)
actionResult.Log()
actionResult.ApplyBuffs(*s.Players[i])
totalResult.totalDamageDone += actionResult.DamageDone
totalResult.skillsPerformed[actionResult.SkillIndex]++
currentSkillIndex++
totalResult.skillCount++
totalResult.totalHits++
if actionResult.DidCrit {
totalResult.critCount++
}
if actionResult.DidDirect {
totalResult.directCount++
}
if actionResult.DidCrit && actionResult.DidDirect {
totalResult.critDirectCount++
}
}
}
}
return totalResult
}
func (s *simulator) RunParse(parsedSkills []parsedSkill) simResult {
var totalResult simResult
totalResult.skillsPerformed = make([]int, len(s.Players[0].Skills))
currentSkillIndex := 0
simErrors := 0
validSkills := 0
invalidSkills := 0
for _, skill := range parsedSkills {
if skill.Ability == "Attack" {
continue
}
skillPerformed := false
for skillPerformed == false {
if totalResult.timeEllapsed >= skill.RelativeTime && skill.Ability != "Attack" {
// Perform current action
actionResult := s.Players[0].performAction(skill.Ability, enemies[0])
if actionResult != nil {
enemies[0].applyDamage(actionResult)
actionResult.Log()
actionResult.ApplyBuffs(*s.Players[0])
totalResult.totalDamageDone += actionResult.DamageDone
totalResult.skillsPerformed[actionResult.SkillIndex]++
currentSkillIndex++
totalResult.skillCount++
totalResult.totalHits++
if actionResult.DidCrit {
totalResult.critCount++
}
if actionResult.DidDirect {
totalResult.directCount++
}
if actionResult.DidCrit && actionResult.DidDirect {
totalResult.critDirectCount++
}
} else {
globalLog(Important, "SKILL UNAVAILABLE ERROR: "+skill.Ability)
simErrors++
}
skillPerformed = true
// Reset timing, as the logs may have latency in them.
s.Players[0].GCDTimeRemaining = 0
s.Players[0].IsGCDOnCooldown = false
s.Players[0].AnimationLock = 0
// Check Damage
if skill.Crit == actionResult.DidCrit && skill.Direct == actionResult.DidDirect {
damage := actionResult.BaseDamageDone
if actionResult.DidCrit {
damage *= actionResult.CritMultiplier
}
if actionResult.DidDirect {
damage *= 1.25
}
lowerBound := float64(damage) * 0.95
upperBound := float64(damage) * 1.05
lowerBound *= actionResult.DamageBuff
upperBound *= actionResult.DamageBuff
if float64(skill.Damage) >= lowerBound && float64(skill.Damage) <= upperBound {
globalLog(Basic, "SKILL VALIDATED")
skill.Validated = true
validSkills++
} else {
globalLog(Important, "INVALID DAMAGE")
globalLog(Important, "Simulated: "+strconv.Itoa(actionResult.DamageDone))
globalLog(Important, "Parse: "+strconv.FormatInt(skill.Damage, 10))
invalidSkills++
}
}
}
// Advance time to take care of Dots, Cooldowns, and Autos
results := enemies[0].advanceTime(timeIncrement)
if results != nil {
totalResult.dotTicks += len(results)
for i := range results {
totalResult.totalDamageDone += results[i].DamageDone
}
}
timeResult := s.Players[0].advanceTime(timeIncrement, enemies[0])
if timeResult != nil {
totalResult.totalDamageDone += timeResult.DamageDone
if timeResult.SkillName == "Attack" {
totalResult.autoAttacks++
}
// TODO Figure out proper logic here
//if skill.Ability == "Attack" {
// if s.Players[0].TotalTime > skill.RelativeTime+0.1 {
// globalLog(Important, "SKILL TIMING ERROR: "+skill.Ability)
// }
// skillPerformed = true
//} else {
// globalLog(Important, "AUTO ATTACK TIMING")
//}
if results != nil {
results = append(results, *timeResult)
} else {
results = []skillResult{*timeResult}
}
}
for _, result := range results {
enemies[0].applyDamage(&result)
result.Log()
result.ApplyBuffs(*s.Players[0])
totalResult.totalHits++
if result.DidCrit {
totalResult.critCount++
}
if result.DidDirect {
totalResult.directCount++
}
if result.DidCrit && result.DidDirect {
totalResult.critDirectCount++
}
}
totalResult.timeEllapsed += timeIncrement
}
}
globalLog(Important, "Total Errors: "+strconv.Itoa(simErrors))
globalLog(Important, "Validated Skills: "+strconv.Itoa(validSkills))
globalLog(Important, "Invalid Skills: "+strconv.Itoa(invalidSkills))
return totalResult
}
func (s *simResult) log() {
globalLog(Important, "Total Damage Done: "+strconv.Itoa(s.totalDamageDone))
globalLogFloat(Important, "Time ellapsed: ", s.timeEllapsed)
globalLogFloat(Important, "DPS: ", float64(s.totalDamageDone)/s.timeEllapsed)
globalLog(Important, "Skills performed: "+strconv.Itoa(s.skillCount))
globalLogFloat(Important, "Crit Rate: ", float64(s.critCount)/float64(s.totalHits))
globalLogFloat(Important, "Direct Rate: ", float64(s.directCount)/float64(s.totalHits))
globalLogFloat(Important, "CritDirect Rate: ", float64(s.critDirectCount)/float64(s.totalHits))
globalLogIntSlice(Important, "Skill Counts: ", s.skillsPerformed)
globalLogFloat(Important, "Auto Attacks: ", float64(s.autoAttacks))
globalLogFloat(Important, "DoT Ticks: ", float64(s.dotTicks))
globalLog(Important, "")
}
func (s *simResultCollection) add(res simResult) {
s.results = append(s.results, res)
}
func (s *simResultCollection) parseResults() {
var dps []float64
var critCountTotal int
var directCountTotal int
var critDirectCountTotal int
var totalHitsTotal int
var totalDamageDone int
var totalTimeEllapsed float64
for i := range s.results {
dps = append(dps, float64(s.results[i].totalDamageDone)/s.results[i].timeEllapsed)
critCountTotal += s.results[i].critCount
directCountTotal += s.results[i].directCount
critDirectCountTotal += s.results[i].critDirectCount
totalHitsTotal += s.results[i].totalHits
totalDamageDone += s.results[i].totalDamageDone
totalTimeEllapsed += s.results[i].timeEllapsed
}
globalLogFloat(Important, "Average Crit Rate: ", float64(critCountTotal)/float64(totalHitsTotal))
globalLogFloat(Important, "Average Direct Rate: ", float64(directCountTotal)/float64(totalHitsTotal))
globalLogFloat(Important, "Average Crit + Direct Rate: ", float64(critDirectCountTotal)/float64(totalHitsTotal))
globalLogFloat(Important, "Average DPS: ", float64(totalDamageDone)/totalTimeEllapsed)
}
func (s *simResultCollection) exportToCsv(fileName *string) {
f, err := os.Create(*fileName)
if err != nil {
globalLog(Important, "Error opening file: "+err.Error())
return
}
defer f.Close()
f.WriteString("SkillCount,CritCount,DirectCount,CritDirectCount,TotalDamageDone,TimeEllapsed,AutoAttacks,DotTicks,TotalHits\n")
for i := range s.results {
f.WriteString(fmt.Sprintf("%d,%d,%d,%d,%d,%f,%d,%d,%d\n", s.results[i].skillCount, s.results[i].critCount, s.results[i].directCount, s.results[i].critDirectCount, s.results[i].totalDamageDone, s.results[i].timeEllapsed, s.results[i].autoAttacks, s.results[i].dotTicks, s.results[i].totalHits))
}
}