-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData.lua
More file actions
287 lines (244 loc) · 8.79 KB
/
Copy pathData.lua
File metadata and controls
287 lines (244 loc) · 8.79 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
-- MythicLootMap Data Loading
-- Loads dungeon and loot data from WoW Encounter Journal API
local ADDON_NAME, ns = ...
local MythicLootMap = ns
local Data = {}
MythicLootMap.Data = Data
-- Pending item data requests for async loading
local pendingItems = {}
function Data:LoadDungeonData()
MythicLootMap.db.dungeons = {}
MythicLootMap.db.items = {}
local challengeModeIDs = C_ChallengeMode.GetMapTable()
if not challengeModeIDs or #challengeModeIDs == 0 then
MythicLootMap:Print(MythicLootMap.L["NoDungeons"])
return
end
-- Reset ALL EJ state before querying (must be in this exact order)
EJ_ClearSearch()
C_EncounterJournal.ResetSlotFilter()
EJ_ResetLootFilter()
-- Apply class/spec filter if enabled
if MythicLootMap.Filters.current.specFilter then
local _, _, classID = UnitClass("player")
local specIndex = GetSpecialization()
if specIndex then
local specID = GetSpecializationInfo(specIndex)
EJ_SetLootFilter(classID, specID)
end
end
-- Build EJ instanceID lookup from all tiers (fallback for EJ_GetInstanceForMap)
local ejLookupByName = self:BuildEJNameLookup()
-- Set Mythic (M0) difficulty for loot queries
EJ_SetDifficulty(MythicLootMap.MYTHIC_DIFFICULTY)
for _, cmID in ipairs(challengeModeIDs) do
local name, _, _, _, _, uiMapID = C_ChallengeMode.GetMapUIInfo(cmID)
if name then
local ejInstanceID = self:ResolveEJInstanceID(name, uiMapID, ejLookupByName)
if ejInstanceID and ejInstanceID > 0 then
MythicLootMap.db.dungeons[ejInstanceID] = {
name = name,
challengeModeID = cmID,
uiMapID = uiMapID,
instanceID = ejInstanceID,
encounters = {},
}
self:LoadInstanceLoot(ejInstanceID, name)
end
end
end
self:RequestMissingItemData()
MythicLootMap:Print(string.format(MythicLootMap.L["Loaded"], #MythicLootMap.db.items, self:CountDungeons()))
end
function Data:ResolveEJInstanceID(dungeonName, uiMapID, ejLookupByName)
if uiMapID and EJ_GetInstanceForMap then
local id = EJ_GetInstanceForMap(uiMapID)
if id and id > 0 then
return id
end
end
if dungeonName and ejLookupByName then
return ejLookupByName[dungeonName]
end
return nil
end
function Data:BuildEJNameLookup()
local lookup = {}
local numTiers = EJ_GetNumTiers()
if not numTiers or numTiers == 0 then return lookup end
local savedTier = EJ_GetCurrentTier()
for tierIndex = 1, numTiers do
EJ_SelectTier(tierIndex)
local instanceIndex = 1
while true do
local instanceID, instanceName = EJ_GetInstanceByIndex(instanceIndex, false)
if not instanceID then break end
if instanceName then
lookup[instanceName] = instanceID
end
instanceIndex = instanceIndex + 1
end
end
if savedTier then
EJ_SelectTier(savedTier)
end
return lookup
end
function Data:LoadInstanceLoot(instanceID, dungeonName)
-- Difficulty and preview level are already set in LoadDungeonData
EJ_SelectInstance(instanceID)
local numLoot = EJ_GetNumLoot()
local dungeon = MythicLootMap.db.dungeons[instanceID]
for lootIndex = 1, numLoot do
local itemInfo = C_EncounterJournal.GetLootInfoByIndex(lootIndex)
if itemInfo and itemInfo.itemID then
local encounterName = ""
local encounterID = itemInfo.encounterID
if encounterID then
local name = EJ_GetEncounterInfo(encounterID)
encounterName = name or ""
if not dungeon.encounters[encounterID] then
dungeon.encounters[encounterID] = {
name = encounterName,
items = {},
}
end
end
local entry = self:BuildItemEntry({
itemID = itemInfo.itemID,
name = itemInfo.name,
icon = itemInfo.icon,
slot = itemInfo.slot,
armorType = itemInfo.armorType,
itemLink = itemInfo.link,
encounterID = encounterID,
encounterName = encounterName,
instanceID = instanceID,
dungeonName = dungeonName,
})
-- Skip items with no known equipment slot
if not entry.slotID then
-- skip
else
if encounterID and dungeon.encounters[encounterID] then
table.insert(dungeon.encounters[encounterID].items, entry)
end
table.insert(MythicLootMap.db.items, entry)
end
if not itemInfo.name or itemInfo.name == "" then
pendingItems[itemInfo.itemID] = entry
end
end
end
end
function Data:BuildItemEntry(info)
local slotID = MythicLootMap:ResolveSlotID(info.slot)
local entry = {
itemID = info.itemID,
name = info.name or "",
icon = info.icon,
slot = info.slot,
slotID = slotID,
armorType = info.armorType,
itemLink = info.itemLink,
ilvl = 0,
crit = 0,
haste = 0,
mastery = 0,
vers = 0,
encounterID = info.encounterID,
encounterName = info.encounterName,
instanceID = info.instanceID,
dungeonName = info.dungeonName,
owned = false,
ilvlDelta = 0,
}
self:EnrichItemEntry(entry)
return entry
end
function Data:EnrichItemEntry(entry)
-- Use the EJ link (has correct difficulty bonus IDs) if available
local source = entry.itemLink or entry.itemID
local itemName, itemLink, itemQuality, itemLevel, _, _, _, _, itemEquipLoc, itemTexture =
GetItemInfo(source)
if itemName then
if not entry.name or entry.name == "" then
entry.name = itemName
end
entry.ilvl = itemLevel or 0
entry.icon = entry.icon or itemTexture
if itemEquipLoc and itemEquipLoc ~= "" then
entry.slot = itemEquipLoc
entry.slotID = MythicLootMap:ResolveSlotID(itemEquipLoc)
end
if not entry.itemLink and itemLink then
entry.itemLink = itemLink
end
-- Extract secondary stats (only works when item data is cached)
local statsLink = entry.itemLink or itemLink
if statsLink then
local stats = C_Item.GetItemStats(statsLink)
if stats then
entry.crit = stats["ITEM_MOD_CRIT_RATING_SHORT"] or 0
entry.haste = stats["ITEM_MOD_HASTE_RATING_SHORT"] or 0
entry.mastery = stats["ITEM_MOD_MASTERY_RATING_SHORT"] or 0
entry.vers = stats["ITEM_MOD_VERSATILITY"] or 0
end
end
-- Detect armor type from item class/subclass (locale-independent)
local _, _, _, _, _, classID, subclassID = GetItemInfoInstant(entry.itemID)
if classID == Enum.ItemClass.Armor then
entry.armorType = MythicLootMap.ARMOR_SUBCLASS_TO_TYPE[subclassID]
end
else
pendingItems[entry.itemID] = entry
end
if C_TransmogCollection and C_TransmogCollection.PlayerHasTransmog then
entry.owned = C_TransmogCollection.PlayerHasTransmog(entry.itemID, 0)
end
end
function Data:RequestMissingItemData()
for itemID, _ in pairs(pendingItems) do
C_Item.RequestLoadItemDataByID(itemID)
end
end
function Data:OnItemDataLoaded(itemID, success)
if not success then return end
local entry = pendingItems[itemID]
if entry then
self:EnrichItemEntry(entry)
pendingItems[itemID] = nil
end
end
function Data:UpdateComparisons()
local equipped = MythicLootMap.Compare:GetPlayerEquipment()
for _, item in ipairs(MythicLootMap.db.items) do
item.ilvlDelta = MythicLootMap.Compare:CompareItem(item, equipped)
end
end
function Data:ParseDungeonList(mapIDs)
local dungeons = {}
if not mapIDs then return dungeons end
for _, cmID in ipairs(mapIDs) do
local name = C_ChallengeMode.GetMapUIInfo(cmID)
if name then
dungeons[cmID] = { name = name, challengeModeID = cmID }
end
end
return dungeons
end
function Data:CountDungeons()
local count = 0
for _ in pairs(MythicLootMap.db.dungeons) do
count = count + 1
end
return count
end
function Data:GetDungeonList()
local list = {}
for instanceID, dungeon in pairs(MythicLootMap.db.dungeons) do
table.insert(list, { instanceID = instanceID, name = dungeon.name })
end
table.sort(list, function(a, b) return a.name < b.name end)
return list
end