forked from AaronV-T/AutoBiographer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMigrations.lua
More file actions
346 lines (303 loc) · 15.4 KB
/
Copy pathMigrations.lua
File metadata and controls
346 lines (303 loc) · 15.4 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
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
-- *** MigrationManager ***
AutoBiographer_MigrationManager = {
Migrations = {}
}
local MM = AutoBiographer_MigrationManager
function MM:GetLatestDatabaseVersion()
return #self.Migrations
end
function MM:RunMigrations(currentDatabaseVersion, eventManager, controller)
if (not currentDatabaseVersion) then currentDatabaseVersion = 0 end
if (currentDatabaseVersion >= #self.Migrations) then return end
for i = currentDatabaseVersion + 1, #self.Migrations do
self.Migrations[i]:Execute(eventManager, controller)
end
end
-- *** Migration Base Class ***
AutoBiographer_Migration = {}
function AutoBiographer_Migration:New(migrationNum, func)
return {
Execute = function(self, eventManager, controller)
controller:AddLog("Running migration " .. self.MigrationNumber .. "...", AutoBiographerEnum.LogLevel.Information)
func(eventManager, controller)
controller:AddLog("Migration " .. self.MigrationNumber .. " finished.", AutoBiographerEnum.LogLevel.Information)
eventManager.PersistentPlayerInfo.DatabaseVersion = self.MigrationNumber
end,
MigrationNumber = migrationNum
}
end
-- *** Concrete Migrations ***
table.insert(MM.Migrations,
AutoBiographer_Migration:New(
1,
function(eventManager, controller)
for k,v in pairs(controller.CharacterData.Levels) do
if (v.OtherPlayerStatisticsByOtherPlayer == nil) then v.OtherPlayerStatisticsByOtherPlayer = {} end
if (v.SpellStatisticsBySpell == nil) then v.SpellStatisticsBySpell = {} end
end
end
)
)
table.insert(MM.Migrations,
AutoBiographer_Migration:New(
2,
function(eventManager, controller)
if (AutoBiographer_Settings.Options["ShowMinimapButton"] == nil) then AutoBiographer_Settings.Options["ShowMinimapButton"] = true end
if (AutoBiographer_Settings.Options["ShowTimePlayedOnLevelUp"] == nil) then AutoBiographer_Settings.Options["ShowTimePlayedOnLevelUp"] = true end
end
)
)
table.insert(MM.Migrations,
AutoBiographer_Migration:New(
3,
function(eventManager, controller)
if (AutoBiographer_Settings.Options["EnableDebugLogging"] == nil) then AutoBiographer_Settings.Options["EnableDebugLogging"] = false end
if (AutoBiographer_Settings.Options["TakeScreenshotOnlyOnFirstBossKill"] == nil) then AutoBiographer_Settings.Options["TakeScreenshotOnlyOnFirstBossKill"] = true end
for k,v in pairs(controller.CharacterData.Levels) do
if (v.ExperienceStatistics == nil) then v.ExperienceStatistics = ExperienceStatistics.New() end
end
end
)
)
table.insert(MM.Migrations,
AutoBiographer_Migration:New(
4,
function(eventManager, controller)
-- Delete erroneous death events for pet classes.
local playerClass, englishClass = UnitClass("player")
if (englishClass == "HUNTER" or englishClass == "WARLOCK") then
local lastDeathTimestamp = nil
local indexesToDelete = {}
for i = 1, #controller.CharacterData.Events do
local event = controller.CharacterData.Events[i]
if (event.Type == AutoBiographerEnum.EventType.Death or event.SubType == AutoBiographerEnum.EventSubType.PlayerDeath) then
if (lastDeathTimestamp and (event.Timestamp - lastDeathTimestamp < 10)) then
indexesToDelete[i] = true
end
lastDeathTimestamp = event.Timestamp
end
end
HelperFunctions.RemoveElementsFromArrayAtIndexes(controller.CharacterData.Events, indexesToDelete)
controller:AddLog("Deleted " .. #HelperFunctions.GetKeysFromTable(indexesToDelete) .. " duplicate death events.", AutoBiographerEnum.LogLevel.Information)
end
-- Create MiscellaneousStatistics for each level.
for k,v in pairs(controller.CharacterData.Levels) do
if (v.MiscellaneousStatistics == nil) then v.MiscellaneousStatistics = MiscellaneousStatistics.New() end
end
-- Populate each level's MiscellaneousStatistics with death count.
local levelNum = HelperFunctions.GetKeysFromTable(controller.CharacterData.Levels, true)[1]
for i = 1, #controller.CharacterData.Events do
local event = controller.CharacterData.Events[i]
if (event.Type == AutoBiographerEnum.EventType.Level and event.SubType == AutoBiographerEnum.EventSubType.LevelUp) then
levelNum = event.LevelNum
end
if (event.Type == AutoBiographerEnum.EventType.Death and event.SubType == AutoBiographerEnum.EventSubType.PlayerDeath) then
MiscellaneousStatistics.Add(controller.CharacterData.Levels[levelNum].MiscellaneousStatistics, AutoBiographerEnum.MiscellaneousTrackingType.PlayerDeaths, 1)
end
end
end
)
)
table.insert(MM.Migrations,
AutoBiographer_Migration:New(
5,
function(eventManager, controller)
-- Create BossCatalog.
if (controller.CharacterData.Catalogs.BossCatalog == nil) then controller.CharacterData.Catalogs.BossCatalog = {} end
-- Delete duplicate boss kill events and update BossCatalog.
local indexesToDelete = {}
for i = 1, #controller.CharacterData.Events do
local event = controller.CharacterData.Events[i]
if (event.Type == AutoBiographerEnum.EventType.Kill and event.SubType == AutoBiographerEnum.EventSubType.BossKill) then
local catalogUnit = controller.CharacterData.Catalogs.UnitCatalog[event.BossId]
local isFromRegularKillEvent = catalogUnit ~= nil and catalogUnit.Name == event.BossName
if (not isFromRegularKillEvent) then
if (not Catalogs.PlayerHasKilledBoss(controller.CharacterData.Catalogs, event.BossId)) then
controller:UpdateCatalogBoss(CatalogBoss.New(event.BossId, event.BossName, true))
end
end
local matchingBossKillEvent = nil
local otherEventIndex = i - 1
while (matchingBossKillEvent == nil and event.Timestamp - controller.CharacterData.Events[otherEventIndex].Timestamp < 2) do
local otherEvent = controller.CharacterData.Events[otherEventIndex]
if (otherEvent.Type == AutoBiographerEnum.EventType.Kill and otherEvent.SubType == AutoBiographerEnum.EventSubType.BossKill and otherEvent.BossName == event.BossName) then
matchingBossKillEvent = otherEvent
else
otherEventIndex = otherEventIndex - 1
end
end
if (matchingBossKillEvent ~= nil) then
if (isFromRegularKillEvent) then
indexesToDelete[i] = true
else
indexesToDelete[otherEventIndex] = true
end
end
end
end
HelperFunctions.RemoveElementsFromArrayAtIndexes(controller.CharacterData.Events, indexesToDelete)
controller:AddLog("Deleted " .. #HelperFunctions.GetKeysFromTable(indexesToDelete) .. " duplicate boss kill events.", AutoBiographerEnum.LogLevel.Information)
end
)
)
table.insert(MM.Migrations,
AutoBiographer_Migration:New(
6,
function(eventManager, controller)
-- Update UnitCatalog with unit types.
for k,v in pairs(controller.CharacterData.Catalogs.UnitCatalog) do
if (v.UType == nil) then
v.UType = HelperFunctions.GetUnitTypeFromCatalogUnitId(v.Id)
if (v.UType == AutoBiographerEnum.UnitType.Player) then v.Killed = nil end -- A bug was setting the player units Killed field.
end
end
-- Create DeathStatistics for each level.
for k,v in pairs(controller.CharacterData.Levels) do
if (v.DeathStatistics == nil) then v.DeathStatistics = DeathStatistics.New() end
v.MiscellaneousStatistics[AutoBiographerEnum.MiscellaneousTrackingType.PlayerDeaths] = nil
end
-- Populate each level's DeathStatistics.
local levelNum = HelperFunctions.GetKeysFromTable(controller.CharacterData.Levels, true)[1]
for i = 1, #controller.CharacterData.Events do
local event = controller.CharacterData.Events[i]
if (event.Type == AutoBiographerEnum.EventType.Level and event.SubType == AutoBiographerEnum.EventSubType.LevelUp) then
levelNum = event.LevelNum
elseif (event.Type == AutoBiographerEnum.EventType.Death and event.SubType == AutoBiographerEnum.EventSubType.PlayerDeath) then
local deathTrackingType
if (event.KillerCuid == nil) then
deathTrackingType = AutoBiographerEnum.DeathTrackingType.DeathToEnvironment
elseif (HelperFunctions.GetUnitTypeFromCatalogUnitId(event.KillerCuid) == AutoBiographerEnum.UnitType.Creature) then
deathTrackingType = AutoBiographerEnum.DeathTrackingType.DeathToCreature
elseif (HelperFunctions.GetUnitTypeFromCatalogUnitId(event.KillerCuid) == AutoBiographerEnum.UnitType.Pet) then
deathTrackingType = AutoBiographerEnum.DeathTrackingType.DeathToPet
elseif (HelperFunctions.GetUnitTypeFromCatalogUnitId(event.KillerCuid) == AutoBiographerEnum.UnitType.Player) then
deathTrackingType = AutoBiographerEnum.DeathTrackingType.DeathToPlayer
end
DeathStatistics.Increment(controller.CharacterData.Levels[levelNum].DeathStatistics, deathTrackingType)
end
end
end
)
)
table.insert(MM.Migrations,
AutoBiographer_Migration:New(
7,
function(eventManager, controller)
if (eventManager.PersistentPlayerInfo.BattlegroundStatuses == nil) then
eventManager.PersistentPlayerInfo.BattlegroundStatuses = {}
end
-- Create BattlegroundStatistics for each level.
for k,v in pairs(controller.CharacterData.Levels) do
if (v.BattlegroundStatistics == nil) then
v.BattlegroundStatistics = BattlegroundStatistics.New()
end
end
end
)
)
table.insert(MM.Migrations,
AutoBiographer_Migration:New(
8,
function(eventManager, controller)
if (AutoBiographer_Settings.MapEventDisplayFilters == nil) then
AutoBiographer_Settings.MapEventDisplayFilters = {}
end
end
)
)
table.insert(MM.Migrations,
AutoBiographer_Migration:New(
9,
function(eventManager, controller)
if (controller:GetCurrentLevelStatistics().KillStatistics) then
local ensureKillStatisticsExistsForCatalogUnitId = function(killStatisticsByUnit, catalogUnitId)
if (not killStatisticsByUnit[catalogUnitId]) then
killStatisticsByUnit[catalogUnitId] = {
TaggedAssists = 0,
TaggedGroupAssistsAndKillingBlows = 0,
TaggedKillingBlows = 0,
UntaggedAssists = 0,
UntaggedGroupAssistsAndKillingBlows = 0,
UntaggedKillingBlows = 0,
}
end
end
for levelNum, levelStats in pairs(controller.CharacterData.Levels) do
if (not levelStats.KillStatisticsByUnit) then
levelStats.KillStatisticsByUnit = {}
for catalogUnitId, taggedKillingBlows in pairs(levelStats.KillStatistics.TaggedKills.PlayerKillingBlows) do
ensureKillStatisticsExistsForCatalogUnitId(levelStats.KillStatisticsByUnit, catalogUnitId)
levelStats.KillStatisticsByUnit[catalogUnitId].TaggedKillingBlows = levelStats.KillStatisticsByUnit[catalogUnitId].TaggedKillingBlows + taggedKillingBlows
end
for catalogUnitId, taggedAssists in pairs(levelStats.KillStatistics.TaggedKills.PlayerAssists) do
ensureKillStatisticsExistsForCatalogUnitId(levelStats.KillStatisticsByUnit, catalogUnitId)
levelStats.KillStatisticsByUnit[catalogUnitId].TaggedAssists = levelStats.KillStatisticsByUnit[catalogUnitId].TaggedAssists + taggedAssists
end
for catalogUnitId, taggedGroupAssistsAndKillingBlows in pairs(levelStats.KillStatistics.TaggedKills.GroupAssistsAndKillingBlows) do
ensureKillStatisticsExistsForCatalogUnitId(levelStats.KillStatisticsByUnit, catalogUnitId)
levelStats.KillStatisticsByUnit[catalogUnitId].TaggedGroupAssistsAndKillingBlows = levelStats.KillStatisticsByUnit[catalogUnitId].TaggedGroupAssistsAndKillingBlows + taggedGroupAssistsAndKillingBlows
end
for catalogUnitId, untaggedKillingBlows in pairs(levelStats.KillStatistics.UntaggedKills.PlayerKillingBlows) do
ensureKillStatisticsExistsForCatalogUnitId(levelStats.KillStatisticsByUnit, catalogUnitId)
levelStats.KillStatisticsByUnit[catalogUnitId].UntaggedKillingBlows = levelStats.KillStatisticsByUnit[catalogUnitId].UntaggedKillingBlows + untaggedKillingBlows
end
for catalogUnitId, untaggedAssists in pairs(levelStats.KillStatistics.UntaggedKills.PlayerAssists) do
ensureKillStatisticsExistsForCatalogUnitId(levelStats.KillStatisticsByUnit, catalogUnitId)
levelStats.KillStatisticsByUnit[catalogUnitId].UntaggedAssists = levelStats.KillStatisticsByUnit[catalogUnitId].UntaggedAssists + untaggedAssists
end
for catalogUnitId, untaggedGroupAssistsAndKillingBlows in pairs(levelStats.KillStatistics.UntaggedKills.GroupAssistsAndKillingBlows) do
ensureKillStatisticsExistsForCatalogUnitId(levelStats.KillStatisticsByUnit, catalogUnitId)
levelStats.KillStatisticsByUnit[catalogUnitId].UntaggedGroupAssistsAndKillingBlows = levelStats.KillStatisticsByUnit[catalogUnitId].UntaggedGroupAssistsAndKillingBlows + untaggedGroupAssistsAndKillingBlows
end
levelStats.KillStatistics = nil
end
end
end
end
)
)
table.insert(MM.Migrations,
AutoBiographer_Migration:New(
10,
function(eventManager, controller)
for levelNum, levelStatistics in pairs(controller.CharacterData.Levels) do
for catalogUnitId, killStatistics in pairs(levelStatistics.KillStatisticsByUnit) do
if (killStatistics.TaggedAssists) then
killStatistics[AutoBiographerEnum.KillTrackingType.TaggedAssist] = killStatistics.TaggedAssists
end
if (killStatistics.TaggedGroupAssistsAndKillingBlows) then
killStatistics[AutoBiographerEnum.KillTrackingType.TaggedGroupAssistOrKillingBlow] = killStatistics.TaggedGroupAssistsAndKillingBlows
end
if (killStatistics.TaggedKillingBlows) then
killStatistics[AutoBiographerEnum.KillTrackingType.TaggedKillingBlow] = killStatistics.TaggedKillingBlows
end
if (killStatistics.UntaggedAssists) then
killStatistics[AutoBiographerEnum.KillTrackingType.UntaggedAssist] = killStatistics.UntaggedAssists
end
if (killStatistics.UntaggedGroupAssistsAndKillingBlows) then
killStatistics[AutoBiographerEnum.KillTrackingType.UntaggedGroupAssistOrKillingBlow] = killStatistics.UntaggedGroupAssistsAndKillingBlows
end
if (killStatistics.UntaggedKillingBlows) then
killStatistics[AutoBiographerEnum.KillTrackingType.UntaggedKillingBlow] = killStatistics.UntaggedKillingBlows
end
killStatistics.TaggedAssists = nil
killStatistics.TaggedGroupAssistsAndKillingBlows = nil
killStatistics.TaggedKillingBlows = nil
killStatistics.UntaggedAssists = nil
killStatistics.UntaggedGroupAssistsAndKillingBlows = nil
killStatistics.UntaggedKillingBlows = nil
end
end
end
)
)
table.insert(MM.Migrations,
AutoBiographer_Migration:New(
11,
function(eventManager, controller)
if (AutoBiographer_Settings.Options.ShowFriendlyPlayerToolTips == nil) then
AutoBiographer_Settings.Options.ShowFriendlyPlayerToolTips = true
end
end
)
)