-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathejournal.lua
411 lines (343 loc) · 16.3 KB
/
ejournal.lua
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
local detailsFramework = _G["DetailsFramework"]
if (not detailsFramework or not DetailsFrameworkCanLoad) then
return
end
local defaultCreatureIconCoords = {0, 1, 0, 0.95}
---@class df_encounterinfo : table
---@field name string
---@field mapId number
---@field instanceId number
---@field dungeonEncounterId number
---@field journalEncounterId number
---@field journalInstanceId number
---@field creatureName string
---@field creatureIcon string
---@field creatureIconCoords table<number, number, number, number>
---@field creatureId number
---@field creatureDisplayId number
---@field creatureUIModelSceneId number
---@class df_instanceinfo : table
---@field name string
---@field bgImage string
---@field mapId number
---@field instanceId number
---@field journalInstanceId number
---@field isRaid boolean
---@field encountersArray df_encounterinfo[]
---@field encountersByName table<string, df_encounterinfo>
---@field encountersByDungeonEncounterId table<number, df_encounterinfo>
---@field encountersByJournalEncounterId table<number, df_encounterinfo>
---@field icon string
---@field iconSize table<number, number>
---@field iconCoords table<number, number, number, number>
---@field iconLore string
---@field iconLoreSize table<number, number>
---@field iconLoreCoords table<number, number, number, number>
---@field iconTexture string
---@field iconTextureSize table<number, number>
---@field iconTextureCoords table<number, number, number, number>
---@class df_ejc : table
---@field GetEncounterInfo fun(id:number):df_encounterinfo
---@field GetInstanceInfo fun(id:instanceid|instancename|mapid):df_instanceinfo
---@field GetInstanceEJID fun(...):number
---@field IsCurrentContent fun(id:number):boolean
---@field GetAllEncountersFromInstance fun(id:any):df_encounterinfo[]
---@field CreateEncounterJournalDump fun()
---@field GetAllRaidInstances fun():df_instanceinfo[]
---@field GetAllDungeonInstances fun():df_instanceinfo[]
---@field GetEncounterSpells fun(journalInstanceId:number, journalEncounterId:number, difficulty:number):df_ejspell[]
---@field CacheRaidData_OnlyRaidInstances table<number, df_instanceinfo[]>
---@field CacheRaidData_OnlyDungeonInstances table<number, df_instanceinfo[]>
---@field CacheRaidData_ByInstanceId table<number, df_instanceinfo>
---@field CacheRaidData_ByInstanceName table<string, df_instanceinfo>
---@field CacheRaidData_ByMapId table<number, df_instanceinfo>
---@field CacheEncountersByEncounterName table<string, df_encounterinfo>
---@field CacheEncountersBy_EncounterName table<string, df_encounterinfo>
---@field CacheEncountersBy_EncounterId table<number, df_encounterinfo>
---@field CacheEncountersBy_JournalEncounterId table<number, df_encounterinfo>
---@field Id_To_JournalInstanceID table<number, number>
---@field CurrentContent table<number, boolean>
local bHasLoaded = false
if (detailsFramework.Ejc) then
wipe(detailsFramework.Ejc)
end
detailsFramework.Ejc = {}
local Ejc = detailsFramework.Ejc
---@return df_encounterinfo?
function Ejc.GetEncounterInfo(id)
if (not bHasLoaded) then
Ejc.CreateEncounterJournalDump()
end
---@type df_encounterinfo
local encounterData = Ejc.CacheEncountersBy_EncounterId[id]
if (encounterData) then
return encounterData
end
encounterData = Ejc.CacheEncountersBy_EncounterName[id]
if (encounterData) then
return encounterData
end
encounterData = Ejc.CacheEncountersBy_JournalEncounterId[id]
if (encounterData) then
return encounterData
end
end
function Ejc.Load()
Ejc.CreateEncounterJournalDump()
end
---@param id instanceid|instancename|mapid
---@return df_instanceinfo?
function Ejc.GetInstanceInfo(id)
if (not id) then
return
end
if (not bHasLoaded) then
Ejc.CreateEncounterJournalDump()
end
if (id == 463) then --fall
id = 1209
end
---@type df_instanceinfo
local instanceData = Ejc.CacheRaidData_ByInstanceId[id]
if (instanceData) then
return instanceData
end
instanceData = Ejc.CacheRaidData_ByInstanceName[id]
if (instanceData) then
return instanceData
end
instanceData = Ejc.CacheRaidData_ByMapId[id]
if (instanceData) then
return instanceData
end
end
function Ejc.GetInstanceEJID(...)
for i = 1, select("#", ...) do
local id = select(i, ...)
local EJID = Ejc.Id_To_JournalInstanceID[id]
if (EJID) then
return EJID
end
end
end
function Ejc.IsCurrentContent(id)
return Ejc.CurrentContent[id]
end
function Ejc.GetAllEncountersFromInstance(id)
if (not bHasLoaded) then
Ejc.CreateEncounterJournalDump()
end
local instanceData = Ejc.GetInstanceInfo(id)
if (instanceData) then
return instanceData.encountersArray
end
end
function Ejc.GetAllRaidInstances()
if (not bHasLoaded) then
Ejc.CreateEncounterJournalDump()
end
return Ejc.CacheRaidData_OnlyRaidInstances
end
function Ejc.GetAllDungeonInstances()
if (not bHasLoaded) then
Ejc.CreateEncounterJournalDump()
end
return Ejc.CacheRaidData_OnlyDungeonInstances
end
---@class df_ejspell : table
---@field spellID number
---@field title string header name in the encounter journal
---@field abilityIcon number journal spell icon
function Ejc.GetEncounterSpells(journalInstanceId, journalEncounterId, difficulty)
EJ_SetDifficulty(difficulty or 16)
EJ_SelectInstance(journalInstanceId)
EJ_SelectEncounter(journalEncounterId)
local encounterName, encounterDescription, journalEncounterID, rootSectionID, link, journalInstanceID, dungeonEncounterID, instanceID = EJ_GetEncounterInfo(journalEncounterId)
local sectionStack = {}
local currentSectionId = rootSectionID
local spells = {}
repeat
local sectionInfo = C_EncounterJournal.GetSectionInfo(currentSectionId)
if (not sectionInfo) then
break
end
if (sectionInfo.spellID) then
local spellInfo = C_Spell.GetSpellInfo(sectionInfo.spellID)
sectionInfo.spellName = spellInfo and spellInfo.name
sectionInfo.spellIcon = spellInfo and spellInfo.iconID
table.insert(spells, sectionInfo)
spells[sectionInfo.spellID] = sectionInfo
if (sectionInfo.spellName) then
spells[sectionInfo.spellName] = sectionInfo
end
if (sectionInfo.title) then
spells[sectionInfo.title] = sectionInfo
end
end
if (sectionInfo.siblingSectionID) then
table.insert(sectionStack, sectionInfo.siblingSectionID)
end
if (sectionInfo.firstChildSectionID) then
table.insert(sectionStack, sectionInfo.firstChildSectionID)
end
currentSectionId = table.remove(sectionStack)
until not currentSectionId
end
function Ejc.CreateEncounterJournalDump()
--if the cache has been already created, then return
if (bHasLoaded) then
return
else
bHasLoaded = true
end
--this table store ids which indicates the bossId, encounterId or mapId is a content from the current expansion
Ejc.CurrentContent = {}
Ejc.CacheRaidData_ByInstanceId = {}
Ejc.CacheRaidData_ByInstanceName = {} --this is localized name
Ejc.CacheRaidData_ByMapId = {} --retrivied from GetInstanceInfo()
Ejc.CacheEncountersByEncounterName = {}
Ejc.CacheEncountersBy_EncounterName = {}
Ejc.CacheEncountersBy_EncounterId = {}
Ejc.CacheEncountersBy_JournalEncounterId = {}
Ejc.CacheRaidData_OnlyRaidInstances = {}
Ejc.CacheRaidData_OnlyDungeonInstances = {}
---cahe the uiMapID pointing to the instanceID
---this replace the need to call EJ_GetInstanceForMap to get the journalInstanceID
---@type table
local id_to_journalInstanceID = {}
Ejc.Id_To_JournalInstanceID = id_to_journalInstanceID
--if the expansion does not support the encounter journal, then return
if (not EncounterJournal_LoadUI) then
return
end
local data = {}
---returns the number of valid encounter journal tier indices
---@type number
local tierAmount = EJ_GetNumTiers() --return 11 for dragonisles, is returning 11 for wow11 as well
---returns the currently active encounter journal tier index
---could also be tierAmount - 1
---because the tier is "current season"
---@type number
local currentTierId = tierAmount --EJ_GetCurrentTier(), for some unknown reason, this function is returning 3 on retail
---maximum amount of dungeons in the expansion
---@type number
local maxAmountOfDungeons = 20
---the index of the first raid tier in the expansion, ignoring the first tier as it is open world bosses
---@type number
local raidTierStartIndex = 2
---max amount of bosses which a raid tier can have
---@type number
local maxRaidBosses = 20
---two iterations are required, one for dungeons and another for raids
---this table store two booleans that are passed to EJ_GetInstanceByIndex second argument, to indicate if we want to get dungeons or raids
local tGetDungeonsOrRaids = {false, true}
do --get raid instances data
for i = 1, #tGetDungeonsOrRaids do
local bIsRaid = tGetDungeonsOrRaids[i]
--select the tier, use current tier - 1 for raids, as the currentTier only shows the latest release raid
--use current tier for dungeons, as the current tier shows the dungeons used for the current season of Mythic+
local startIndex, endIndex
if (bIsRaid) then
if (detailsFramework.IsCataWow()) then
if (currentTierId == 1) then --Cata has only one tier. Looking up tier 0 errors. ~CATA
break
end
end
EJ_SelectTier(currentTierId) --print("tier selected:", currentTierId - 1, "raids") --debug: was (currentTierId - 1), but was selecting wow10 content
startIndex = raidTierStartIndex
endIndex = 20
else
EJ_SelectTier(currentTierId) --print("tier selected:", currentTierId, "dungeons", "currentTierId:", currentTierId) --debug
startIndex = 1
endIndex = maxAmountOfDungeons
end
for instanceIndex = endIndex, startIndex, -1 do
--instanceID: number - the unique ID of the instance, also returned by GetInstanceInfo() 8th return value
--journalInstanceID: number - the ID used by the Encounter Journal API
--dungeonUiMapID: number - the ID used by the world map API
--dungeonEncounterID: number - same ID passed by the ENCOUNTER_STAR and ENCOUNTER_END events
local journalInstanceID, instanceName, description, bgImage, buttonImage1, loreImage, buttonImage2, dungeonUiMapID, journalLink, shouldDisplayDifficulty, instanceID = EJ_GetInstanceByIndex(instanceIndex, bIsRaid)
if (journalInstanceID) then
id_to_journalInstanceID[dungeonUiMapID] = journalInstanceID
id_to_journalInstanceID[instanceName] = journalInstanceID
id_to_journalInstanceID[instanceID] = journalInstanceID
Ejc.CurrentContent[journalInstanceID] = true
Ejc.CurrentContent[dungeonUiMapID] = true
Ejc.CurrentContent[instanceID] = true
Ejc.CurrentContent[instanceName] = true
--select the raid instance, this allow to retrieve data about the encounters of the instance
EJ_SelectInstance(journalInstanceID)
--build a table with data of the raid instance
local instanceData = {
name = instanceName,
bgImage = bgImage,
mapId = dungeonUiMapID,
instanceId = instanceID,
journalInstanceId = journalInstanceID,
isRaid = bIsRaid,
encountersArray = {},
encountersByName = {},
encountersByDungeonEncounterId = {},
encountersByJournalEncounterId = {},
icon = buttonImage1,
iconSize = {70, 36},
iconCoords = {0.01, .67, 0.025, .725},
iconLore = loreImage,
iconLoreSize = {70, 36},
iconLoreCoords = {0, 1, 0, 0.95},
iconTexture = buttonImage2,
iconTextureSize = {70, 36},
iconTextureCoords = {0, 1, 0, 0.95},
}
--cache the raidData, in different tables, using different keys
Ejc.CacheRaidData_ByInstanceId[journalInstanceID] = instanceData
Ejc.CacheRaidData_ByInstanceId[instanceID] = instanceData
Ejc.CacheRaidData_ByInstanceName[instanceName] = instanceData
Ejc.CacheRaidData_ByMapId[dungeonUiMapID] = instanceData
if (bIsRaid) then
Ejc.CacheRaidData_OnlyRaidInstances[#Ejc.CacheRaidData_OnlyRaidInstances+1] = instanceData
else
Ejc.CacheRaidData_OnlyDungeonInstances[#Ejc.CacheRaidData_OnlyDungeonInstances+1] = instanceData
end
--get information about the bosses in the raid
for encounterIndex = 1, maxRaidBosses do
local encounterName, encounterDescription, journalEncounterID, rootSectionID, link, journalInstanceID, dungeonEncounterID, instanceID = EJ_GetEncounterInfoByIndex(encounterIndex, journalInstanceID)
if (encounterName) then
local encounterData = {
name = encounterName,
mapId = dungeonUiMapID,
instanceId = instanceID,
dungeonEncounterId = dungeonEncounterID,
journalEncounterId = journalEncounterID,
journalInstanceId = journalInstanceID,
}
Ejc.CurrentContent[encounterName] = true
Ejc.CurrentContent[journalEncounterID] = true
Ejc.CurrentContent[dungeonEncounterID] = true
local journalEncounterCreatureId, creatureName, creatureDescription, creatureDisplayID, iconImage, uiModelSceneID = EJ_GetCreatureInfo(1, journalEncounterID)
if (journalEncounterCreatureId) then
encounterData.creatureName = creatureName
encounterData.creatureIcon = iconImage
encounterData.creatureIconCoords = defaultCreatureIconCoords
encounterData.creatureId = journalEncounterCreatureId
encounterData.creatureDisplayId = creatureDisplayID
encounterData.creatureUIModelSceneId = uiModelSceneID
end
instanceData.encountersArray[#instanceData.encountersArray+1] = encounterData
instanceData.encountersByName[encounterName] = encounterData
--print(instanceName, encounterName, journalEncounterID, journalInstanceID, dungeonEncounterID, instanceID)
instanceData.encountersByDungeonEncounterId[dungeonEncounterID] = encounterData
instanceData.encountersByJournalEncounterId[journalEncounterID] = encounterData
Ejc.CacheEncountersBy_EncounterName[encounterName] = encounterData
Ejc.CacheEncountersBy_EncounterId[dungeonEncounterID] = encounterData
Ejc.CacheEncountersBy_JournalEncounterId[journalEncounterID] = encounterData
id_to_journalInstanceID[encounterName] = journalInstanceID
id_to_journalInstanceID[dungeonEncounterID] = journalInstanceID
id_to_journalInstanceID[journalEncounterID] = journalInstanceID
end
end
end
end
end
end
end