2011-08-30 20:29:41 -04:00
|
|
|
ChoreTracker = LibStub('AceAddon-3.0'):NewAddon('ChoreTracker', 'AceConsole-3.0', 'AceEvent-3.0')
|
2011-08-20 07:41:29 -04:00
|
|
|
local core = ChoreTracker
|
2011-08-29 18:51:14 -04:00
|
|
|
local LibQTip
|
2011-09-16 16:00:16 -04:00
|
|
|
local db
|
2011-08-20 07:41:29 -04:00
|
|
|
|
2011-08-21 10:59:28 -04:00
|
|
|
local trackedInstances = {
|
2011-08-25 03:50:22 -04:00
|
|
|
['Baradin Hold'] = 'BH',
|
|
|
|
['Firelands'] = 'FL',
|
2011-08-31 13:01:25 -04:00
|
|
|
['The Bastion of Twilight'] = 'BoT',
|
|
|
|
['Blackwing Descent'] = 'BWD',
|
|
|
|
['Throne of the Four Winds'] = '4W',
|
2011-08-21 10:59:28 -04:00
|
|
|
}
|
|
|
|
|
2011-08-20 07:41:29 -04:00
|
|
|
local defaults = {
|
2011-09-16 16:00:16 -04:00
|
|
|
global = {},
|
|
|
|
profile = {
|
|
|
|
instances = {},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
local options_setter = function(info, v) local t=core.db.profile for k=1,#info-1 do t=t[info[k]] end t[info[#info]]=v end
|
|
|
|
local options_getter = function(info) local t=core.db.profile for k=1,#info-1 do t=t[info[k]] end return t[info[#info]] end
|
|
|
|
local options = {
|
|
|
|
name = 'ChoreTracker',
|
|
|
|
type = 'group',
|
|
|
|
set = options_setter,
|
|
|
|
get = options_getter,
|
|
|
|
args = {
|
|
|
|
enabled = {
|
|
|
|
name = 'Toggle Instances',
|
|
|
|
type = 'group',
|
|
|
|
order = 10,
|
|
|
|
args = {},
|
|
|
|
}
|
|
|
|
}
|
2011-08-20 07:41:29 -04:00
|
|
|
}
|
|
|
|
|
2011-08-25 04:38:35 -04:00
|
|
|
local classColors = {}
|
|
|
|
local flagColors = {}
|
|
|
|
|
2011-09-01 03:16:53 -04:00
|
|
|
function core:OnInitialize()
|
|
|
|
--prepare the database if necessary
|
2011-08-30 20:29:41 -04:00
|
|
|
self.db = LibStub('AceDB-3.0'):New('ChoreTrackerDB', defaults, 'Default')
|
2011-08-25 03:50:22 -04:00
|
|
|
|
2011-09-01 03:16:53 -04:00
|
|
|
local level = UnitLevel('player')
|
|
|
|
local realm = GetRealmName()
|
|
|
|
local name = UnitName('player')
|
|
|
|
if self.db.global[realm] == nil then
|
|
|
|
self.db.global[realm] = {}
|
2011-08-25 03:50:22 -04:00
|
|
|
end
|
2011-09-01 03:16:53 -04:00
|
|
|
|
|
|
|
if self.db.global[realm][name] == nil and level == 85 then
|
|
|
|
self.db.global[realm][name] = {}
|
2011-08-31 02:17:58 -04:00
|
|
|
|
2011-09-01 03:16:53 -04:00
|
|
|
local class = UnitClass('player')
|
|
|
|
class = class:lower()
|
|
|
|
if class == 'deathknight' then
|
|
|
|
class = 'death knight'
|
2011-08-25 04:38:35 -04:00
|
|
|
end
|
2011-08-25 03:50:22 -04:00
|
|
|
|
2011-09-01 03:16:53 -04:00
|
|
|
self.db.global[realm][name].class = class
|
|
|
|
self.db.global[realm][name].valorPoints = {
|
|
|
|
valorPoints = 0,
|
|
|
|
resetTime = 0,
|
|
|
|
}
|
|
|
|
self.db.global[realm][name].lockouts = {}
|
2011-08-25 03:50:22 -04:00
|
|
|
end
|
2011-09-16 16:00:16 -04:00
|
|
|
|
|
|
|
-- Generate our options and add them to Blizzard Interface
|
|
|
|
LibStub('AceConfigRegistry-3.0'):RegisterOptionsTable('ChoreTracker', options)
|
|
|
|
local ACD = LibStub('AceConfigDialog-3.0')
|
|
|
|
ACD:AddToBlizOptions('ChoreTracker', 'ChoreTracker')
|
|
|
|
|
|
|
|
LoadAddOn('LibQTip-1.0')
|
2011-08-25 03:50:22 -04:00
|
|
|
end
|
|
|
|
|
2011-09-01 03:16:53 -04:00
|
|
|
function core:OnEnable()
|
|
|
|
LibQTip = LibStub('LibQTip-1.0')
|
2011-08-25 03:50:22 -04:00
|
|
|
|
2011-09-01 03:16:53 -04:00
|
|
|
self:RegisterChatCommand('ct', 'ViewChores');
|
2011-08-25 03:50:22 -04:00
|
|
|
|
2011-09-01 03:16:53 -04:00
|
|
|
local level = UnitLevel('player')
|
|
|
|
if level == 85 then
|
|
|
|
self:RegisterEvent('UPDATE_INSTANCE_INFO', 'UpdateChores')
|
|
|
|
self:RegisterEvent('CALENDAR_UPDATE_EVENT_LIST', 'UpdateChores')
|
2011-09-06 15:54:46 -04:00
|
|
|
self:RegisterEvent('CHAT_MSG_CURRENCY', 'UpdateChores')
|
|
|
|
self:RegisterEvent('PLAYER_LEAVING_WORLD', 'UpdateChores')
|
|
|
|
|
2011-09-01 03:16:53 -04:00
|
|
|
end
|
|
|
|
LoadAddOn("Blizzard_Calendar")
|
2011-08-25 03:50:22 -04:00
|
|
|
|
2011-09-06 15:54:46 -04:00
|
|
|
|
|
|
|
|
2011-09-01 03:16:53 -04:00
|
|
|
core:CreateChoreFrame()
|
2011-08-25 03:50:22 -04:00
|
|
|
|
2011-08-25 04:38:35 -04:00
|
|
|
for class,color in pairs(RAID_CLASS_COLORS) do
|
|
|
|
class = class:lower()
|
|
|
|
if class == 'deathknight' then
|
|
|
|
class = 'death knight'
|
|
|
|
end
|
|
|
|
|
2011-08-29 01:17:37 -04:00
|
|
|
classColors[class] = CreateFont('ClassFont' .. class)
|
|
|
|
classColors[class]:CopyFontObject(GameTooltipText)
|
2011-08-30 20:29:41 -04:00
|
|
|
classColors[class]:SetTextColor(color.r, color.g, color.b)
|
2011-08-25 04:38:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
flagColors['green'] = CreateFont('FlagFontGreen')
|
|
|
|
flagColors['green']:CopyFontObject(GameTooltipText)
|
2011-08-30 20:29:41 -04:00
|
|
|
flagColors['green']:SetTextColor(0, 255, 0)
|
2011-08-25 04:38:35 -04:00
|
|
|
|
|
|
|
flagColors['red'] = CreateFont('FlagFontRed')
|
|
|
|
flagColors['red']:CopyFontObject(GameTooltipText)
|
2011-08-30 20:29:41 -04:00
|
|
|
flagColors['red']:SetTextColor(255, 0, 0)
|
2011-09-01 03:16:53 -04:00
|
|
|
|
|
|
|
--reset data if necessary
|
|
|
|
core:ResetInstances()
|
|
|
|
core:ResetValorPoints()
|
2011-08-20 07:41:29 -04:00
|
|
|
end
|
|
|
|
|
2011-08-21 14:26:49 -04:00
|
|
|
function core:ViewChores()
|
2011-08-25 03:50:22 -04:00
|
|
|
|
2011-08-21 14:26:49 -04:00
|
|
|
end
|
|
|
|
|
2011-08-21 14:10:05 -04:00
|
|
|
function core:UpdateChores()
|
2011-08-25 02:02:50 -04:00
|
|
|
--reset data if necessary
|
|
|
|
core:ResetInstances()
|
|
|
|
core:ResetValorPoints()
|
2011-09-01 03:16:53 -04:00
|
|
|
|
|
|
|
local realm = GetRealmName()
|
|
|
|
local name = UnitName('player')
|
2011-08-25 02:02:50 -04:00
|
|
|
|
2011-09-01 03:16:53 -04:00
|
|
|
local vpReset = core:GetNextVPReset()
|
2011-09-06 12:23:46 -04:00
|
|
|
local _,_,_,earnedThisWeek = GetCurrencyInfo(396)
|
|
|
|
|
2011-09-01 03:16:53 -04:00
|
|
|
--store Valor Points
|
|
|
|
if vpReset ~= nil then
|
|
|
|
self.db.global[realm][name].valorPoints = {}
|
|
|
|
self.db.global[realm][name].valorPoints.points = earnedThisWeek
|
|
|
|
self.db.global[realm][name].valorPoints.resetTime = vpReset
|
|
|
|
end
|
2011-08-21 11:01:32 -04:00
|
|
|
|
2011-09-01 03:16:53 -04:00
|
|
|
--store Saved Instances
|
|
|
|
local savedInstances = GetNumSavedInstances()
|
|
|
|
for i = 1, savedInstances do
|
|
|
|
local instanceName, _, instanceReset, _, _, _, _, _, _, _, _, defeatedBosses = GetSavedInstanceInfo(i)
|
|
|
|
|
|
|
|
if trackedInstances[instanceName] ~= nil then
|
|
|
|
if instanceReset > 0 then
|
|
|
|
self.db.global[realm][name].lockouts[instanceName] = {}
|
|
|
|
self.db.global[realm][name].lockouts[instanceName].defeatedBosses = defeatedBosses
|
|
|
|
self.db.global[realm][name].lockouts[instanceName].resetTime = time() + instanceReset
|
|
|
|
else
|
|
|
|
self.db.global[realm][name].lockouts[instanceName] = nil
|
2011-08-21 10:59:28 -04:00
|
|
|
end
|
|
|
|
end
|
2011-08-21 00:03:50 -04:00
|
|
|
end
|
2011-08-23 04:27:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
function core:ResetInstances()
|
2011-09-01 03:16:53 -04:00
|
|
|
for realm,realmTable in pairs(self.db.global) do
|
|
|
|
for name in pairs(realmTable) do
|
|
|
|
for instance,instanceTable in pairs(self.db.global[realm][name].lockouts) do
|
|
|
|
if instanceTable.resetTime < time() then
|
|
|
|
self.db.global[realm][name].lockouts[instance] = nil
|
|
|
|
end
|
2011-08-23 04:27:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function core:ResetValorPoints()
|
2011-09-01 03:16:53 -04:00
|
|
|
for realm,realmTable in pairs(self.db.global) do
|
|
|
|
for name in pairs(realmTable) do
|
|
|
|
if self.db.global[realm][name].valorPoints.resetTime < time() then
|
|
|
|
self.db.global[realm][name].valorPoints = {
|
|
|
|
valorPoints = 0,
|
|
|
|
resetTime = 0,
|
|
|
|
}
|
2011-08-31 02:54:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-08-30 20:29:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
function core:GetNextVPReset()
|
|
|
|
--prepare calendar
|
|
|
|
local currentCalendarSetting = GetCVar('calendarShowResets') -- get current value and store
|
2011-08-31 03:30:12 -04:00
|
|
|
SetCVar('calendarShowResets', 1) -- set it to what we want
|
|
|
|
OpenCalendar()
|
2011-08-30 20:29:41 -04:00
|
|
|
|
|
|
|
--figure out what time the server resets daily information
|
|
|
|
local questReset = GetQuestResetTime()
|
2011-08-31 02:17:58 -04:00
|
|
|
local resetTime = date('*t', time() + questReset)
|
2011-08-30 20:29:41 -04:00
|
|
|
|
|
|
|
--figure out reset day using next BH lockout
|
|
|
|
local _, month, day, year = CalendarGetDate()
|
|
|
|
|
|
|
|
local monthOffset = 0
|
|
|
|
local resetDate = nil
|
|
|
|
while resetDate == nil do
|
|
|
|
local todaysEvents = CalendarGetNumDayEvents(monthOffset, day)
|
|
|
|
|
|
|
|
for i = 1,todaysEvents do
|
|
|
|
if todaysEvents == 0 then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
|
|
|
|
local title,hour,minute = CalendarGetDayEvent(monthOffset, day, i)
|
|
|
|
|
2011-08-31 12:51:17 -04:00
|
|
|
if title == 'Baradin Hold' then
|
2011-08-30 20:29:41 -04:00
|
|
|
resetDate = { year = year, month = month + monthOffset, day = day }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
day = day + 1
|
|
|
|
if day > 31 then
|
|
|
|
if monthOffset == 1 then break end
|
|
|
|
day = 1
|
|
|
|
monthOffset = 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--return calendar
|
2011-09-01 04:07:22 -04:00
|
|
|
SetCVar('calendarShowResets', currentCalendarSetting)
|
2011-08-30 20:29:41 -04:00
|
|
|
|
|
|
|
--and combine for the reset timestamp
|
2011-08-31 03:30:12 -04:00
|
|
|
if(resetDate ~= nil) then
|
|
|
|
resetDate.hour = resetTime.hour
|
|
|
|
resetDate.min = resetTime.min
|
|
|
|
resetDate.sec = resetTime.sec
|
2011-08-31 11:20:09 -04:00
|
|
|
|
2011-08-31 03:30:12 -04:00
|
|
|
return time(resetDate)
|
2011-08-31 12:51:17 -04:00
|
|
|
else
|
|
|
|
return nil
|
2011-08-31 03:30:12 -04:00
|
|
|
end
|
2011-09-01 03:16:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
local function anchor_OnEnter(self)
|
|
|
|
self.db = LibStub('AceDB-3.0'):New('ChoreTrackerDB', defaults, 'Default')
|
|
|
|
local columnCount = 2
|
|
|
|
for instance,abbreviation in pairs(trackedInstances) do
|
|
|
|
columnCount = columnCount + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
self.tooltip = LibQTip:Acquire('ChoreTrackerTooltip', columnCount, 'LEFT', 'CENTER', 'RIGHT')
|
|
|
|
|
|
|
|
--create the tooltip header
|
|
|
|
self.tooltip:AddHeader('')
|
|
|
|
local valorPointColumn = self.tooltip:AddColumn('LEFT')
|
|
|
|
self.tooltip:SetCell(1, 1, '')
|
|
|
|
self.tooltip:SetCell(1, 2, 'VP')
|
|
|
|
local nextColumn = 3
|
|
|
|
for instance,abbreviation in pairs(trackedInstances) do
|
2011-09-01 03:41:08 -04:00
|
|
|
self.tooltip:SetCell(1, nextColumn, abbreviation, nil, 'CENTER')
|
2011-09-01 03:16:53 -04:00
|
|
|
nextColumn = nextColumn + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
for realm in pairs(self.db.global) do
|
|
|
|
for name in pairs(self.db.global[realm]) do
|
|
|
|
local characterLine = self.tooltip:AddLine('')
|
|
|
|
local class = self.db.global[realm][name].class
|
|
|
|
self.tooltip:SetCell(characterLine, 1, name, classColors[class], 'LEFT')
|
|
|
|
|
|
|
|
local valorPoints, valorPointColor
|
|
|
|
valorPoints = self.db.global[realm][name].valorPoints.points
|
2011-09-06 12:23:46 -04:00
|
|
|
if valorPoints == nil then
|
|
|
|
valorPoints = 0
|
|
|
|
end
|
2011-09-01 03:16:53 -04:00
|
|
|
if valorPoints == 980 then
|
|
|
|
valorPointColor = flagColors['red']
|
|
|
|
else
|
|
|
|
valorPointColor = flagColors['green']
|
|
|
|
end
|
2011-09-01 03:41:08 -04:00
|
|
|
self.tooltip:SetCell(characterLine, 2, valorPoints, valorPointColor, 'RIGHT')
|
2011-09-01 03:16:53 -04:00
|
|
|
|
|
|
|
local nextColumn = 3
|
|
|
|
for instance,abbreviation in pairs(trackedInstances) do
|
|
|
|
if self.db.global[realm][name].lockouts[instance] ~= nil then
|
|
|
|
local defeatedBosses = self.db.global[realm][name].lockouts[instance].defeatedBosses
|
2011-09-01 03:41:08 -04:00
|
|
|
self.tooltip:SetCell(characterLine, nextColumn, defeatedBosses, flagColors['red'], 'RIGHT')
|
2011-09-01 03:16:53 -04:00
|
|
|
else
|
2011-09-01 03:41:08 -04:00
|
|
|
self.tooltip:SetCell(characterLine, nextColumn, '0', flagColors['green'], 'RIGHT')
|
2011-09-01 03:16:53 -04:00
|
|
|
end
|
|
|
|
nextColumn = nextColumn + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
self.tooltip:SmartAnchorTo(self)
|
|
|
|
self.tooltip:Show()
|
|
|
|
end
|
|
|
|
|
|
|
|
local function anchor_OnLeave(self)
|
|
|
|
LibQTip:Release(self.tooltip)
|
|
|
|
self.tooltip = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function core:CreateChoreFrame()
|
|
|
|
local ChoresDisplay = CreateFrame('Frame', 'ChoreTrackerFrame', UIParent)
|
|
|
|
ChoresDisplay:SetPoint('TOPLEFT')
|
|
|
|
ChoresDisplay.background = ChoresDisplay:CreateTexture(nil, 'BACKGROUND')
|
|
|
|
ChoresDisplay.background:SetAllPoints(true)
|
2011-09-01 04:07:22 -04:00
|
|
|
ChoresDisplay.background:SetTexture('Interface\\AddOns\\ChoreTracker\\icon')
|
|
|
|
ChoresDisplay:SetHeight(32)
|
|
|
|
ChoresDisplay:SetWidth(32)
|
2011-09-01 03:16:53 -04:00
|
|
|
ChoresDisplay:Show()
|
|
|
|
|
|
|
|
ChoresDisplay:EnableMouse(true)
|
|
|
|
ChoresDisplay:SetMovable(true)
|
|
|
|
ChoresDisplay:RegisterForDrag('LeftButton')
|
|
|
|
|
|
|
|
ChoresDisplay:SetScript('OnDragStart', ChoresDisplay.StartMoving)
|
|
|
|
ChoresDisplay:SetScript('OnDragStop', ChoresDisplay.StopMovingOrSizing)
|
|
|
|
ChoresDisplay:SetScript('OnHide', ChoresDisplay.StopMovingOrSizing)
|
|
|
|
ChoresDisplay:SetScript('OnEnter', anchor_OnEnter)
|
|
|
|
ChoresDisplay:SetScript('OnLeave', anchor_OnLeave)
|
2011-08-20 07:41:29 -04:00
|
|
|
end
|