Repository navigation
Expand file tree
/
Copy pathcore.lua
More file actions
216 lines (186 loc) · 6.47 KB
/
Copy pathcore.lua
File metadata and controls
216 lines (186 loc) · 6.47 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
-- LDB-Broker
-------------
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local AceConfig = LibStub("AceConfig-3.0")
local AceConfigReg = LibStub("AceConfigRegistry-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("RBPBroker")
local UPDATEPERIOD, elapsed = 0.5, 0
local RBPSPELL = 125439
local dataobj = ldb:NewDataObject(L['Revive Battle Pets'], { type = "data source", text = L['Revive Battle Pets'] })
local f = CreateFrame("frame")
RBPBroker = LibStub("AceAddon-3.0"):NewAddon("RBP-Broker", "AceConsole-3.0")
local options = {
name = "RBP-Broker",
handler = RBPBroker,
type = 'group',
args = {
main = {
type = 'group',
name = L['Main'],
args = {
cooldown = {
type = 'toggle',
name = L['Show Cooldown'],
desc = L['Show cooldown time for Revive Battle Pets spell in bar'],
set = function(info, val) RBPBroker.config.profile.cooldown = val end,
get = function(info) return RBPBroker.config.profile.cooldown end
},
notifyEnd = {
type ='select',
name = L['Notify Availability'],
desc = L['Notify the player when cooldown time finishes'],
values = {
n0 = L['None'],
n1 = L['With Level Up Sound'],
n2 = L['In Chat'],
n3 = L['Both']
},
set = function(info, val) RBPBroker.config.profile.notifyEnd = val end,
get = function(info) return RBPBroker.config.profile.notifyEnd end
},
currentStatus = {
type = 'group',
inline = true,
name = L['Report Current Status'],
args = {
battleStart = {
type = 'toggle',
name = L['At Battle Start'],
desc = L['Notify current status in chat after battle start animation finishes'],
set = function(info, val) RBPBroker.config.profile.battleStart = val end,
get = function(info) return RBPBroker.config.profile.battleStart end
},
battleEnd = {
type = 'toggle',
name = L['At Battle End'],
desc = L['Notify current status in chat on returning to normal game'],
set = function(info, val) RBPBroker.config.profile.battleEnd = val end,
get = function(info) return RBPBroker.config.profile.battleEnd end
}
}
}
}
}
}
}
local defaultOptions = {
profile = {
cooldown = true,
notifyEnd = 'n0',
battleStart = false,
battleEnd = false
}
}
function RBPBroker:OnEnable()
local brokerOptions = AceConfigReg:GetOptionsTable("Broker", "dialog", "LibDataBroker-1.1")
if not brokerOptions then
brokerOptions = {
type = 'group',
name = 'Broker',
args = {}
}
AceConfigReg:RegisterOptionsTable('Broker', brokerOptions)
LibStub('AceConfigDialog-3.0'):AddToBlizOptions('Broker', 'Broker')
end
-- Get and store Revive Battle Pets icon and name
local name, rank, icon, cost, isFunnel, powerType, castTime, minRange, maxRange = GetSpellInfo(RBPSPELL)
dataobj.icon = icon
RBPBroker.RBPname = name
RBPBroker.RBPfullName = string.format("|T%s:14|t %s", icon, name)
options.name = name
options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.config)
AceConfigReg:RegisterOptionsTable(RBPBroker.name, options)
RBPBroker.menu = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(RBPBroker.name, RBPBroker.RBPname, "Broker")
-- Register event handlers and events
f:SetScript('OnEvent', function(self, event, ...)
RBPBroker[event](self, ...)
end)
f:RegisterEvent('PET_BATTLE_OPENING_DONE')
f:RegisterEvent('PET_BATTLE_CLOSE')
end
function RBPBroker:OnInitialize()
self.config = LibStub("AceDB-3.0"):New("RBPBrokerConfig", defaultOptions, true)
end
f:SetScript('OnUpdate', function(self, elap)
elapsed = elapsed + elap
if elapsed < UPDATEPERIOD then return end
elapsed = 0
local text = ''
local start, duration, enabled = GetSpellCooldown(RBPSPELL)
local cooldown = start + duration - GetTime()
if RBPBroker.config.profile.cooldown then
text = text .. RBPBroker:GetShortTime(cooldown)
end
if cooldown > 0 then
RBPBroker.inCooldown = true
else
if RBPBroker.inCooldown then -- finished
RBPBroker.inCooldown = false
if not (RBPBroker.config.profile.notifyEnd == 'n0') then
RBPBroker:NotifyEnd()
end
end
end
dataobj.text = text
end)
function RBPBroker:NotifyEnd()
if (RBPBroker.config.profile.notifyEnd == 'n1') or (RBPBroker.config.profile.notifyEnd == 'n3') then -- sound or both
PlaySound("LEVELUP")
end
if (RBPBroker.config.profile.notifyEnd == 'n2') or (RBPBroker.config.profile.notifyEnd == 'n3') then -- chat or both
RBPBroker:Printf(L['%s is ready'], RBPBroker.RBPfullName)
end
end
function RBPBroker:GetShortTime(seconds)
if seconds > 0 then
local min = math.floor(seconds / 60)
local sec = seconds % 60
return string.format('|cFFFFFFFF%d:%02d|r', min, sec)
else
return string.format('|cFF00FF00%s|r', L['Ready'])
end
end
function dataobj:OnTooltipShow()
self:AddLine(RBPBroker.RBPname)
self:AddLine(L['Left Click to open Pet Journal'])
self:AddLine(L['Right Click for options'])
end
function dataobj:OnClick(button)
if (button == "LeftButton") then
ToggleCollectionsJournal(2)
elseif (button == "RightButton") then
InterfaceOptionsFrame_OpenToCategory(RBPBroker.menu)
end
end
function dataobj:OnEnter()
GameTooltip:SetOwner(self, "ANCHOR_NONE")
GameTooltip:SetPoint("TOPLEFT", self, "BOTTOMLEFT")
GameTooltip:ClearLines()
dataobj.OnTooltipShow(GameTooltip)
GameTooltip:Show()
end
function dataobj:OnLeave()
GameTooltip:Hide()
end
function RBPBroker.PET_BATTLE_OPENING_DONE(...)
if RBPBroker.config.profile.battleStart then
RBPBroker:NotifyCurrentStatus()
end
end
function RBPBroker.PET_BATTLE_CLOSE(...)
-- Event fires twice. The first time, [petbattle] macro conditional
-- evalueates to true, the second to false
local result, target = SecureCmdOptionParse("[petbattle] In;Out")
if RBPBroker.config.profile.battleEnd and result == "Out" then
RBPBroker:NotifyCurrentStatus()
end
end
function RBPBroker:NotifyCurrentStatus()
local start, duration, enabled = GetSpellCooldown(RBPSPELL)
local cooldown = start + duration - GetTime()
if cooldown >= 1 then
RBPBroker:Printf(L['%s ready in %s'], RBPBroker.RBPfullName, SecondsToTime(cooldown))
else
RBPBroker:Printf(L['%s is ready'], RBPBroker.RBPfullName)
end
end