-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
executable file
·252 lines (217 loc) · 8.88 KB
/
main.lua
File metadata and controls
executable file
·252 lines (217 loc) · 8.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
--[[
Copyright Daniel D. Neilson, 2006
This file is part of DKPmon.
DKPmon is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DKPmon is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DKPmon; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
]]
DKPmon = AceLibrary("AceAddon-2.0"):new("AceConsole-2.0", "AceDB-2.0", "AceComm-2.0", "Metrognome-2.0", "AceEvent-2.0", "FuBarPlugin-2.0")
local L = AceLibrary("AceLocale-2.2"):new("DKPmon")
local tablet = AceLibrary("Tablet-2.0")
local DKPmonDBver = 2.0
DKPmon.DBDefaults = {
dbversion = DKPmonDBver, -- Structure version of the SavedVariables DB
password = "default", -- Password for points database broadcasting
disenchanter = "", -- Player name of the person to give items to be disenchanted to
bankname = "", -- Player name of the person to give items to for the guild bank
amLeader = false, -- true iff we're running DKPmon for this raid
alwayssync = true, -- true -> always send our points database on a sync request
DKP = {
dbversion = 1.0, -- What structure version of the points database
system = "FDKP", -- The sysID of the DKP system to use
checksum = nil, -- The checksum for the database data
db = {} -- The points database
},
Log = {
dbversion = 1.1, -- What structure version of the points database
active = false, -- whether logging's active
currentLog = nil, -- string; what log name we're logging to
autologging = false, -- boolean; whether to automatically start a log when entering a raid instance
logs = {} -- table of the logs
},
RaidRoster = {
list = {}, -- list of RaidRoster structs for all players in your current raid
left = {} -- list of RaidRoster structs for all players who have left your current raid.
},
PluginData = { -- Data that import/export modules wanted to save.
}
}
DKPmon.hasIcon = "Interface\\Addons\\DKPmon\\DKPmon_icon.tga"
DKPmon.cannotDetachTooltip = true
DKPmon.cannotHideText = false
function DKPmon:OnInitialize()
self.OnMenuRequest = self.Options.fubar
-- Set the console commands
self:RegisterChatCommand({L["/dkp"], L["/dkpmon"]}, self.Options.console)
-- Called when the addon is loaded
self:RegisterDB("DKPmonDB")
self:RegisterDefaults('realm', self.DBDefaults)
-- Ensure the database is up to date.
if self.db.realm.dbversion < DKPmonDBver then
-- Database is from a previous version of DKPmon
-- Need to migrate it over.
self:Print(L["Database version changed. Migrating to new format."])
-- Just wipe out the old database.
--self:TableDelete(self.db.realm)
self.db.realm = DBDefaults
end
-- Log format changed. Migrate old data to new data.
if self.db.realm.Log.dbversion < 1.1 then
self:Print(L["Log version changed. Migrating to new format."])
self.Logging:MigrateLog()
end
-- Calculate the checksum for the DKP database if there isn't one
if self.db.realm.DKP.checksum == nil then
self.PointsDB:CalculateChecksum()
end
-- Claim our message prefix from the Bidder stub hack
if BidderDKPStub ~= nil then
BidderDKPStub:DeregisterComm()
end
self:SetCommPrefix(self.Comm.DKPmonCommPrefix)
self:RegisterMetro("DKPmonCommDispatch", function() DKPmon.Comm:DispatchMessages() end)
self:ChangeMetroRate("DKPmonCommDispatch", 1.0/20) -- Call it 20 times per second
self:RegisterMetro("DKPmonClose", function() DKPmon.Looting:StartCloseBiddingTimer() end)
self:RegisterMetro("DKPmonUpdateLevelZeros", function() DKPmon.RaidRoster:UpdateLevelZeros() end)
self:ChangeMetroRate("DKPmonUpdateLevelZeros", 1.0)
self.Comm:RegisterCommand("L", self.ReceiveLeaderClaim, self)
self:RegisterMetro("DKPmonLeader", function() DKPmon:CheckLeader() end)
self.leadername = ""
--DKPmon:Print("Initialize System: "..DKPmon.db.realm.DKP.system)
--[[
-- Register the metronome
self:RegisterMetro("DKPmonBidderCheck", function() DKPmon:PrintNoBidderInstalledList() end)
]]
end
function DKPmon:OnEnable()
self.Comm:Enable() -- enable communications
--DKPmon:Print("Initializing DKP Types")
self.DKP:Initialize()
--DKPmon:Print("Initializing DKP Types Finished")
self.Logging:Initialize()
self.ImpExpModules:InitializeModules()
self.lastLeaderClaim = GetTime()
self:SetLeader(false)
self:ChangeMetroRate("DKPmonLeader", 17) -- Call every 17 seconds
self:StartMetro("DKPmonLeader")
self:RegisterEvent("LOOT_OPENED", function() DKPmon.Looting:OnLootEvent() end)
self:RegisterEvent("RAID_ROSTER_UPDATE",
function()
if IsInRaid() == false or GetNumGroupMembers() == 0 then
-- Turn off the log if one's going
local logtab = DKPmon.Logging:GetTable()
if logtab.active then DKPmon.Logging:StopLog() end
end
DKPmon.RaidRoster:UpdateRoster()
end)
-- Fires when entering an instance that saves when a boss is killed (ie: raid instance or heroic)
self:RegisterEvent("RAID_INSTANCE_WELCOME",
function()
local logtab = DKPmon.Logging:GetTable()
if IsInRaid == false or GetNumGroupMembers() == 0 then -- Heroic instance
return
end
if logtab.active then return end -- Logging already turned on.
if not logtab.autologging then return end
logtab.logname = arg1
StaticPopup_Show("DKPMON_CONFIRM_STARTLOG", logtab.logname)
end )
self.RaidRoster:BuildRoster()
end
function DKPmon:OnDisable()
-- Called when the addon is disabled.
--self:Print("Disabled")
end
--[[ AceDB-2.0 Methods ]]
function DKPmon:OnProfileDisable()
-- Called when the user changes profiles (before change)
end
function DKPmon:OnProfileEnable()
-- Called when the user changes profiles (after change)
end
--[[ Function for checking the whether the raid has a DKPmon leader set ]]
function DKPmon:SetLeader(val)
-- Never allowed to be leader if you're not in a raid
if IsInRaid() == false then self.db.realm.amLeader = false; return end
if (val and not self.db.realm.amLeader) then
DKPmon:Print(L["I'm now the DKP lead."])
end
self.db.realm.amLeader = val
if val then
self.Comm:SendToDKPmon("L")
self:SetIcon("Interface\\AddOns\\DKPmon\\DKPmon_leader.tga")
self:UpdateDisplay()
else
self:SetIcon("Interface\\AddOns\\DKPmon\\DKPmon_icon.tga")
self:UpdateDisplay()
end
end
function DKPmon:GetLeaderState()
return self.db.realm.amLeader
end
function DKPmon:CheckLeader()
if IsInRaid() == false then
-- Not in a raid, ignore.
return
end
if self:GetLeaderState() then
-- We're the leader, send a message that we're the leader to the raid.
self.Comm:SendToDKPmon("L")
else
-- We're not the leader. If it's been more than 45 seconds since we last had a DKPmon
-- claim leader, then claim leader for ourself.
local currTime = GetTime()
if (currTime - self.lastLeaderClaim) > 45.0 then
self:SetLeader(true)
end
end
end
function DKPmon:ReceiveLeaderClaim(sender)
--self:Print("Got claim leader from "..sender)
self.lastLeaderClaim = GetTime()
if sender ~= self.leadername then
self.leadername = sender
DKPmon:Print(L["DKP leader changed to "]..sender)
end
if sender ~= UnitName("player") then
self:SetLeader(false)
end
return true
end
--[[ FuBarPlugin-2.0 Methods ]]
--[[
Called when FuBar icon is left-clicked
Show Looting window if it's hidden, otherwise show points award window
]]
function DKPmon:OnClick()
if self.Looting:GetBidState() > 0 and not self.Looting.frame:IsVisible() then
self.Looting:Show()
else
self.Awarding:Show()
end
end
--[[
Called when FuBar icon is moused over and tooltip needs updating
]]
function DKPmon:OnTooltipUpdate()
local cat = tablet:AddCategory('columns',2)
cat:AddLine('text',L["DKP Leader:"],'text2',self.leadername)
local log = DKPmon.Logging:GetCurrentLog()
local text
if log then
text = log.raidkey
else
text = L["Disabled"]
end
cat:AddLine('text',L["Logging:"],'text2',text)
tablet:SetTitle(L["DKPmon"])
tablet:SetHint(L["Click to open Points Awarding window."])
end