-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcore.lua
More file actions
410 lines (352 loc) · 10.6 KB
/
core.lua
File metadata and controls
410 lines (352 loc) · 10.6 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
local A = FonzSummon
A.module 'fsm'
-- TRANSLATIONS
local L = AceLibrary("AceLocale-2.2"):new("FonzSummon")
-- LIBRARIES
local tablet = AceLibrary("Tablet-2.0")
-- GLOBAL IMPORTS
local tolower, toupper, strmatch = strlower, strupper, string.match
local LNONE = tolower(NONE)
local LDEFAULTS = tolower(DEFAULTS)
-- MODULES
local util = A.requires(
'util.string',
'util.chat'
)
local warlock = A.require 'fsm.warlock'
--------------------------------------------------------------------------------
-- SETTINGS
local defaults = {
enable = true,
received = true,
received_msg = L["Received summon. Thank you {summoner}"],
received_chan = L["GROUP"],
summoner = true,
summoner_msg = L["Click to summon {target} to {zone}. "
.."Do not move when you click. [{shards} shards left]"],
summoner_chan = L["GROUP"],
whisper = true,
whisper_msg = L["Summoning you to {zone}"],
}
local options = {
type = "group",
args = {
Enable = {
type = "toggle",
name = L["Enable messages"],
desc = L["Toggles whether to output messages"],
get = "isEnabled",
set = "toggleEnabled",
order = 10,
},
Received = {
type = "toggle",
name = L["Toggle received message"],
desc = L["Toggle received message"],
get = "isReceived",
set = "toggleReceived",
order = 35,
},
ReceivedMsg = {
type = "text",
name = L["Received message"],
desc = L["Sets the summon received message"],
get = "getReceivedMsg",
set = "setReceivedMsg",
usage = string.format(
L["|cffffff7f%s|r to reset or |cffffff7f%s|r to disable"],
DEFAULTS, NONE),
order = 40,
},
ReceivedChan = {
type = "text",
name = L["Received channel"],
desc = L["Chat channel: SAY, PARTY, RAID, GROUP, WHISPER "
.."or a channel number"],
get = "getReceivedChan",
set = "setReceivedChan",
usage = L["SAY, PARTY, RAID, GROUP, WHISPER, <channel number>"],
validate = function(text) local tu=toupper return
tu(text)==L["SAY"] or tu(text)==L["PARTY"]
or tu(text)==L["RAID"] or tu(text)==L["GROUP"]
or tu(text)==L["WHISPER"]
or strmatch(text, "^%d+$")
end,
order = 50,
},
}
}
-- ADDON METHODS
-- Settings control --
function A:isEnabled()
return self.db.profile.enable
end
function A:toggleEnabled()
self.db.profile.enable = not self.db.profile.enable
end
function A:isReceived()
return self.db.profile.received
end
function A:toggleReceived()
self.db.profile.received = not self.db.profile.received
end
function A:getReceivedMsg()
return self.db.profile.received_msg
end
function A:setReceivedMsg(msg)
local lmsg = tolower(msg)
if lmsg == LNONE then
self.db.profile.received_msg = nil
elseif lmsg == LDEFAULTS then
self.db.profile.received_msg = defaults["received_msg"]
else
self.db.profile.received_msg = msg
end
end
function A:getReceivedChan()
return self.db.profile.received_chan
end
function A:setReceivedChan(id)
self.db.profile.received_chan = tolower(id)
end
function A:isSummoner()
return self.db.profile.summoner
end
function A:toggleSummoner()
self.db.profile.summoner = not self.db.profile.summoner
end
function A:getSummonerMsg()
return self.db.profile.summoner_msg
end
function A:setSummonerMsg(msg)
local lmsg = tolower(msg)
if lmsg == LNONE then
self.db.profile.summoner_msg = nil
elseif lmsg == LDEFAULTS then
self.db.profile.summoner_msg = defaults["summoner_msg"]
else
self.db.profile.summoner_msg = msg
end
end
function A:getSummonerChan()
return self.db.profile.summoner_chan
end
function A:setSummonerChan(id)
self.db.profile.summoner_chan = tolower(id)
end
function A:isWhisper()
return self.db.profile.whisper
end
function A:toggleWhisper()
self.db.profile.whisper = not self.db.profile.whisper
end
function A:getWhisperMsg()
return self.db.profile.whisper_msg
end
function A:setWhisperMsg(msg)
local lmsg = tolower(msg)
if lmsg == LNONE then
self.db.profile.whisper_msg = nil
elseif lmsg == LDEFAULTS then
self.db.profile.whisper_msg = defaults["whisper_msg"]
else
self.db.profile.whisper_msg = msg
end
end
-- Events --
do
local summoner
function getSummoner()
return summoner
end
function A:CONFIRM_SUMMON(...)
local profile = self.db.profile
if not profile.enable then return end
if profile.received and profile.received_msg then
summoner = GetSummonConfirmSummoner() or ""
local msg = util.replace_vars{
profile.received_msg,
summoner = summoner
}
local channel = profile.received_chan
if toupper(channel) == L["WHISPER"] then
if summoner ~= "" then
util.whisperMessage(summoner, msg)
else
self:Print(L["Unable to whisper the summoner."])
end
else
util.chatMessage(msg, channel)
end
end
end
end
function A:SPELLCAST_START(...)
local profile = self.db.profile
if not profile.enable then return end
if arg1 == L["Ritual of Summoning"] then
if not A.timers then
A.timers = {}
A.timers.spell = {}
end
A.timers.spell["Ritual of Summoning"] = GetTime()
end
end
do
local target
function getSummoned()
return target
end
function A:SPELLCAST_CHANNEL_START(...)
local profile = self.db.profile
if not profile.enable then return end
-- arg1=duration.
-- duration of Ritual of Summoning is 600000 (10 min). Ignore anything less
if arg1 < 600000 then return end
if A.timers and A.timers.spell then
-- Ensure that this is the spell channel immediately following Ritual cast
local cast_time = A.timers.spell["Ritual of Summoning"]
if cast_time then
local elapsed = GetTime() - cast_time
-- Ritual of Summoning cast timer = 5s default
if elapsed < 6 then
target = UnitName("target")
local zone = GetRealZoneText()
local shards = warlock.getShardCount()
local msg
if profile.summoner and profile.summoner_msg then
msg = util.replace_vars{
profile.summoner_msg,
target = target,
zone = zone,
shards = shards
}
util.chatMessage(msg, profile.summoner_chan)
end
if profile.whisper and profile.whisper_msg then
msg = util.replace_vars{
profile.whisper_msg,
zone = zone,
shards = shards
}
util.whisperMessage(target, msg)
end
end
end
end
end
end
-- Loading --
function A:HookEvents()
-- Fires when a summons is offered to the player
self:RegisterEvent("CONFIRM_SUMMON")
if warlock.isSummoner() then
-- Fires when a unit begins casting a spell
self:RegisterEvent("SPELLCAST_START")
-- Fires when a unt starts channeling a spell
self:RegisterEvent("SPELLCAST_CHANNEL_START")
end
end
function A:OnEnable()
self:HookEvents()
-- Player check requires code that runs after PLAYER_LOGIN event.
-- This is why this code block is in the OnEnable() handler.
if warlock.isSummoner() then
-- Additional options for a summoner
options.args["Summoner"] = {
type = "toggle",
name = L["Toggle warlock chat message"],
desc = L["Toggle warlock chat message"],
get = "isSummoner",
set = "toggleSummoner",
order = 55,
}
options.args["SummonerMsg"] = {
type = "text",
name = L["Warlock summon message"],
desc = L["Sets the warlock summon message"],
get = "getSummonerMsg",
set = "setSummonerMsg",
usage = string.format(
L["|cffffff7f%s|r to reset or |cffffff7f%s|r to disable"],
DEFAULTS, NONE),
order = 60,
}
options.args["SummonerChan"] = {
type = "text",
name = L["Warlock channel"],
desc = L["Chat channel: SAY, PARTY, RAID, GROUP or a channel number"],
get = "getSummonerChan",
set = "setSummonerChan",
usage = L["SAY, PARTY, RAID, GROUP, <channel number>"],
validate = function(text) local tu=toupper return
tu(text)==L["SAY"] or tu(text)==L["PARTY"]
or tu(text)==L["RAID"] or tu(text)==L["GROUP"]
or strmatch(text, "^%d+$")
end,
order = 70,
}
options.args["Whisper"] = {
type = "toggle",
name = L["Toggle warlock whisper message"],
desc = L["Toggle warlock whisper message"],
get = "isWhisper",
set = "toggleWhisper",
order = 85,
}
options.args["WhisperMsg"] = {
type = "text",
name = L["Warlock whisper message"],
desc = L["Sets the warlock whisper message"],
get = "getWhisperMsg",
set = "setWhisperMsg",
usage = string.format(
L["|cffffff7f%s|r to reset or |cffffff7f%s|r to disable"],
DEFAULTS, NONE),
order = 90,
}
end
end
-- STARTUP
-- Command line --
A:RegisterChatCommand({L["SLASHCMD_SHORT"], L["SLASHCMD_LONG"]}, options)
A:RegisterDB("FonzSummonDB")
A:RegisterDefaults("profile", defaults)
-- Fubar --
-- Sensible Fubar defaults for an independent profile, minimap-enabled,
-- minimap-hideable, customized minimap tooltip addon if Fubar addon is not
-- available.
-- Inspired: @Roadblock, author of "Interruptor" addon
function A:OnTooltipUpdate()
local category = tablet:AddCategory(
"columns", 2,
"child_textR", 1,"child_textG", 1, "child_textB", 0,
"child_text2R", 1, "child_text2G", 1, "child_text2B", 1
)
local summoner = getSummoner()
summoner = summoner ~= "" and summoner or "-"
category:AddLine(
"text", L["Last Summon By:"],
"text2", summoner
)
if warlock.isSummoner() then
local summoned = getSummoned() or "-"
category:AddLine(
"text", L["Last Summoned:"],
"text2", summoned
)
end
tablet:SetHint(L["|cffFFA500Right-Click:|r Options"])
end
A.hasIcon = A.addon_path .. [[\img\icon]]
A.defaultMinimapPosition = 260
A.defaultPosition = "CENTER"
A.cannotDetachTooltip = true
A.tooltipHiddenWhenEmpty = false
A.hideWithoutStandby = true
A.independentProfile = true
A.OnMenuRequest = options
if not FuBar then
A.OnMenuRequest.args.hide.guiName = L["Hide minimap icon"]
A.OnMenuRequest.args.hide.desc = L["Hide minimap icon"]
end