Files
wow-weakauras/FreshShit/BattlePassTimer/init.lua

83 lines
2.6 KiB
Lua

if not WeakAurasSaved.Cyka then WeakAurasSaved.Cyka = {} end
if not WeakAurasSaved.Cyka.LoginInfo then WeakAurasSaved.Cyka.LoginInfo = {} end
Today = date("%Y-%m-%d")
if not WeakAurasSaved.Cyka.LoginInfo[Today] then WeakAurasSaved.Cyka.LoginInfo[Today] = {} end
if not WeakAurasSaved.Cyka.LoginInfo[Today][UnitName("player")] then
WeakAurasSaved.Cyka.LoginInfo[Today][UnitName("player")] = {
onlineTimeInMinutes = 0,
claimed = 0,
}
end
---@param input string
---@param deliminer string
---@return table<string>
aura_env.Split = function(input, deliminer)
local ret = {}
for str in string.gmatch(input, "([^" .. deliminer .. "]+)") do
table.insert(ret, str)
end
return ret
end
---@class BattlepassInfo
---@field week number
---@field getRew number
---@field dayRewardComplete number
---@field lostDay number
---@field cost number
---@field currentDayOnlineTimeMinutes number
---@field currentDayOnlineTimeMilliseconds number
BattlepassInfo = {
PingApi = function()
SendAddonMessage('UIMSG_TO_SERVER', "UIMSG_GET_ONLINETIME_DAY" .. "\t", 'WHISPER', UnitName('player'))
end,
ParseApi = function(msg)
local packets = aura_env.Split(msg, ":")
if packets[1] ~= "UISMSG_EVT_WEEK_TIME" then return end
BattlepassInfo.currentDayOnlineTimeMilliseconds = tonumber(packets[2])
BattlepassInfo.week = tonumber(packets[3]) + 1
BattlepassInfo.getRew = tonumber(packets[4])
BattlepassInfo.dayRewardComplete = tonumber(packets[5])
BattlepassInfo.lostDay = tonumber(packets[6])
BattlepassInfo.cost = tonumber(packets[7])
BattlepassInfo.currentDayOnlineTimeMinutes = math.ceil(BattlepassInfo.currentDayOnlineTimeMilliseconds / 60000)
WeakAurasSaved.Cyka.LoginInfo[Today][UnitName("player")].onlineTimeInMinutes = BattlepassInfo
.currentDayOnlineTimeMinutes
WeakAurasSaved.Cyka.LoginInfo[Today][UnitName("player")].claimed = BattlepassInfo.dayRewardComplete
if BattlepassInfo.dayRewardComplete == 0 and BattlepassInfo.currentDayOnlineTimeMinutes >= 120 then
BattlepassInfo.DoClaim()
C_Timer.After(0.2, function()
BattlepassInfo.PingApi()
end)
end
end,
DoClaim = function()
SendAddonMessage('UIMSG_TO_SERVER', "UIMSG_WEEKLY_REW_GET" .. "\t", 'WHISPER', UnitName('player'))
end
}
setmetatable(BattlepassInfo, {
__call = BattlepassInfo.PingApi,
__index = BattlepassInfo,
__tostring = function()
local ret = {}
for k, v in pairs(BattlepassInfo) do
table.insert(ret, k .. ": " .. tostring(v))
end
return table.concat(ret, "\n")
end
})
for k, v in pairs(BattlepassInfo) do
if type(v) == "number" then
BattlepassInfo[k] = 0
end
end
BattlepassInfo()
-- Claiming rewards works fine
-- But the bar does not hide once rewards are claimed