--[[ |
|
NotBloated.004.1 |
Sliker, Auchindoun EU |
|
TODO: add way to ignore a bg |
|
--]] |
|
-- Initialize |
|
-- Change this to false to disable the larger warning |
-- The number must correspond to another in the warningsDone table |
local bigWarning = { 5, 5 } |
-- local bigWarning = { false, false } |
|
-- As it says, the times are in minutes. If you want a warning at |
-- 25 minutes, add this line: |
-- [25] = false, |
local warningsDone = { |
['big'] = { false, false }, |
-- In minutes: |
[120] = { false, false }, |
[60] = { false, false }, |
[30] = { false, false }, |
[15] = { false, false }, |
[5] = { false, false }, |
[0] = { false, false } |
} |
|
local Times = {} |
|
local lastSync, lastUpdate = 180, 1 |
local canUp, doBigWarning = false, false |
|
local debug = false |
local NotBloated = CreateFrame('Frame', 'NotBloated') |
|
local function print(msg) DEFAULT_CHAT_FRAME:AddMessage('NotBloated: ' .. msg) end |
|
--- Functions --- |
|
function NotBloated:OnEvent(event, addon) |
if event == 'ADDON_LOADED' and addon ~= 'NotBloated' then return end |
|
local x, i = GetNumWorldPVPAreas() |
|
for i = 1, x do |
Times[i] = { ['n'] = select(2, GetWorldPVPAreaInfo(i)) } |
end |
|
-- just in case the impossible happens |
canUp = true |
|
-- i am asking myself if I /really/ needed to future proof this |
end |
|
function NotBloated:OnUpdate(elapsed) |
lastSync = lastSync + elapsed |
lastUpdate = lastUpdate + elapsed |
|
if lastSync >= 60 then |
-- Every minute: |
-- Synchronize the timer with WoW |
self:Sync() |
lastSync = 0 |
end |
|
if canUp and lastUpdate >= 10 then |
-- Every ten seconds: |
-- Increment the timer [and warn the player] |
self:Update() |
lastUpdate = 0 |
end |
end |
|
-- Incrementing timer manually (not fetching from WoW) |
-- Also calls warnings |
function NotBloated:Update() |
-- TODO: should store the runtime (system timestamp) on first update |
-- then here, do `CurrentTime - LastTime` to get time difference |
-- without messing up on slow systems/minimizing/zoning etc |
|
-- TODO: need to rewrite this (due to redundancy) |
|
local a, i |
|
for i = 1, #Times do |
a = Times[i] |
a.waitTime = a.waitTime - 10 |
|
if a.waitTime <= 0 then |
return |
end |
|
-- Perform warnings! |
|
for warning, done in pairs(warningsDone) do |
done = done[i] |
|
if warning ~= 'big' and (a.waitTime <= (warning + 1) * 60 and not done) then |
warningsDone[warning][i] = true |
doWarning = true |
|
if bigWarning[i] and not warningsDone.big[i] and bigWarning[i] == warning then |
-- big warning will only be performed if a normal warning |
-- is also set to this time |
|
doBigWarning = i |
warningsDone.big[i] = true |
end |
end |
end |
|
--doWarning = true |
--doBigWarning = true |
|
if doWarning then |
self:PrintTime(i) |
doWarning = false |
end |
end |
end |
|
-- Synchronizes the timer with WoW (every minute) |
function NotBloated:Sync() |
local a, i |
|
for i = 1, #Times do |
a = Times[i] |
|
a['lastTime'] = a.waitTime or 0 |
a['newTime'] = select(5, GetWorldPVPAreaInfo(i)) |
|
a['oldInProgress'] = a.inProgress |
a['inProgress'] = select(3, GetWorldPVPAreaInfo(i)) |
end |
|
for i = 1, #Times do |
a = Times[i] |
|
if not a.waitTime then |
-- upon logging in |
a['waitTime'] = a.newTime |
end |
|
if a.newTime > 0 or a.inProgress then |
-- time was fetched successfully, i can trust newTime |
a['invalid'] = false |
a['waitTime'] = a.newTime |
elseif a.newTime <= 0 and (not a.inProgress) then |
-- as of 4.0.1, this happens in instances |
-- even though it still knows if that battle has started? |
if debug and not a.invalid then |
print('you have zoned into an area where the waitTime for ' .. a.n .. ' cannot be fetched') |
end |
|
a['invalid'] = true |
end |
|
if not a.inProgress and a.oldInProgress then |
-- the battle has ended since the last update |
self:ResetWarnings() |
print('The battle for ' .. a.n .. ' has ended.') |
|
a.oldInProgress = false |
end |
end |
|
--if debug then |
_G['NBTEST'] = Times |
--end |
end |
|
-- Prints the time remainng/status of the battle |
function NotBloated:PrintTime(index) |
local a, seconds, minutes, hours, warnText |
|
a = Times[index] |
|
if a.waitTime <= 0 and a.invalid then |
-- time has never been successfully fetched |
print('Time remainng for ' .. a.n .. ' could not be fetched.') |
return |
end |
|
if a.inProgress then |
print('The battle for ' .. a.n .. ' is currently in progress!') |
return |
end |
|
seconds = a.waitTime % 60 |
minutes = floor(a.waitTime / 60) % 60 |
hours = floor(a.waitTime / 60 / 60) |
|
if minutes <= 1 and hours == 0 then |
warnText = 'The battle for ' .. a.n .. ' is about to begin!' |
print(warnText) |
|
self:BigWarning(warnText) |
|
return |
elseif minutes == 0 and hours > 0 then |
if hours ~= 1 then |
warnText = hours .. ' hours' |
else |
warnText = hours .. ' hour' |
end |
elseif hours == 0 and minutes > 1 then |
warnText = minutes .. ' minutes' |
else |
-- cop-out |
warnText = hours .. 'h ' .. minutes .. 'm' |
end |
|
self:BigWarning(warnText, true) |
|
print(warnText .. ' to ' .. a.n) |
return true |
end |
|
function NotBloated:BigWarning(text, time) |
if not doBigWarning or not text then return end |
|
local a = Times[doBigWarning] |
|
if time then |
text = "The battle for " .. a.n .. " begins in " .. text .. "!" |
end |
|
RaidNotice_AddMessage(RaidBossEmoteFrame, text, ChatTypeInfo["RAID_BOSS_EMOTE"]) |
PlaySound("RaidBossEmoteWarning") |
|
doBigWarning = false |
end |
|
-- I think this resets warnings or something |
function NotBloated:ResetWarnings() |
for warning,_ in pairs(warningsDone) do |
warningsDone[warning] = { false, false } |
end |
end |
|
--- Slash commands --- |
|
SlashCmdList["NOTBLOATED"] = function(arg) |
if arg == 'debug on' then |
print('debug on') |
debug = true |
elseif arg == 'debug off' then |
print('debug off') |
debug = false |
else |
for i = 1, #Times do |
NotBloated:PrintTime(i) |
end |
end |
end |
|
SLASH_NOTBLOATED1 = '/nb' |
|
--- Finishing up --- |
|
NotBloated:SetScript('OnUpdate', NotBloated.OnUpdate) |
NotBloated:SetScript('OnEvent', NotBloated.OnEvent) |
|
NotBloated:RegisterEvent('ADDON_LOADED') |