Commit 8deb52c0 authored by Merathilis's avatar Merathilis

This fucking Invasion Timers are driving me nuts. Switched back to the beginning code.

parent ab068d4b
......@@ -6,6 +6,7 @@ local MERS = MER:GetModule("muiSkins")
--Lua functions
local _G = _G
local ipairs, pairs, select, tonumber, unpack = ipairs, pairs, select, tonumber, unpack
local tinsert = table.insert
local floor = math.floor
local format = string.format
local strfind = strfind
......@@ -188,25 +189,82 @@ local questlist = {
{name = L["Timewarped"], id = 45799, texture = 1530590} -- MoP
}
-- Invasion Code --
-- Invasion
local region = GetCVar("portal")
local legionZoneTime = {
["EU"] = 1565168400, -- CN-16
["US"] = 1565197200, -- CN-8
["CN"] = 1565226000, -- CN time 8/8/2019 09:00 [1]
}
local bfaZoneTime = {
["CN"] = 1546743600, -- CN time 1/6/2019 11:00 [1]
["EU"] = 1546768800, -- CN+7
["US"] = 1546769340, -- CN+16
}
if not region or #region ~= 2 then
local regionID = GetCurrentRegion()
region = regionID and ({ "US", "KR", "EU", "TW", "CN" })[regionID]
end
-- Check Invasion Status
local invIndex = {
[1] = {title = L["Legion Invasion"], duration = 66600, maps = {630, 641, 650, 634}, timeTable = {}, baseTime = legionZoneTime[region] or legionZoneTime["EU"]},
[2] = {title = L["Faction Assault"], duration = 68400, maps = {862, 863, 864, 896, 942, 895}, timeTable = {4, 1, 6, 2, 5, 3}, baseTime = bfaZoneTime[region] or bfaZoneTime["EU"]},
{
title = L["Faction Assault"], -- BfA Invasions
interval = 68400,
duration = 25200,
maps = {862, 863, 864, 896, 942, 895},
timeTable = {4, 1, 6, 2, 5, 3},
-- Drustvar Beginning
baseTime = {
US = 1548032400, -- 01/20/2019 17:00 UTC-8
EU = 1548000000, -- 01/20/2019 16:00 UTC+0
CN = 1546743600, -- 01/06/2019 11:00 UTC+8
},
},
{
title = L["Legion Invasion"], -- Legion Invasions
interval = 66600,
duration = 21600,
maps = {630, 641, 650, 634},
timeTable = {4, 3, 2, 1, 4, 2, 3, 1, 2, 4, 1, 3},
-- Stormheim Beginning then Highmountain
baseTime = {
US = 1547614800, -- 01/15/2019 21:00 UTC-8
EU = 1547586000, -- 01/15/2019 21:00 UTC+0
CN = 1546844400, -- 01/07/2019 15:00 UTC+8
},
}
}
local function GetCurrentInvasion(index)
local inv = invIndex[index]
local currentTime = time()
local baseTime = inv.baseTime[region]
local duration = inv.duration
local interval = inv.interval
local elapsed = mod(currentTime - baseTime, interval)
if elapsed < duration then
local count = #inv.timeTable
local round = mod(floor((currentTime - baseTime) / interval) + 1, count)
if round == 0 then
round = count
end
return duration - elapsed, C_Map_GetMapInfo(inv.maps[inv.timeTable[round]]).name
end
end
local function GetFutureInvasion(index, length)
if not length then length = 1 end
local tbl, i = {}
local inv = invIndex[index]
local currentTime = time()
local baseTime = inv.baseTime[region]
local interval = inv.interval
local count = #inv.timeTable
local elapsed = mod(currentTime - baseTime, interval)
local nextTime = interval - elapsed + currentTime
local round = mod(floor((nextTime - baseTime) / interval) + 1, count)
for i = 1, length do
if round == 0 then round = count end
tinsert(tbl, {nextTime, C_Map_GetMapInfo(inv.maps[inv.timeTable[round]]).name})
nextTime = nextTime + interval
round = mod(round + 1, count)
end
return tbl
end
-- Fallback
local mapAreaPoiIDs = {
[630] = 5175,
[641] = 5210,
......@@ -217,10 +275,10 @@ local mapAreaPoiIDs = {
[864] = 5970,
[896] = 5964,
[942] = 5966,
[895] = 5896
[895] = 5896,
}
local function GetInvasionTimeInfo(mapID)
local function GetInvasionInfo(mapID)
local areaPoiID = mapAreaPoiIDs[mapID]
local seconds = C_AreaPoiInfo_GetAreaPOISecondsLeft(areaPoiID)
local mapInfo = C_Map_GetMapInfo(mapID)
......@@ -229,31 +287,28 @@ end
local function CheckInvasion(index)
for _, mapID in pairs(invIndex[index].maps) do
local timeLeft, name = GetInvasionTimeInfo(mapID)
local timeLeft, name = GetInvasionInfo(mapID)
if timeLeft and timeLeft > 0 then
return timeLeft, name
end
end
end
local function GetNextTime(baseTime, index)
local currentTime = time()
local duration = invIndex[index].duration
local elapsed = mod(currentTime - baseTime, duration)
return duration - elapsed + currentTime
end
local function GetNextLocation(nextTime, index)
local inv = invIndex[index]
local count = #inv.timeTable
if count == 0 then return QUEUE_TIME_UNAVAILABLE end
local DUNGEON_FLOOR_TEMPESTKEEP1 = DUNGEON_FLOOR_TEMPESTKEEP1
local TempestKeep = select(2, GetAchievementInfo(1088)):match('%((.-)%)$')
local elapsed = nextTime - inv.baseTime
local round = mod(floor(elapsed / inv.duration) + 1, count)
if round == 0 then round = count end
return C_Map_GetMapInfo(inv.maps[inv.timeTable[round]]).name
local instanceIconByName = {}
local function GetInstanceImages(index, raid)
local instanceID, name, _, _, buttonImage = EJ_GetInstanceByIndex(index, raid);
while instanceID do
if name == DUNGEON_FLOOR_TEMPESTKEEP1 then
instanceIconByName[TempestKeep] = buttonImage
else
instanceIconByName[name] = buttonImage
end
index = index + 1
instanceID, name, _, _, buttonImage = EJ_GetInstanceByIndex(index, raid);
end
end
local title
......@@ -265,6 +320,7 @@ local function addTitle(text)
end
end
local collectedInstanceImages = false
function module.OnEnter(self)
if E.db.mui.microBar.tooltip ~= true then
return
......@@ -279,6 +335,27 @@ function module.OnEnter(self)
return
end
if not collectedInstanceImages then
local numTiers = (EJ_GetNumTiers() or 0)
if numTiers > 0 then
local currentTier = EJ_GetCurrentTier()
-- Loop through the expansions to collect the textures
for i = 1, numTiers do
EJ_SelectTier(i);
GetInstanceImages(1, false); -- Populate for dungeon icons
GetInstanceImages(1, true); -- Populate for raid icons
end
-- Set it back to the previous tier
if currentTier then
EJ_SelectTier(currentTier);
end
collectedInstanceImages = true
end
end
GameTooltip:SetOwner(self, "ANCHOR_BOTTOM")
GameTooltip:ClearAllPoints()
GameTooltip:SetPoint("BOTTOM", timeButton, "TOP")
......@@ -314,8 +391,10 @@ function module.OnEnter(self)
-- Mythic Dungeons
title = false
local img
for i = 1, GetNumSavedInstances() do
local name, _, reset, diff, locked, extended = GetSavedInstanceInfo(i)
img = instanceIconByName[name] and format("|T%s:16:16:0:0:96:96:0:64:0:64|t ", instanceIconByName[name]) or ""
if diff == 23 and (locked or extended) then
addTitle(L["Mythic Dungeon"])
if extended then
......@@ -323,14 +402,16 @@ function module.OnEnter(self)
else
r, g, b = 1, 1, 1
end
GameTooltip:AddDoubleLine(name, SecondsToTime(reset, true, nil, 3), 1, 1, 1, r, g, b)
GameTooltip:AddDoubleLine(img..name, SecondsToTime(reset, true, nil, 3), 1, 1, 1, r, g, b)
end
end
-- Raids
title = false
local img
for i = 1, GetNumSavedInstances() do
local name, _, reset, _, locked, extended, _, isRaid, _, diffName = GetSavedInstanceInfo(i)
img = instanceIconByName[name] and format("|T%s:16:16:0:0:96:96:0:64:0:64|t ", instanceIconByName[name]) or ""
if isRaid and (locked or extended) then
addTitle(RAID_INFORMATION)
if extended then
......@@ -338,7 +419,7 @@ function module.OnEnter(self)
else
r, g, b = 1, 1, 1
end
GameTooltip:AddDoubleLine(name .. " - " .. diffName, SecondsToTime(reset, true, nil, 3), 1, 1, 1, r, g, b)
GameTooltip:AddDoubleLine(img..name .. " - " .. diffName, SecondsToTime(reset, true, nil, 3), 1, 1, 1, r, g, b)
end
end
......@@ -385,23 +466,41 @@ function module.OnEnter(self)
end
-- Invasions
GameTooltip:AddLine(" ")
for index, value in ipairs(invIndex) do
title = false
addTitle(value.title)
local timeLeft, zoneName = CheckInvasion(index)
local nextTime = GetNextTime(value.baseTime, index)
if timeLeft then
timeLeft = timeLeft / 60
if timeLeft < 60 then
r, g, b = 1, 0, 0
else
r, g, b = 0, 1, 0
GameTooltip:AddLine(value.title)
if value.baseTime[region] then
-- baseTime provided
local timeLeft, zoneName = GetCurrentInvasion(index)
if timeLeft then
timeLeft = timeLeft / 60
if timeLeft < 60 then
r, g ,b = 1, 0, 0
else
r, g, b = 0, 1, 0
end
GameTooltip:AddDoubleLine(L["Current Invasion: "] .. zoneName, format("%dh %.2dm", timeLeft / 60, timeLeft % 60), 1, 1, 1, r, g, b)
end
local futureTable, i = GetFutureInvasion(index, 2)
for i = 1, #futureTable do
local nextTime, zoneName = unpack(futureTable[i])
GameTooltip:AddDoubleLine(L["Next Invasion: "] .. zoneName, date("%d/%m - %H:%M", nextTime), 1, 1, 1)
end
GameTooltip:AddDoubleLine(L["Current Invasion: "] .. zoneName, format("%.2d:%.2d", timeLeft / 60, timeLeft % 60), 1, 1, 1, r, g, b)
GameTooltip:AddDoubleLine(L["Next Invasion: "] .. GetNextLocation(nextTime, index), date("%d/%m %H:%M", nextTime), 1, 1, 1, 1, 1, 1)
else
GameTooltip:AddDoubleLine(L["Missing invasion info on your realm."])
local timeLeft, zoneName = CheckInvasion(index)
if timeLeft then
timeLeft = timeLeft / 60
if timeLeft < 60 then
r, g, b = 1, 0, 0
else
r, g, b = 0, 1, 0
end
GameTooltip:AddDoubleLine(L["Current Invasion: "] .. zoneName, format("%dh %.2dm", timeLeft / 60, timeLeft % 60), 1, 1, 1, r, g, b)
else
GameTooltip:AddLine(L["Missing invasion info on your realm."])
end
end
GameTooltip:AddLine(" ")
end
GameTooltip:Show()
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment