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-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-21 10:59:28 -04:00
|
|
|
}
|
|
|
|
|
2011-08-20 07:41:29 -04:00
|
|
|
local defaults = {
|
2011-08-25 02:02:50 -04:00
|
|
|
global = {
|
2011-08-25 04:38:35 -04:00
|
|
|
classes = {},
|
2011-08-20 07:41:29 -04:00
|
|
|
valorPoints = {},
|
|
|
|
lockouts = {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-25 04:38:35 -04:00
|
|
|
local classColors = {}
|
|
|
|
local flagColors = {}
|
|
|
|
|
2011-08-25 03:50:22 -04:00
|
|
|
local function anchor_OnEnter(self)
|
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
|
|
|
local columnCount = 2
|
|
|
|
for instance,abbreviation in pairs(trackedInstances) do
|
|
|
|
columnCount = columnCount + 1
|
|
|
|
end
|
|
|
|
|
2011-08-30 20:29:41 -04:00
|
|
|
self.tooltip = LibQTip:Acquire('ChoreTrackerTooltip', columnCount, 'LEFT', 'CENTER', 'RIGHT')
|
2011-08-25 03:50:22 -04:00
|
|
|
|
|
|
|
--create the tooltip header
|
|
|
|
self.tooltip:AddHeader('')
|
|
|
|
local valorPointColumn = self.tooltip:AddColumn('LEFT')
|
2011-08-30 20:29:41 -04:00
|
|
|
self.tooltip:SetCell(1, 1, '')
|
|
|
|
self.tooltip:SetCell(1, 2, 'VP')
|
2011-08-25 03:50:22 -04:00
|
|
|
local nextColumn = 3
|
|
|
|
for instance,abbreviation in pairs(trackedInstances) do
|
2011-08-30 20:29:41 -04:00
|
|
|
self.tooltip:SetCell(1, nextColumn, abbreviation, nil, 'LEFT')
|
2011-08-25 03:50:22 -04:00
|
|
|
nextColumn = nextColumn + 1
|
|
|
|
end
|
|
|
|
--go through all stored raiders
|
|
|
|
for character,instancesTable in pairs(self.db.global.lockouts) do
|
|
|
|
local characterLine = self.tooltip:AddLine('')
|
2011-08-25 04:38:35 -04:00
|
|
|
|
|
|
|
local class = self.db.global.classes[character]
|
2011-08-30 20:29:41 -04:00
|
|
|
self.tooltip:SetCell(characterLine, 1, character, classColors[class], 'LEFT')
|
2011-08-25 04:38:35 -04:00
|
|
|
|
2011-08-31 02:17:58 -04:00
|
|
|
local valorPointColor,valorPoints
|
|
|
|
if self.db.global.valorPoints[character] == nil then
|
|
|
|
valorPoints = 0
|
|
|
|
else
|
|
|
|
valorPoints = self.db.global.valorPoints[character].points
|
|
|
|
end
|
|
|
|
|
|
|
|
if valorPoints == 980 then
|
2011-08-25 04:38:35 -04:00
|
|
|
valorPointColor = flagColors['red']
|
2011-08-29 01:17:37 -04:00
|
|
|
else
|
|
|
|
valorPointColor = flagColors['green']
|
2011-08-25 04:38:35 -04:00
|
|
|
end
|
2011-08-31 02:17:58 -04:00
|
|
|
self.tooltip:SetCell(characterLine, 2, valorPoints, valorPointColor, 'LEFT')
|
2011-08-25 03:50:22 -04:00
|
|
|
|
|
|
|
local nextColumn = 3
|
|
|
|
for instance,abbreviation in pairs(trackedInstances) do
|
|
|
|
if self.db.global.lockouts[character][instance] ~= nil then
|
2011-08-30 20:29:41 -04:00
|
|
|
self.tooltip:SetCell(characterLine, nextColumn, self.db.global.lockouts[character][instance].defeatedBosses, flagColors['red'], 'LEFT')
|
2011-08-25 03:50:22 -04:00
|
|
|
else
|
2011-08-30 20:29:41 -04:00
|
|
|
self.tooltip:SetCell(characterLine, nextColumn, '0', flagColors['green'], 'LEFT')
|
2011-08-25 03:50:22 -04:00
|
|
|
end
|
|
|
|
nextColumn = nextColumn + 1
|
|
|
|
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:OnInitialize()
|
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-08-30 20:29:41 -04:00
|
|
|
local ChoresDisplay = CreateFrame('Frame', 'ChoreTrackerFrame', UIParent)
|
|
|
|
ChoresDisplay:SetPoint('TOPLEFT')
|
|
|
|
ChoresDisplay.background = ChoresDisplay:CreateTexture(nil, 'BACKGROUND')
|
2011-08-25 03:50:22 -04:00
|
|
|
ChoresDisplay.background:SetAllPoints(true)
|
2011-08-30 20:29:41 -04:00
|
|
|
ChoresDisplay.background:SetTexture(1, 0.5, 0, 0.5)
|
2011-08-25 03:50:22 -04:00
|
|
|
ChoresDisplay:SetHeight(50)
|
|
|
|
ChoresDisplay:SetWidth(50)
|
|
|
|
ChoresDisplay:Show()
|
|
|
|
|
2011-08-25 04:38:35 -04:00
|
|
|
ChoresDisplay:EnableMouse(true)
|
|
|
|
ChoresDisplay:SetMovable(true)
|
|
|
|
ChoresDisplay:RegisterForDrag('LeftButton')
|
|
|
|
|
2011-08-30 20:29:41 -04:00
|
|
|
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-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-08-20 07:41:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
function core:OnEnable()
|
2011-08-29 18:51:14 -04:00
|
|
|
LibQTip = LibStub('LibQTip-1.0')
|
2011-08-21 12:23:18 -04:00
|
|
|
local name = UnitName('player')
|
|
|
|
|
2011-08-23 04:27:44 -04:00
|
|
|
if self.db.global.lockouts[name] == nil then
|
|
|
|
self.db.global.lockouts[name] = {}
|
2011-08-21 12:23:18 -04:00
|
|
|
end
|
2011-08-31 02:17:58 -04:00
|
|
|
if self.db.global.valorPoints[name] == nil then
|
|
|
|
self.db.global.valorPoints[name] = {}
|
|
|
|
end
|
2011-08-21 12:23:18 -04:00
|
|
|
|
2011-08-30 20:29:41 -04:00
|
|
|
self:RegisterChatCommand('ct', 'ViewChores');
|
|
|
|
self:RegisterEvent('UPDATE_INSTANCE_INFO', 'UpdateChores')
|
2011-08-31 11:20:09 -04:00
|
|
|
self:RegisterEvent('CALENDAR_UPDATE_EVENT_LIST', 'UpdateChores')
|
|
|
|
LoadAddOn("Blizzard_Calendar")
|
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-21 00:03:50 -04:00
|
|
|
local level = UnitLevel('player')
|
2011-08-20 07:41:29 -04:00
|
|
|
|
2011-08-25 02:02:50 -04:00
|
|
|
--reset data if necessary
|
|
|
|
core:ResetInstances()
|
|
|
|
core:ResetValorPoints()
|
|
|
|
|
2011-08-21 00:03:50 -04:00
|
|
|
if(level == 85) then
|
2011-08-21 14:10:05 -04:00
|
|
|
local _,_,_,earnedThisWeek = GetCurrencyInfo(396)
|
|
|
|
local name = UnitName('player')
|
|
|
|
|
2011-08-25 04:38:35 -04:00
|
|
|
--set class if not already set
|
|
|
|
local class = UnitClass('player')
|
|
|
|
self.db.global.classes[name] = class:lower()
|
2011-08-31 02:17:58 -04:00
|
|
|
local vpReset = core:GetNextVPReset()
|
2011-08-25 04:38:35 -04:00
|
|
|
|
2011-08-21 12:48:18 -04:00
|
|
|
--store Valor Points
|
2011-08-31 12:51:17 -04:00
|
|
|
if vpReset ~= nil then
|
|
|
|
self.db.global.valorPoints[name] = {}
|
|
|
|
self.db.global.valorPoints[name].points = earnedThisWeek
|
|
|
|
self.db.global.valorPoints[name].resetTime = vpReset
|
|
|
|
end
|
2011-08-21 11:01:32 -04:00
|
|
|
|
2011-08-21 12:48:18 -04:00
|
|
|
--store Saved Instances
|
2011-08-21 11:01:32 -04:00
|
|
|
local savedInstances = GetNumSavedInstances()
|
2011-08-21 14:10:05 -04:00
|
|
|
for i = 1, savedInstances do
|
2011-08-30 20:29:41 -04:00
|
|
|
local instanceName, _, instanceReset, _, _, _, _, _, _, _, _, defeatedBosses = GetSavedInstanceInfo(i)
|
2011-08-21 10:59:28 -04:00
|
|
|
|
2011-08-25 03:50:22 -04:00
|
|
|
if trackedInstances[instanceName] ~= nil then
|
2011-08-21 10:59:28 -04:00
|
|
|
if instanceReset > 0 then
|
2011-08-23 04:27:44 -04:00
|
|
|
self.db.global.lockouts[name][instanceName] = {}
|
|
|
|
self.db.global.lockouts[name][instanceName].defeatedBosses = defeatedBosses
|
|
|
|
self.db.global.lockouts[name][instanceName].resetTime = time() + instanceReset
|
2011-08-21 10:59:28 -04:00
|
|
|
else
|
2011-08-23 04:27:44 -04:00
|
|
|
self.db.global.lockouts[name][instanceName] = nil
|
2011-08-21 10:59:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-08-21 00:03:50 -04:00
|
|
|
end
|
2011-08-23 04:27:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
function core:ResetInstances()
|
|
|
|
for k,v in pairs(self.db.global.lockouts) do
|
|
|
|
for x,y in pairs(self.db.global.lockouts[k]) do
|
|
|
|
if y.resetTime < time() then
|
2011-08-25 02:02:50 -04:00
|
|
|
self.db.global.lockouts[k][x] = nil
|
2011-08-23 04:27:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function core:ResetValorPoints()
|
2011-08-31 02:54:50 -04:00
|
|
|
for k,v in pairs(self.db.global.valorPoints) do
|
|
|
|
if v.resetTime ~= nil then
|
|
|
|
if v.resetTime < time() then
|
|
|
|
self.db.global.valorPoints[k] = nil
|
|
|
|
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()
|
|
|
|
|
2011-08-31 03:30:12 -04:00
|
|
|
--calendar not yet loaded? Cannot find events when first fires of this;
|
|
|
|
--"arbitrarily" fires at unknown time.
|
2011-08-30 20:29:41 -04:00
|
|
|
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
|
|
|
|
SetCVar('calendarShowResets',currentCalendarSetting)
|
|
|
|
|
|
|
|
--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-08-20 07:41:29 -04:00
|
|
|
end
|