Diff
checker
Testo
Testo
Immagini
Documenti
Excel
Cartelle
Legal
Enterprise
Applicazione per desktop
Prezzi
Accedi
Scarica Diffchecker Desktop
Confronta il testo
Trova la differenza tra due file di testo
Strumenti
Cronologia
Editor live
Comprimi invariate
Senza a capo
Layout
Diviso
Unificato
Livello di dettaglio
Intelligente
Parola
Carattere
Evidenziazione sintassi
Scegli sintassi
Ignora
Trasforma testo
Vai alla prima modifica
Modifica input
Diffchecker Desktop
Il modo più sicuro per usare Diffchecker. Ottieni l'app Diffchecker Desktop: i tuoi diff non lasciano mai il tuo computer!
Ottieni Desktop
Untitled diff
Creato
10 anni fa
Il diff non scade mai
Eliminare
Esporta
Condividere
Spiegare
4 rimozioni
Linee
Totale
Rimosso
Caratteri
Totale
Rimosso
Per continuare a utilizzare questa funzione, aggiorna a
Diff
checker
Pro
Visualizza prezzi
541 linee
Copia tutti
2 aggiunte
Linee
Totale
Aggiunto
Caratteri
Totale
Aggiunto
Per continuare a utilizzare questa funzione, aggiorna a
Diff
checker
Pro
Visualizza prezzi
539 linee
Copia tutti
if not InspectEquip then return end
if not InspectEquip then return end
local IE = InspectEquip
local IE = InspectEquip
local IS = InspectEquip_ItemSources
local IS = InspectEquip_ItemSources
local L = LibStub("AceLocale-3.0"):GetLocale("InspectEquip")
local L = LibStub("AceLocale-3.0"):GetLocale("InspectEquip")
local band = bit.band
local band = bit.band
local bor = bit.bor
local bor = bit.bor
local tinsert = table.insert
local tinsert = table.insert
local strfind = string.find
local strfind = string.find
local max = math.max
local max = math.max
-- check for 5.0+ client, because EJ api was changed
-- check for 5.0+ client, because EJ api was changed
local mop = select(4, GetBuildInfo()) >= 50000
local mop = select(4, GetBuildInfo()) >= 50000
local wod = select(4, GetBuildInfo()) >= 60000
local wod = select(4, GetBuildInfo()) >= 60000
-- Database
-- Database
InspectEquipLocalDB = {}
InspectEquipLocalDB = {}
local ieVersion
local ieVersion
-- Max wait cycles for database update
-- Max wait cycles for database update
local MAX_WC = 5
local MAX_WC = 5
local DATA_RECEIVED_WC = 7
local DATA_RECEIVED_WC = 7
local newDataReceived
local newDataReceived
Copia
Copiato
Copia
Copiato
local newDataCycles = 0
local dbInitialized = false
local dbInitialized = false
-- GUI
-- GUI
local bar, barText
local bar, barText
local coUpdate
local coUpdate
function IE:InitLocalDatabase()
function IE:InitLocalDatabase()
if dbInitialized then return end
if dbInitialized then return end
if not InspectEquipLocalDB then InspectEquipLocalDB = {} end
if not InspectEquipLocalDB then InspectEquipLocalDB = {} end
setmetatable(InspectEquipLocalDB, {__index = {
setmetatable(InspectEquipLocalDB, {__index = {
Zones = {}, Bosses = {}, Items = {}
Zones = {}, Bosses = {}, Items = {}
}})
}})
local _, currentBuild = GetBuildInfo()
local _, currentBuild = GetBuildInfo()
ieVersion = GetAddOnMetadata("InspectEquip", "Version")
ieVersion = GetAddOnMetadata("InspectEquip", "Version")
-- create database if not present or outdated (or wrong locale)
-- create database if not present or outdated (or wrong locale)
if (InspectEquipLocalDB.ClientBuild ~= currentBuild) or
if (InspectEquipLocalDB.ClientBuild ~= currentBuild) or
(InspectEquipLocalDB.Locale ~= GetLocale()) or
(InspectEquipLocalDB.Locale ~= GetLocale()) or
(InspectEquipLocalDB.IEVersion ~= ieVersion) or
(InspectEquipLocalDB.IEVersion ~= ieVersion) or
(InspectEquipLocalDB.Expansion ~= GetExpansionLevel()) then
(InspectEquipLocalDB.Expansion ~= GetExpansionLevel()) then
--self:CreateLocalDatabase()
--self:CreateLocalDatabase()
self:ScheduleTimer("CreateLocalDatabase", 5)
self:ScheduleTimer("CreateLocalDatabase", 5)
end
end
dbInitialized = true
dbInitialized = true
end
end
local function createUpdateGUI()
local function createUpdateGUI()
if not bar then
if not bar then
bar = CreateFrame("STATUSBAR", nil, UIParent, "TextStatusBar")
bar = CreateFrame("STATUSBAR", nil, UIParent, "TextStatusBar")
end
end
bar:SetWidth(300)
bar:SetWidth(300)
bar:SetHeight(30)
bar:SetHeight(30)
bar:SetPoint("CENTER", 0, -100)
bar:SetPoint("CENTER", 0, -100)
bar:SetBackdrop({
bar:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = 1, tileSize = 10, edgeSize = 10,
tile = 1, tileSize = 10, edgeSize = 10,
insets = {left = 1, right = 1, top = 1, bottom = 1}
insets = {left = 1, right = 1, top = 1, bottom = 1}
})
})
bar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
bar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
bar:SetBackdropColor(0, 0, 0, 1)
bar:SetBackdropColor(0, 0, 0, 1)
bar:SetStatusBarColor(0.6, 0.6, 0, 0.4)
bar:SetStatusBarColor(0.6, 0.6, 0, 0.4)
bar:SetMinMaxValues(0, 100)
bar:SetMinMaxValues(0, 100)
bar:SetValue(0)
bar:SetValue(0)
if not barText then
if not barText then
barText = bar:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
barText = bar:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
end
end
barText:SetPoint("CENTER", bar, "CENTER")
barText:SetPoint("CENTER", bar, "CENTER")
barText:SetJustifyH("CENTER")
barText:SetJustifyH("CENTER")
barText:SetJustifyV("CENTER")
barText:SetJustifyV("CENTER")
barText:SetTextColor(1, 1, 1)
barText:SetTextColor(1, 1, 1)
barText:SetText("InspectEquip: " .. L["Updating database..."])
barText:SetText("InspectEquip: " .. L["Updating database..."])
end
end
local ejDisabled = false
local ejDisabled = false
local ejToggle = ToggleEncounterJournal
local ejToggle = ToggleEncounterJournal
-- this function disables the EJ GUI during update
-- this function disables the EJ GUI during update
-- because using the EJ during update will result in an invalid database
-- because using the EJ during update will result in an invalid database
-- (other addons may still use the EJ api and possibly destroy the DB that way...)
-- (other addons may still use the EJ api and possibly destroy the DB that way...)
local function DisableEJ()
local function DisableEJ()
if ejDisabled then return end
if ejDisabled then return end
ejDisabled = true
ejDisabled = true
-- hide EJ
-- hide EJ
if EncounterJournal then
if EncounterJournal then
if EncounterJournal:IsShown() then
if EncounterJournal:IsShown() then
EncounterJournal:Hide()
EncounterJournal:Hide()
end
end
end
end
ejToggle = ToggleEncounterJournal
ejToggle = ToggleEncounterJournal
ToggleEncounterJournal = function() end
ToggleEncounterJournal = function() end
EJMicroButton:Disable()
EJMicroButton:Disable()
end
end
local function EnableEJ()
local function EnableEJ()
if not ejDisabled then return end
if not ejDisabled then return end
ejDisabled = false
ejDisabled = false
ToggleEncounterJournal = ejToggle
ToggleEncounterJournal = ejToggle
EJMicroButton:Enable()
EJMicroButton:Enable()
EJMicroButton:SetAlpha(1)
EJMicroButton:SetAlpha(1)
end
end
local function EndUpdate()
local function EndUpdate()
bar:SetScript("OnUpdate", nil)
bar:SetScript("OnUpdate", nil)
bar:Hide()
bar:Hide()
EnableEJ()
EnableEJ()
coUpdate = nil
coUpdate = nil
IE:UnregisterEvent("EJ_LOOT_DATA_RECIEVED")
IE:UnregisterEvent("EJ_LOOT_DATA_RECIEVED")
end
end
local function UpdateTick()
local function UpdateTick()
if coUpdate then
if coUpdate then
-- wait for loot data
-- wait for loot data
if newDataReceived then -- data received this frame
if newDataReceived then -- data received this frame
newDataCycles = newDataCycles + DATA_RECEIVED_WC
newDataCycles = newDataCycles + DATA_RECEIVED_WC
newDataReceived = false
newDataReceived = false
end
end
Copia
Copiato
Copia
Copiato
if newDataCycles
> 0 then
if newDataCycles
and newDataCycles
> 0 then
newDataCycles = newDataCycles - 1
newDataCycles = newDataCycles - 1
return
return
end
end
local ok, msg = coroutine.resume(coUpdate)
local ok, msg = coroutine.resume(coUpdate)
if not ok then
if not ok then
EndUpdate()
EndUpdate()
message("[InspectEquip] Could not update database: " .. msg)
message("[InspectEquip] Could not update database: " .. msg)
end
end
end
end
end
end
local function UpdateBar()
local function UpdateBar()
bar:SetValue(bar:GetValue() + 1)
bar:SetValue(bar:GetValue() + 1)
coroutine.yield()
coroutine.yield()
end
end
local function GetReverseMapping(baseMap)
local function GetReverseMapping(baseMap)
local map = {}
local map = {}
local id, name
local id, name
for id, name in pairs(baseMap) do
for id, name in pairs(baseMap) do
map[name] = id
map[name] = id
end
end
return map
return map
end
end
local function DifficultyToMode(diff, raid)
local function DifficultyToMode(diff, raid)
if diff == 1 then
if diff == 1 then
-- 5 normal
-- 5 normal
return 2
return 2
elseif diff == 2 then
elseif diff == 2 then
-- 5 heroic
-- 5 heroic
return 1
return 1
elseif diff == 3 then
elseif diff == 3 then
-- 10 normal
-- 10 normal
return 8
return 8
elseif diff == 4 then
elseif diff == 4 then
-- 25 normal
-- 25 normal
return 16
return 16
elseif diff == 5 then
elseif diff == 5 then
-- 10 heroic
-- 10 heroic
return 32
return 32
elseif diff == 6 then
elseif diff == 6 then
-- 25 heroic
-- 25 heroic
return 64
return 64
elseif diff == 7 then
elseif diff == 7 then
-- 25 lfr
-- 25 lfr
return 128
return 128
elseif diff == 8 then
elseif diff == 8 then
-- 5 challenge TODO
-- 5 challenge TODO
return 2
return 2
elseif diff == 14 then
elseif diff == 14 then
-- normal / flexible
-- normal / flexible
return 65536
return 65536
elseif diff == 15 then
elseif diff == 15 then
-- heroic
-- heroic
return 131072
return 131072
elseif diff == 16 then
elseif diff == 16 then
-- mythic
-- mythic
return 262144
return 262144
elseif diff == 17 then
elseif diff == 17 then
-- lfr
-- lfr
return 524288
return 524288
end
end
end
end
local function AddToDB(tempDB, itemID, zoneID, bossID, mode)
local function AddToDB(tempDB, itemID, zoneID, bossID, mode)
local sources = tempDB[itemID]
local sources = tempDB[itemID]
local entry
local entry
if sources then
if sources then
for _, entry in pairs(sources) do
for _, entry in pairs(sources) do
if (entry[1] == zoneID) and (entry[2] == bossID) then
if (entry[1] == zoneID) and (entry[2] == bossID) then
entry[3] = bor(entry[3], mode)
entry[3] = bor(entry[3], mode)
return
return
end
end
end
end
tinsert(sources, {zoneID, bossID, mode})
tinsert(sources, {zoneID, bossID, mode})
else
else
tempDB[itemID] = {{zoneID, bossID, mode}}
tempDB[itemID] = {{zoneID, bossID, mode}}
end
end
end
end
local function SaveToDB(tempDB, entryType)
local function SaveToDB(tempDB, entryType)
local itemID, sources, entry
local itemID, sources, entry
for itemID, sources in pairs(tempDB) do
for itemID, sources in pairs(tempDB) do
local str = InspectEquipLocalDB.Items[itemID]
local str = InspectEquipLocalDB.Items[itemID]
local isEntry = IS.Items[itemID]
local isEntry = IS.Items[itemID]
-- loop through sources we found
-- loop through sources we found
for _, entry in pairs(sources) do
for _, entry in pairs(sources) do
local entryStr = entryType .. "_" .. entry[1] .. "_" .. entry[3] .. "_" .. entry[2]
local entryStr = entryType .. "_" .. entry[1] .. "_" .. entry[3] .. "_" .. entry[2]
-- skip if already in IS DB
-- skip if already in IS DB
if not (isEntry and (strfind(";" .. isEntry .. ";", ";" .. entryStr .. ";"))) then
if not (isEntry and (strfind(";" .. isEntry .. ";", ";" .. entryStr .. ";"))) then
if str then
if str then
str = str .. ";" .. entryStr
str = str .. ";" .. entryStr
else
else
str = entryStr
str = entryStr
end
end
end
end
end
end
InspectEquipLocalDB.Items[itemID] = str
InspectEquipLocalDB.Items[itemID] = str
end
end
end
end
local function GetInstanceCount(isRaid)
local function GetInstanceCount(isRaid)
local i = 1
local i = 1
local id
local id
repeat
repeat
id = EJ_GetInstanceByIndex(i, isRaid)
id = EJ_GetInstanceByIndex(i, isRaid)
i = i + 1
i = i + 1
until not id
until not id
return i - 2
return i - 2
end
end
local function GetTotalLootCount(tierCount)
local function GetTotalLootCount(tierCount)
local lootCount = 0
local lootCount = 0
local tier, i
local tier, i
for tier = 1, tierCount do
for tier = 1, tierCount do
if mop then
if mop then
EJ_SelectTier(tier)
EJ_SelectTier(tier)
end
end
local isRaid = false
local isRaid = false
while true do
while true do
i = 1
i = 1
local insID, insName = EJ_GetInstanceByIndex(i, isRaid)
local insID, insName = EJ_GetInstanceByIndex(i, isRaid)
while insID do
while insID do
EJ_SelectInstance(insID)
EJ_SelectInstance(insID)
local diff
local diff
local diffOffset = (mop and isRaid) and 2 or 0
local diffOffset = (mop and isRaid) and 2 or 0
local maxDiff = isRaid and 5 or 2
local maxDiff = isRaid and 5 or 2
for diff = 1, maxDiff do
for diff = 1, maxDiff do
if EJ_IsValidInstanceDifficulty(diff + diffOffset) then
if EJ_IsValidInstanceDifficulty(diff + diffOffset) then
EJ_SetDifficulty(diff)
EJ_SetDifficulty(diff)
lootCount = lootCount + EJ_GetNumLoot()
lootCount = lootCount + EJ_GetNumLoot()
end
end
end
end
i = i + 1
i = i + 1
insID, insName = EJ_GetInstanceByIndex(i, isRaid)
insID, insName = EJ_GetInstanceByIndex(i, isRaid)
end
end
if isRaid then
if isRaid then
break
break
else
else
isRaid = true
isRaid = true
end
end
end
end
end
end
return lootCount
return lootCount
end
end
local function UpdateFunction(recursive)
local function UpdateFunction(recursive)
local _, i, j, tier
local _, i, j, tier
-- reset EJ
-- reset EJ
DisableEJ()
DisableEJ()
EJ_ClearSearch()
EJ_ClearSearch()
if mop then
if mop then
EJ_ResetLootFilter()
EJ_ResetLootFilter()
else
else
EJ_SetClassLootFilter(0)
EJ_SetClassLootFilter(0)
end
end
newDataReceived = false
newDataReceived = false
IE:RegisterEvent("EJ_LOOT_DATA_RECIEVED")
IE:RegisterEvent("EJ_LOOT_DATA_RECIEVED")
-- init/reset database
-- init/reset database
local db = InspectEquipLocalDB
local db = InspectEquipLocalDB
db.Zones = {}
db.Zones = {}
db.Bosses = {}
db.Bosses = {}
db.Items = {}
db.Items = {}
db.NextZoneID = 1000
db.NextZoneID = 1000
db.NextBossID = 1000
db.NextBossID = 1000
-- count total number of instances
-- count total number of instances
local insCount = 0
local insCount = 0
local tierCount = 1
local tierCount = 1
if mop then
if mop then
-- as of 5.x there are multiple tiers (classic, bc, wotlk, cata, mop...)
-- as of 5.x there are multiple tiers (classic, bc, wotlk, cata, mop...)
tierCount = EJ_GetNumTiers()
tierCount = EJ_GetNumTiers()
for tier = 1, tierCount do
for tier = 1, tierCount do
local tierName = EJ_GetTierInfo(tier)
local tierName = EJ_GetTierInfo(tier)
EJ_SelectTier(tier)
EJ_SelectTier(tier)
--IE:Print("Tier: " .. tostring(tier) .. " = " .. tierName)
--IE:Print("Tier: " .. tostring(tier) .. " = " .. tierName)
local dungeonCount = GetInstanceCount(false)
local dungeonCount = GetInstanceCount(false)
local raidCount = GetInstanceCount(true)
local raidCount = GetInstanceCount(true)
--IE:Print(" ==> " .. tostring(dungeonCount) .. " Dungeons, " .. tostring(raidCount) .. " Raids")
--IE:Print(" ==> " .. tostring(dungeonCount) .. " Dungeons, " .. tostring(raidCount) .. " Raids")
insCount = insCount + dungeonCount + raidCount
insCount = insCount + dungeonCount + raidCount
end
end
else
else
local dungeonCount = GetInstanceCount(false)
local dungeonCount = GetInstanceCount(false)
local raidCount = GetInstanceCount(true)
local raidCount = GetInstanceCount(true)
insCount = dungeonCount + raidCount
insCount = dungeonCount + raidCount
--IE:Print(" ==> " .. tostring(dungeonCount) .. " Dungeons, " .. tostring(raidCount) .. " Raids")
--IE:Print(" ==> " .. tostring(dungeonCount) .. " Dungeons, " .. tostring(raidCount) .. " Raids")
end
end
-- set bar max value
-- set bar max value
local startValue = bar:GetValue()
local startValue = bar:GetValue()
bar:SetMinMaxValues(0, startValue + insCount + 2)
bar:SetMinMaxValues(0, startValue + insCount + 2)
-- get IS mapping for zone/boss name -> zone/boss id
-- get IS mapping for zone/boss name -> zone/boss id
local zoneMap = GetReverseMapping(IS.Zones)
local zoneMap = GetReverseMapping(IS.Zones)
local bossMap = GetReverseMapping(IS.Bosses)
local bossMap = GetReverseMapping(IS.Bosses)
UpdateBar()
UpdateBar()
-- temp db to allow for merging of modes
-- temp db to allow for merging of modes
local tempDungeonDB = {}
local tempDungeonDB = {}
local tempRaidDB = {}
local tempRaidDB = {}
local totalLootCount = 0
local totalLootCount = 0
local waitCycles = 0
local waitCycles = 0
-- get loot
-- get loot
for tier = 1, tierCount do
for tier = 1, tierCount do
if mop then
if mop then
EJ_SelectTier(tier)
EJ_SelectTier(tier)
end
end
-- loop through all instances of this tier, dungeons first, then raids
-- loop through all instances of this tier, dungeons first, then raids
local isRaid = false
local isRaid = false
while true do
while true do
i = 1
i = 1
local insID, insName = EJ_GetInstanceByIndex(i, isRaid)
local insID, insName = EJ_GetInstanceByIndex(i, isRaid)
local tempDB = isRaid and tempRaidDB or tempDungeonDB
local tempDB = isRaid and tempRaidDB or tempDungeonDB
while insID do
while insID do
-- get zone id for db
-- get zone id for db
local zoneID = zoneMap[insName]
local zoneID = zoneMap[insName]
if not zoneID then
if not zoneID then
-- zone is not in db
-- zone is not in db
zoneID = db.NextZoneID
zoneID = db.NextZoneID
db.Zones[zoneID] = insName
db.Zones[zoneID] = insName
zoneMap[insName] = zoneID
zoneMap[insName] = zoneID
db.NextZoneID = db.NextZoneID + 1
db.NextZoneID = db.NextZoneID + 1
end
end
EJ_SelectInstance(insID)
EJ_SelectInstance(insID)
local diff
local diff
local difficulties
local difficulties
if wod then
if wod then
if isRaid then
if isRaid then
difficulties = {3, 4, 5, 6, 7, 14, 15, 16, 17}
difficulties = {3, 4, 5, 6, 7, 14, 15, 16, 17}
else
else
difficulties = {1, 2, 8}
difficulties = {1, 2, 8}
end
end
elseif mop then
elseif mop then
if isRaid then
if isRaid then
difficulties = {3, 4, 5, 6, 7, 14}
difficulties = {3, 4, 5, 6, 7, 14}
else
else
difficulties = {1, 2}
difficulties = {1, 2}
end
end
else
else
-- not sure if this still works. probably not.
-- not sure if this still works. probably not.
if isRaid then
if isRaid then
difficulties = {1, 2, 3, 4, 5}
difficulties = {1, 2, 3, 4, 5}
else
else
difficulties = {1, 2}
difficulties = {1, 2}
end
end
end
end
for _, diff in ipairs(difficulties) do
for _, diff in ipairs(difficulties) do
if EJ_IsValidInstanceDifficulty(diff) then
if EJ_IsValidInstanceDifficulty(diff) then
newDataCycles = DATA_RECEIVED_WC * 3
newDataCycles = DATA_RECEIVED_WC * 3
EJ_SetDifficulty(diff)
EJ_SetDifficulty(diff)
local mode = DifficultyToMode(diff, isRaid)
local mode = DifficultyToMode(diff, isRaid)
local n = EJ_GetNumLoot()
local n = EJ_GetNumLoot()
-- the problem here is that when the items are not in the cache, EJ_GetNumLoot() will not
-- the problem here is that when the items are not in the cache, EJ_GetNumLoot() will not
-- return the correct number. it returns the number of items that are cached, which may be
-- return the correct number. it returns the number of items that are cached, which may be
-- 0 or a number lower than the correct number. it seems to be impossible to determine the
-- 0 or a number lower than the correct number. it seems to be impossible to determine the
-- correct number without waiting. EJ_LOOT_DATA_RECIEVED events are received, but we don't
-- correct number without waiting. EJ_LOOT_DATA_RECIEVED events are received, but we don't
-- know which event is the last one. also, no EJ_LOOT_DATA_RECIEVED are received if all
-- know which event is the last one. also, no EJ_LOOT_DATA_RECIEVED are received if all
-- items are already in the cache. so we try to wait a couple of frames until we have a
-- items are already in the cache. so we try to wait a couple of frames until we have a
-- number that is somehow stable.
-- number that is somehow stable.
-- at the end we count all items again, and if we then have more items, we start all over
-- at the end we count all items again, and if we then have more items, we start all over
-- again (at this point, the items are already cached, so the 2nd iteration is faster).
-- again (at this point, the items are already cached, so the 2nd iteration is faster).
local wc = 0
local wc = 0
local wcMax = MAX_WC
local wcMax = MAX_WC
while wc < wcMax do
while wc < wcMax do
coroutine.yield()
coroutine.yield()
wc = wc + 1
wc = wc + 1
local nNew = EJ_GetNumLoot()
local nNew = EJ_GetNumLoot()
if n ~= nNew then
if n ~= nNew then
wcMax = wc + MAX_WC
wcMax = wc + MAX_WC
end
end
n = nNew
n = nNew
end
end
waitCycles = waitCycles + wc
waitCycles = waitCycles + wc
totalLootCount = totalLootCount + n
totalLootCount = totalLootCount + n
--IE:Print("T=" .. tostring(tier) .. " I=" .. insName .. " D=" .. diff .. " M=" .. mode .. " ! #loot = " .. n .. " [wc = " .. wc .. "]")
--IE:Print("T=" .. tostring(tier) .. " I=" .. insName .. " D=" .. diff .. " M=" .. mode .. " ! #loot = " .. n .. " [wc = " .. wc .. "]")
for j = 1, n do
for j = 1, n do
-- get item info
-- get item info
Copia
Copiato
Copia
Copiato
local
itemName, _, _, _, item
ID, item
Link
, encID
= EJ_GetLootInfoByIndex(j)
local
itemID, encID,
itemName, _, _, _, item
Link
= EJ_GetLootInfoByIndex(j)
-- wait until data has arrived
-- wait until data has arrived
-- this doesn't seem necessary
-- this doesn't seem necessary
-- while not itemID do
-- while not itemID do
-- coroutine.yield()
-- coroutine.yield()
-- waitCycles = waitCycles + 1
-- waitCycles = waitCycles + 1
-- itemName, _, _, _, itemID, itemLink, encID = EJ_GetLootInfoByIndex(j)
-- itemName, _, _, _, itemID, itemLink, encID = EJ_GetLootInfoByIndex(j)
-- end
-- end
local encName = EJ_GetEncounterInfo(encID)
local encName = EJ_GetEncounterInfo(encID)
-- if not encName then
-- if not encName then
-- IE:Print("no encounter name! encID = " .. encID)
-- IE:Print("no encounter name! encID = " .. encID)
-- end
-- end
-- get boss id for db
-- get boss id for db
local bossID = bossMap[encName]
local bossID = bossMap[encName]
if not bossID then
if not bossID then
-- boss is not in db
-- boss is not in db
bossID = db.NextBossID
bossID = db.NextBossID
db.Bosses[bossID] = encName
db.Bosses[bossID] = encName
bossMap[encName] = bossID
bossMap[encName] = bossID
db.NextBossID = db.NextBossID + 1
db.NextBossID = db.NextBossID + 1
end
end
-- add item to db
-- add item to db
AddToDB(tempDB, itemID, zoneID, bossID, mode)
AddToDB(tempDB, itemID, zoneID, bossID, mode)
end
end
end
end
end
end
-- next instance
-- next instance
UpdateBar()
UpdateBar()
i = i + 1
i = i + 1
insID, insName = EJ_GetInstanceByIndex(i, isRaid)
insID, insName = EJ_GetInstanceByIndex(i, isRaid)
end
end
if isRaid then
if isRaid then
-- done with dungeons + raids, next tier
-- done with dungeons + raids, next tier
break
break
else
else
-- done with dungeons, now do it again for raids
-- done with dungeons, now do it again for raids
isRaid = true
isRaid = true
end
end
end
end
end
end
-- save to db
-- save to db
SaveToDB(tempDungeonDB, "d")
SaveToDB(tempDungeonDB, "d")
SaveToDB(tempRaidDB, "r")
SaveToDB(tempRaidDB, "r")
local _, currentBuild = GetBuildInfo()
local _, currentBuild = GetBuildInfo()
db.ClientBuild = currentBuild
db.ClientBuild = currentBuild
db.Locale = GetLocale()
db.Locale = GetLocale()
db.IEVersion = ieVersion
db.IEVersion = ieVersion
db.Expansion = GetExpansionLevel()
db.Expansion = GetExpansionLevel()
UpdateBar()
UpdateBar()
-- Check loot count
-- Check loot count
local lootCountVerification = GetTotalLootCount(tierCount)
local lootCountVerification = GetTotalLootCount(tierCount)
--IE:Print("totalLootCount = " .. totalLootCount .. " / lootCountVerification = " .. lootCountVerification)
--IE:Print("totalLootCount = " .. totalLootCount .. " / lootCountVerification = " .. lootCountVerification)
-- Check if EJ db is stable
-- Check if EJ db is stable
if totalLootCount < lootCountVerification then
if totalLootCount < lootCountVerification then
-- We missed some items, retry...
-- We missed some items, retry...
--IE:Print("Restarting update...")
--IE:Print("Restarting update...")
UpdateFunction((recursive and recursive or 0) + 1)
UpdateFunction((recursive and recursive or 0) + 1)
else
else
-- Done
-- Done
EndUpdate()
EndUpdate()
--IE:Print("Wait cycles = " .. waitCycles)
--IE:Print("Wait cycles = " .. waitCycles)
end
end
end
end
function IE:EJ_LOOT_DATA_RECIEVED(event, itemID)
function IE:EJ_LOOT_DATA_RECIEVED(event, itemID)
-- self:Print("LOOT_DATA_RECEIVED [" .. (itemID and itemID or "nil") .. "]")
-- self:Print("LOOT_DATA_RECEIVED [" .. (itemID and itemID or "nil") .. "]")
newDataReceived = true
newDataReceived = true
end
end
function IE:CreateLocalDatabase()
function IE:CreateLocalDatabase()
if coUpdate then
if coUpdate then
-- update already in progress
-- update already in progress
return
return
end
end
-- load encounter journal
-- load encounter journal
if not IsAddOnLoaded("Blizzard_EncounterJournal") then
if not IsAddOnLoaded("Blizzard_EncounterJournal") then
local loaded, reason = LoadAddOn("Blizzard_EncounterJournal")
local loaded, reason = LoadAddOn("Blizzard_EncounterJournal")
if not loaded then
if not loaded then
message("[InspectEquip] Could not load encounter journal: " .. reason)
message("[InspectEquip] Could not load encounter journal: " .. reason)
end
end
end
end
-- show progress bar
-- show progress bar
createUpdateGUI()
createUpdateGUI()
bar:Show()
bar:Show()
-- start update
-- start update
coUpdate = coroutine.create(UpdateFunction)
coUpdate = coroutine.create(UpdateFunction)
local ok, msg = coroutine.resume(coUpdate)
local ok, msg = coroutine.resume(coUpdate)
if ok then
if ok then
bar:SetScript("OnUpdate", UpdateTick)
bar:SetScript("OnUpdate", UpdateTick)
else
else
EndUpdate()
EndUpdate()
message("[InspectEquip] Could not update database: " .. msg)
message("[InspectEquip] Could not update database: " .. msg)
end
end
end
end
Copia
Copiato
Copia
Copiato
Diff salvati
Testo originale
Apri file
if not InspectEquip then return end local IE = InspectEquip local IS = InspectEquip_ItemSources local L = LibStub("AceLocale-3.0"):GetLocale("InspectEquip") local band = bit.band local bor = bit.bor local tinsert = table.insert local strfind = string.find local max = math.max -- check for 5.0+ client, because EJ api was changed local mop = select(4, GetBuildInfo()) >= 50000 local wod = select(4, GetBuildInfo()) >= 60000 -- Database InspectEquipLocalDB = {} local ieVersion -- Max wait cycles for database update local MAX_WC = 5 local DATA_RECEIVED_WC = 7 local newDataReceived local newDataCycles = 0 local dbInitialized = false -- GUI local bar, barText local coUpdate function IE:InitLocalDatabase() if dbInitialized then return end if not InspectEquipLocalDB then InspectEquipLocalDB = {} end setmetatable(InspectEquipLocalDB, {__index = { Zones = {}, Bosses = {}, Items = {} }}) local _, currentBuild = GetBuildInfo() ieVersion = GetAddOnMetadata("InspectEquip", "Version") -- create database if not present or outdated (or wrong locale) if (InspectEquipLocalDB.ClientBuild ~= currentBuild) or (InspectEquipLocalDB.Locale ~= GetLocale()) or (InspectEquipLocalDB.IEVersion ~= ieVersion) or (InspectEquipLocalDB.Expansion ~= GetExpansionLevel()) then --self:CreateLocalDatabase() self:ScheduleTimer("CreateLocalDatabase", 5) end dbInitialized = true end local function createUpdateGUI() if not bar then bar = CreateFrame("STATUSBAR", nil, UIParent, "TextStatusBar") end bar:SetWidth(300) bar:SetHeight(30) bar:SetPoint("CENTER", 0, -100) bar:SetBackdrop({ bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = 1, tileSize = 10, edgeSize = 10, insets = {left = 1, right = 1, top = 1, bottom = 1} }) bar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar") bar:SetBackdropColor(0, 0, 0, 1) bar:SetStatusBarColor(0.6, 0.6, 0, 0.4) bar:SetMinMaxValues(0, 100) bar:SetValue(0) if not barText then barText = bar:CreateFontString(nil, "OVERLAY", "GameFontHighlight") end barText:SetPoint("CENTER", bar, "CENTER") barText:SetJustifyH("CENTER") barText:SetJustifyV("CENTER") barText:SetTextColor(1, 1, 1) barText:SetText("InspectEquip: " .. L["Updating database..."]) end local ejDisabled = false local ejToggle = ToggleEncounterJournal -- this function disables the EJ GUI during update -- because using the EJ during update will result in an invalid database -- (other addons may still use the EJ api and possibly destroy the DB that way...) local function DisableEJ() if ejDisabled then return end ejDisabled = true -- hide EJ if EncounterJournal then if EncounterJournal:IsShown() then EncounterJournal:Hide() end end ejToggle = ToggleEncounterJournal ToggleEncounterJournal = function() end EJMicroButton:Disable() end local function EnableEJ() if not ejDisabled then return end ejDisabled = false ToggleEncounterJournal = ejToggle EJMicroButton:Enable() EJMicroButton:SetAlpha(1) end local function EndUpdate() bar:SetScript("OnUpdate", nil) bar:Hide() EnableEJ() coUpdate = nil IE:UnregisterEvent("EJ_LOOT_DATA_RECIEVED") end local function UpdateTick() if coUpdate then -- wait for loot data if newDataReceived then -- data received this frame newDataCycles = newDataCycles + DATA_RECEIVED_WC newDataReceived = false end if newDataCycles > 0 then newDataCycles = newDataCycles - 1 return end local ok, msg = coroutine.resume(coUpdate) if not ok then EndUpdate() message("[InspectEquip] Could not update database: " .. msg) end end end local function UpdateBar() bar:SetValue(bar:GetValue() + 1) coroutine.yield() end local function GetReverseMapping(baseMap) local map = {} local id, name for id, name in pairs(baseMap) do map[name] = id end return map end local function DifficultyToMode(diff, raid) if diff == 1 then -- 5 normal return 2 elseif diff == 2 then -- 5 heroic return 1 elseif diff == 3 then -- 10 normal return 8 elseif diff == 4 then -- 25 normal return 16 elseif diff == 5 then -- 10 heroic return 32 elseif diff == 6 then -- 25 heroic return 64 elseif diff == 7 then -- 25 lfr return 128 elseif diff == 8 then -- 5 challenge TODO return 2 elseif diff == 14 then -- normal / flexible return 65536 elseif diff == 15 then -- heroic return 131072 elseif diff == 16 then -- mythic return 262144 elseif diff == 17 then -- lfr return 524288 end end local function AddToDB(tempDB, itemID, zoneID, bossID, mode) local sources = tempDB[itemID] local entry if sources then for _, entry in pairs(sources) do if (entry[1] == zoneID) and (entry[2] == bossID) then entry[3] = bor(entry[3], mode) return end end tinsert(sources, {zoneID, bossID, mode}) else tempDB[itemID] = {{zoneID, bossID, mode}} end end local function SaveToDB(tempDB, entryType) local itemID, sources, entry for itemID, sources in pairs(tempDB) do local str = InspectEquipLocalDB.Items[itemID] local isEntry = IS.Items[itemID] -- loop through sources we found for _, entry in pairs(sources) do local entryStr = entryType .. "_" .. entry[1] .. "_" .. entry[3] .. "_" .. entry[2] -- skip if already in IS DB if not (isEntry and (strfind(";" .. isEntry .. ";", ";" .. entryStr .. ";"))) then if str then str = str .. ";" .. entryStr else str = entryStr end end end InspectEquipLocalDB.Items[itemID] = str end end local function GetInstanceCount(isRaid) local i = 1 local id repeat id = EJ_GetInstanceByIndex(i, isRaid) i = i + 1 until not id return i - 2 end local function GetTotalLootCount(tierCount) local lootCount = 0 local tier, i for tier = 1, tierCount do if mop then EJ_SelectTier(tier) end local isRaid = false while true do i = 1 local insID, insName = EJ_GetInstanceByIndex(i, isRaid) while insID do EJ_SelectInstance(insID) local diff local diffOffset = (mop and isRaid) and 2 or 0 local maxDiff = isRaid and 5 or 2 for diff = 1, maxDiff do if EJ_IsValidInstanceDifficulty(diff + diffOffset) then EJ_SetDifficulty(diff) lootCount = lootCount + EJ_GetNumLoot() end end i = i + 1 insID, insName = EJ_GetInstanceByIndex(i, isRaid) end if isRaid then break else isRaid = true end end end return lootCount end local function UpdateFunction(recursive) local _, i, j, tier -- reset EJ DisableEJ() EJ_ClearSearch() if mop then EJ_ResetLootFilter() else EJ_SetClassLootFilter(0) end newDataReceived = false IE:RegisterEvent("EJ_LOOT_DATA_RECIEVED") -- init/reset database local db = InspectEquipLocalDB db.Zones = {} db.Bosses = {} db.Items = {} db.NextZoneID = 1000 db.NextBossID = 1000 -- count total number of instances local insCount = 0 local tierCount = 1 if mop then -- as of 5.x there are multiple tiers (classic, bc, wotlk, cata, mop...) tierCount = EJ_GetNumTiers() for tier = 1, tierCount do local tierName = EJ_GetTierInfo(tier) EJ_SelectTier(tier) --IE:Print("Tier: " .. tostring(tier) .. " = " .. tierName) local dungeonCount = GetInstanceCount(false) local raidCount = GetInstanceCount(true) --IE:Print(" ==> " .. tostring(dungeonCount) .. " Dungeons, " .. tostring(raidCount) .. " Raids") insCount = insCount + dungeonCount + raidCount end else local dungeonCount = GetInstanceCount(false) local raidCount = GetInstanceCount(true) insCount = dungeonCount + raidCount --IE:Print(" ==> " .. tostring(dungeonCount) .. " Dungeons, " .. tostring(raidCount) .. " Raids") end -- set bar max value local startValue = bar:GetValue() bar:SetMinMaxValues(0, startValue + insCount + 2) -- get IS mapping for zone/boss name -> zone/boss id local zoneMap = GetReverseMapping(IS.Zones) local bossMap = GetReverseMapping(IS.Bosses) UpdateBar() -- temp db to allow for merging of modes local tempDungeonDB = {} local tempRaidDB = {} local totalLootCount = 0 local waitCycles = 0 -- get loot for tier = 1, tierCount do if mop then EJ_SelectTier(tier) end -- loop through all instances of this tier, dungeons first, then raids local isRaid = false while true do i = 1 local insID, insName = EJ_GetInstanceByIndex(i, isRaid) local tempDB = isRaid and tempRaidDB or tempDungeonDB while insID do -- get zone id for db local zoneID = zoneMap[insName] if not zoneID then -- zone is not in db zoneID = db.NextZoneID db.Zones[zoneID] = insName zoneMap[insName] = zoneID db.NextZoneID = db.NextZoneID + 1 end EJ_SelectInstance(insID) local diff local difficulties if wod then if isRaid then difficulties = {3, 4, 5, 6, 7, 14, 15, 16, 17} else difficulties = {1, 2, 8} end elseif mop then if isRaid then difficulties = {3, 4, 5, 6, 7, 14} else difficulties = {1, 2} end else -- not sure if this still works. probably not. if isRaid then difficulties = {1, 2, 3, 4, 5} else difficulties = {1, 2} end end for _, diff in ipairs(difficulties) do if EJ_IsValidInstanceDifficulty(diff) then newDataCycles = DATA_RECEIVED_WC * 3 EJ_SetDifficulty(diff) local mode = DifficultyToMode(diff, isRaid) local n = EJ_GetNumLoot() -- the problem here is that when the items are not in the cache, EJ_GetNumLoot() will not -- return the correct number. it returns the number of items that are cached, which may be -- 0 or a number lower than the correct number. it seems to be impossible to determine the -- correct number without waiting. EJ_LOOT_DATA_RECIEVED events are received, but we don't -- know which event is the last one. also, no EJ_LOOT_DATA_RECIEVED are received if all -- items are already in the cache. so we try to wait a couple of frames until we have a -- number that is somehow stable. -- at the end we count all items again, and if we then have more items, we start all over -- again (at this point, the items are already cached, so the 2nd iteration is faster). local wc = 0 local wcMax = MAX_WC while wc < wcMax do coroutine.yield() wc = wc + 1 local nNew = EJ_GetNumLoot() if n ~= nNew then wcMax = wc + MAX_WC end n = nNew end waitCycles = waitCycles + wc totalLootCount = totalLootCount + n --IE:Print("T=" .. tostring(tier) .. " I=" .. insName .. " D=" .. diff .. " M=" .. mode .. " ! #loot = " .. n .. " [wc = " .. wc .. "]") for j = 1, n do -- get item info local itemName, _, _, _, itemID, itemLink, encID = EJ_GetLootInfoByIndex(j) -- wait until data has arrived -- this doesn't seem necessary -- while not itemID do -- coroutine.yield() -- waitCycles = waitCycles + 1 -- itemName, _, _, _, itemID, itemLink, encID = EJ_GetLootInfoByIndex(j) -- end local encName = EJ_GetEncounterInfo(encID) -- if not encName then -- IE:Print("no encounter name! encID = " .. encID) -- end -- get boss id for db local bossID = bossMap[encName] if not bossID then -- boss is not in db bossID = db.NextBossID db.Bosses[bossID] = encName bossMap[encName] = bossID db.NextBossID = db.NextBossID + 1 end -- add item to db AddToDB(tempDB, itemID, zoneID, bossID, mode) end end end -- next instance UpdateBar() i = i + 1 insID, insName = EJ_GetInstanceByIndex(i, isRaid) end if isRaid then -- done with dungeons + raids, next tier break else -- done with dungeons, now do it again for raids isRaid = true end end end -- save to db SaveToDB(tempDungeonDB, "d") SaveToDB(tempRaidDB, "r") local _, currentBuild = GetBuildInfo() db.ClientBuild = currentBuild db.Locale = GetLocale() db.IEVersion = ieVersion db.Expansion = GetExpansionLevel() UpdateBar() -- Check loot count local lootCountVerification = GetTotalLootCount(tierCount) --IE:Print("totalLootCount = " .. totalLootCount .. " / lootCountVerification = " .. lootCountVerification) -- Check if EJ db is stable if totalLootCount < lootCountVerification then -- We missed some items, retry... --IE:Print("Restarting update...") UpdateFunction((recursive and recursive or 0) + 1) else -- Done EndUpdate() --IE:Print("Wait cycles = " .. waitCycles) end end function IE:EJ_LOOT_DATA_RECIEVED(event, itemID) -- self:Print("LOOT_DATA_RECEIVED [" .. (itemID and itemID or "nil") .. "]") newDataReceived = true end function IE:CreateLocalDatabase() if coUpdate then -- update already in progress return end -- load encounter journal if not IsAddOnLoaded("Blizzard_EncounterJournal") then local loaded, reason = LoadAddOn("Blizzard_EncounterJournal") if not loaded then message("[InspectEquip] Could not load encounter journal: " .. reason) end end -- show progress bar createUpdateGUI() bar:Show() -- start update coUpdate = coroutine.create(UpdateFunction) local ok, msg = coroutine.resume(coUpdate) if ok then bar:SetScript("OnUpdate", UpdateTick) else EndUpdate() message("[InspectEquip] Could not update database: " .. msg) end end
Testo modificato
Apri file
if not InspectEquip then return end local IE = InspectEquip local IS = InspectEquip_ItemSources local L = LibStub("AceLocale-3.0"):GetLocale("InspectEquip") local band = bit.band local bor = bit.bor local tinsert = table.insert local strfind = string.find local max = math.max -- check for 5.0+ client, because EJ api was changed local mop = select(4, GetBuildInfo()) >= 50000 local wod = select(4, GetBuildInfo()) >= 60000 -- Database InspectEquipLocalDB = {} local ieVersion -- Max wait cycles for database update local MAX_WC = 5 local DATA_RECEIVED_WC = 7 local newDataReceived local dbInitialized = false -- GUI local bar, barText local coUpdate function IE:InitLocalDatabase() if dbInitialized then return end if not InspectEquipLocalDB then InspectEquipLocalDB = {} end setmetatable(InspectEquipLocalDB, {__index = { Zones = {}, Bosses = {}, Items = {} }}) local _, currentBuild = GetBuildInfo() ieVersion = GetAddOnMetadata("InspectEquip", "Version") -- create database if not present or outdated (or wrong locale) if (InspectEquipLocalDB.ClientBuild ~= currentBuild) or (InspectEquipLocalDB.Locale ~= GetLocale()) or (InspectEquipLocalDB.IEVersion ~= ieVersion) or (InspectEquipLocalDB.Expansion ~= GetExpansionLevel()) then --self:CreateLocalDatabase() self:ScheduleTimer("CreateLocalDatabase", 5) end dbInitialized = true end local function createUpdateGUI() if not bar then bar = CreateFrame("STATUSBAR", nil, UIParent, "TextStatusBar") end bar:SetWidth(300) bar:SetHeight(30) bar:SetPoint("CENTER", 0, -100) bar:SetBackdrop({ bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = 1, tileSize = 10, edgeSize = 10, insets = {left = 1, right = 1, top = 1, bottom = 1} }) bar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar") bar:SetBackdropColor(0, 0, 0, 1) bar:SetStatusBarColor(0.6, 0.6, 0, 0.4) bar:SetMinMaxValues(0, 100) bar:SetValue(0) if not barText then barText = bar:CreateFontString(nil, "OVERLAY", "GameFontHighlight") end barText:SetPoint("CENTER", bar, "CENTER") barText:SetJustifyH("CENTER") barText:SetJustifyV("CENTER") barText:SetTextColor(1, 1, 1) barText:SetText("InspectEquip: " .. L["Updating database..."]) end local ejDisabled = false local ejToggle = ToggleEncounterJournal -- this function disables the EJ GUI during update -- because using the EJ during update will result in an invalid database -- (other addons may still use the EJ api and possibly destroy the DB that way...) local function DisableEJ() if ejDisabled then return end ejDisabled = true -- hide EJ if EncounterJournal then if EncounterJournal:IsShown() then EncounterJournal:Hide() end end ejToggle = ToggleEncounterJournal ToggleEncounterJournal = function() end EJMicroButton:Disable() end local function EnableEJ() if not ejDisabled then return end ejDisabled = false ToggleEncounterJournal = ejToggle EJMicroButton:Enable() EJMicroButton:SetAlpha(1) end local function EndUpdate() bar:SetScript("OnUpdate", nil) bar:Hide() EnableEJ() coUpdate = nil IE:UnregisterEvent("EJ_LOOT_DATA_RECIEVED") end local function UpdateTick() if coUpdate then -- wait for loot data if newDataReceived then -- data received this frame newDataCycles = newDataCycles + DATA_RECEIVED_WC newDataReceived = false end if newDataCycles and newDataCycles > 0 then newDataCycles = newDataCycles - 1 return end local ok, msg = coroutine.resume(coUpdate) if not ok then EndUpdate() message("[InspectEquip] Could not update database: " .. msg) end end end local function UpdateBar() bar:SetValue(bar:GetValue() + 1) coroutine.yield() end local function GetReverseMapping(baseMap) local map = {} local id, name for id, name in pairs(baseMap) do map[name] = id end return map end local function DifficultyToMode(diff, raid) if diff == 1 then -- 5 normal return 2 elseif diff == 2 then -- 5 heroic return 1 elseif diff == 3 then -- 10 normal return 8 elseif diff == 4 then -- 25 normal return 16 elseif diff == 5 then -- 10 heroic return 32 elseif diff == 6 then -- 25 heroic return 64 elseif diff == 7 then -- 25 lfr return 128 elseif diff == 8 then -- 5 challenge TODO return 2 elseif diff == 14 then -- normal / flexible return 65536 elseif diff == 15 then -- heroic return 131072 elseif diff == 16 then -- mythic return 262144 elseif diff == 17 then -- lfr return 524288 end end local function AddToDB(tempDB, itemID, zoneID, bossID, mode) local sources = tempDB[itemID] local entry if sources then for _, entry in pairs(sources) do if (entry[1] == zoneID) and (entry[2] == bossID) then entry[3] = bor(entry[3], mode) return end end tinsert(sources, {zoneID, bossID, mode}) else tempDB[itemID] = {{zoneID, bossID, mode}} end end local function SaveToDB(tempDB, entryType) local itemID, sources, entry for itemID, sources in pairs(tempDB) do local str = InspectEquipLocalDB.Items[itemID] local isEntry = IS.Items[itemID] -- loop through sources we found for _, entry in pairs(sources) do local entryStr = entryType .. "_" .. entry[1] .. "_" .. entry[3] .. "_" .. entry[2] -- skip if already in IS DB if not (isEntry and (strfind(";" .. isEntry .. ";", ";" .. entryStr .. ";"))) then if str then str = str .. ";" .. entryStr else str = entryStr end end end InspectEquipLocalDB.Items[itemID] = str end end local function GetInstanceCount(isRaid) local i = 1 local id repeat id = EJ_GetInstanceByIndex(i, isRaid) i = i + 1 until not id return i - 2 end local function GetTotalLootCount(tierCount) local lootCount = 0 local tier, i for tier = 1, tierCount do if mop then EJ_SelectTier(tier) end local isRaid = false while true do i = 1 local insID, insName = EJ_GetInstanceByIndex(i, isRaid) while insID do EJ_SelectInstance(insID) local diff local diffOffset = (mop and isRaid) and 2 or 0 local maxDiff = isRaid and 5 or 2 for diff = 1, maxDiff do if EJ_IsValidInstanceDifficulty(diff + diffOffset) then EJ_SetDifficulty(diff) lootCount = lootCount + EJ_GetNumLoot() end end i = i + 1 insID, insName = EJ_GetInstanceByIndex(i, isRaid) end if isRaid then break else isRaid = true end end end return lootCount end local function UpdateFunction(recursive) local _, i, j, tier -- reset EJ DisableEJ() EJ_ClearSearch() if mop then EJ_ResetLootFilter() else EJ_SetClassLootFilter(0) end newDataReceived = false IE:RegisterEvent("EJ_LOOT_DATA_RECIEVED") -- init/reset database local db = InspectEquipLocalDB db.Zones = {} db.Bosses = {} db.Items = {} db.NextZoneID = 1000 db.NextBossID = 1000 -- count total number of instances local insCount = 0 local tierCount = 1 if mop then -- as of 5.x there are multiple tiers (classic, bc, wotlk, cata, mop...) tierCount = EJ_GetNumTiers() for tier = 1, tierCount do local tierName = EJ_GetTierInfo(tier) EJ_SelectTier(tier) --IE:Print("Tier: " .. tostring(tier) .. " = " .. tierName) local dungeonCount = GetInstanceCount(false) local raidCount = GetInstanceCount(true) --IE:Print(" ==> " .. tostring(dungeonCount) .. " Dungeons, " .. tostring(raidCount) .. " Raids") insCount = insCount + dungeonCount + raidCount end else local dungeonCount = GetInstanceCount(false) local raidCount = GetInstanceCount(true) insCount = dungeonCount + raidCount --IE:Print(" ==> " .. tostring(dungeonCount) .. " Dungeons, " .. tostring(raidCount) .. " Raids") end -- set bar max value local startValue = bar:GetValue() bar:SetMinMaxValues(0, startValue + insCount + 2) -- get IS mapping for zone/boss name -> zone/boss id local zoneMap = GetReverseMapping(IS.Zones) local bossMap = GetReverseMapping(IS.Bosses) UpdateBar() -- temp db to allow for merging of modes local tempDungeonDB = {} local tempRaidDB = {} local totalLootCount = 0 local waitCycles = 0 -- get loot for tier = 1, tierCount do if mop then EJ_SelectTier(tier) end -- loop through all instances of this tier, dungeons first, then raids local isRaid = false while true do i = 1 local insID, insName = EJ_GetInstanceByIndex(i, isRaid) local tempDB = isRaid and tempRaidDB or tempDungeonDB while insID do -- get zone id for db local zoneID = zoneMap[insName] if not zoneID then -- zone is not in db zoneID = db.NextZoneID db.Zones[zoneID] = insName zoneMap[insName] = zoneID db.NextZoneID = db.NextZoneID + 1 end EJ_SelectInstance(insID) local diff local difficulties if wod then if isRaid then difficulties = {3, 4, 5, 6, 7, 14, 15, 16, 17} else difficulties = {1, 2, 8} end elseif mop then if isRaid then difficulties = {3, 4, 5, 6, 7, 14} else difficulties = {1, 2} end else -- not sure if this still works. probably not. if isRaid then difficulties = {1, 2, 3, 4, 5} else difficulties = {1, 2} end end for _, diff in ipairs(difficulties) do if EJ_IsValidInstanceDifficulty(diff) then newDataCycles = DATA_RECEIVED_WC * 3 EJ_SetDifficulty(diff) local mode = DifficultyToMode(diff, isRaid) local n = EJ_GetNumLoot() -- the problem here is that when the items are not in the cache, EJ_GetNumLoot() will not -- return the correct number. it returns the number of items that are cached, which may be -- 0 or a number lower than the correct number. it seems to be impossible to determine the -- correct number without waiting. EJ_LOOT_DATA_RECIEVED events are received, but we don't -- know which event is the last one. also, no EJ_LOOT_DATA_RECIEVED are received if all -- items are already in the cache. so we try to wait a couple of frames until we have a -- number that is somehow stable. -- at the end we count all items again, and if we then have more items, we start all over -- again (at this point, the items are already cached, so the 2nd iteration is faster). local wc = 0 local wcMax = MAX_WC while wc < wcMax do coroutine.yield() wc = wc + 1 local nNew = EJ_GetNumLoot() if n ~= nNew then wcMax = wc + MAX_WC end n = nNew end waitCycles = waitCycles + wc totalLootCount = totalLootCount + n --IE:Print("T=" .. tostring(tier) .. " I=" .. insName .. " D=" .. diff .. " M=" .. mode .. " ! #loot = " .. n .. " [wc = " .. wc .. "]") for j = 1, n do -- get item info local itemID, encID, itemName, _, _, _, itemLink = EJ_GetLootInfoByIndex(j) -- wait until data has arrived -- this doesn't seem necessary -- while not itemID do -- coroutine.yield() -- waitCycles = waitCycles + 1 -- itemName, _, _, _, itemID, itemLink, encID = EJ_GetLootInfoByIndex(j) -- end local encName = EJ_GetEncounterInfo(encID) -- if not encName then -- IE:Print("no encounter name! encID = " .. encID) -- end -- get boss id for db local bossID = bossMap[encName] if not bossID then -- boss is not in db bossID = db.NextBossID db.Bosses[bossID] = encName bossMap[encName] = bossID db.NextBossID = db.NextBossID + 1 end -- add item to db AddToDB(tempDB, itemID, zoneID, bossID, mode) end end end -- next instance UpdateBar() i = i + 1 insID, insName = EJ_GetInstanceByIndex(i, isRaid) end if isRaid then -- done with dungeons + raids, next tier break else -- done with dungeons, now do it again for raids isRaid = true end end end -- save to db SaveToDB(tempDungeonDB, "d") SaveToDB(tempRaidDB, "r") local _, currentBuild = GetBuildInfo() db.ClientBuild = currentBuild db.Locale = GetLocale() db.IEVersion = ieVersion db.Expansion = GetExpansionLevel() UpdateBar() -- Check loot count local lootCountVerification = GetTotalLootCount(tierCount) --IE:Print("totalLootCount = " .. totalLootCount .. " / lootCountVerification = " .. lootCountVerification) -- Check if EJ db is stable if totalLootCount < lootCountVerification then -- We missed some items, retry... --IE:Print("Restarting update...") UpdateFunction((recursive and recursive or 0) + 1) else -- Done EndUpdate() --IE:Print("Wait cycles = " .. waitCycles) end end function IE:EJ_LOOT_DATA_RECIEVED(event, itemID) -- self:Print("LOOT_DATA_RECEIVED [" .. (itemID and itemID or "nil") .. "]") newDataReceived = true end function IE:CreateLocalDatabase() if coUpdate then -- update already in progress return end -- load encounter journal if not IsAddOnLoaded("Blizzard_EncounterJournal") then local loaded, reason = LoadAddOn("Blizzard_EncounterJournal") if not loaded then message("[InspectEquip] Could not load encounter journal: " .. reason) end end -- show progress bar createUpdateGUI() bar:Show() -- start update coUpdate = coroutine.create(UpdateFunction) local ok, msg = coroutine.resume(coUpdate) if ok then bar:SetScript("OnUpdate", UpdateTick) else EndUpdate() message("[InspectEquip] Could not update database: " .. msg) end end
Trovare la differenza