forked from isitLoVe/RaidSummon
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRaidSummon.lua
More file actions
417 lines (393 loc) · 14.4 KB
/
RaidSummon.lua
File metadata and controls
417 lines (393 loc) · 14.4 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
411
412
413
414
415
416
417
local RaidSummonOptions_DefaultSettings = {
whisper = true,
zone = true,
shards = true,
debug = false
}
local function RaidSummon_Initialize()
if not RaidSummonOptions then
RaidSummonOptions = {}
end
for i in RaidSummonOptions_DefaultSettings do
if (not RaidSummonOptions[i]) then
RaidSummonOptions[i] = RaidSummonOptions_DefaultSettings[i]
end
end
end
function RaidSummon_EventFrame_OnLoad()
DEFAULT_CHAT_FRAME:AddMessage(string.format("RaidSummon version %s by %s. Type /rs or /raidsummon to show.", GetAddOnMetadata("RaidSummon", "Version"), GetAddOnMetadata("RaidSummon", "Author")))
this:RegisterEvent("VARIABLES_LOADED")
this:RegisterEvent("CHAT_MSG_ADDON")
this:RegisterEvent("CHAT_MSG_RAID")
this:RegisterEvent("CHAT_MSG_RAID_LEADER")
this:RegisterEvent("CHAT_MSG_SAY")
this:RegisterEvent("CHAT_MSG_YELL")
this:RegisterEvent("CHAT_MSG_WHISPER")
-- Commands
SlashCmdList["RAIDSUMMON"] = RaidSummon_SlashCommand
SLASH_RAIDSUMMON1 = "/raidsummon"
SLASH_RAIDSUMMON2 = "/rs"
MSG_PREFIX_ADD = "RSAdd"
MSG_PREFIX_REMOVE = "RSRemove"
RaidSummonDB = {}
-- Sync Summon Table between raiders ? (if in raid & raiders with unempty table)
--localization
RaidSummonLoc_Header = "RaidSummon"
end
function RaidSummon_EventFrame_OnEvent()
if event == "VARIABLES_LOADED" then
this:UnregisterEvent("VARIABLES_LOADED")
RaidSummon_Initialize()
elseif event == "CHAT_MSG_SAY" or event == "CHAT_MSG_RAID" or event == "CHAT_MSG_RAID_LEADER" or event == "CHAT_MSG_YELL" or event == "CHAT_MSG_WHISPER" then
-- if (string.find(arg1, "^123") and UnitClass("player")~=arg2) then
if string.find(arg1, "^123") then
-- DEFAULT_CHAT_FRAME:AddMessage("CHAT_MSG")
SendAddonMessage(MSG_PREFIX_ADD, arg2, "RAID")
end
elseif event == "CHAT_MSG_ADDON" then
if arg1 == MSG_PREFIX_ADD then
-- DEFAULT_CHAT_FRAME:AddMessage("CHAT_MSG_ADDON - RSAdd : " .. arg2)
if not RaidSummon_hasValue(RaidSummonDB, arg2) and UnitName("player")~=arg2 then
table.insert(RaidSummonDB, arg2)
RaidSummon_UpdateList()
end
elseif arg1 == MSG_PREFIX_REMOVE then
if RaidSummon_hasValue(RaidSummonDB, arg2) then
-- DEFAULT_CHAT_FRAME:AddMessage("CHAT_MSG_ADDON - RSRemove : " .. arg2)
for i, v in ipairs (RaidSummonDB) do
if v == arg2 then
table.remove(RaidSummonDB, i)
RaidSummon_UpdateList()
end
end
end
end
end
end
function RaidSummon_hasValue (tab, val)
for i, v in ipairs (tab) do
if v == val then
return true
end
end
return false
end
--GUI
function RaidSummon_NameListButton_OnClick(button)
local name = getglobal(this:GetName().."TextName"):GetText()
local message, base_message, whisper_message, base_whisper_message, whisper_eviltwin_message, zone_message, subzone_message = ""
local bag,slot,texture,count = FindItem("Soul Shard")
local eviltwin_debuff = "Spell_Shadow_Charm"
local has_eviltwin = false
if button == "LeftButton" and IsControlKeyDown() then
RaidSummon_GetRaidMembers()
if RaidSummon_UnitIDDB then
for i, v in ipairs (RaidSummon_UnitIDDB) do
if v.rName == name then
UnitID = "raid"..v.rIndex
end
end
if UnitID then
TargetUnit(UnitID)
end
else
DEFAULT_CHAT_FRAME:AddMessage("|cff9482c9RaidSummon|r : no raid found")
end
elseif button == "LeftButton" and not IsControlKeyDown() then
RaidSummon_GetRaidMembers()
if RaidSummon_UnitIDDB then
for i, v in ipairs (RaidSummon_UnitIDDB) do
if v.rName == name then
UnitID = "raid"..v.rIndex
end
end
if UnitID then
playercombat = UnitAffectingCombat("player")
targetcombat = UnitAffectingCombat(UnitID)
if not playercombat and not targetcombat then
base_message = "Summoning <" .. name .. ">"
base_whisper_message = "Summoning you"
zone_message = " @" .. GetZoneText()
subzone_message = " @" .. GetSubZoneText()
shards_message = " [" .. count .. " shards]"
message = base_message
whisper_message = base_whisper_message
-- Evil Twin check
for i=1,16 do
s=UnitDebuff("target", i)
if(s) then
if (strfind(strlower(s), strlower(eviltwin_debuff))) then
has_eviltwin = true
end
end
end
TargetUnit(UnitID)
if (has_eviltwin) then
whisper_eviltwin_message = "Can't summon you because of Evil Twin Debuff, you need either to die or to run by yourself"
SendChatMessage(whisper_eviltwin_message, "WHISPER", nil, name)
DEFAULT_CHAT_FRAME:AddMessage("|cff9482c9RaidSummon|r : <" .. name .. "> has |cffff0000Evil Twin|r !")
for i, v in ipairs (RaidSummonDB) do
if v == name then
SendAddonMessage(MSG_PREFIX_REMOVE, name, "RAID")
table.remove(RaidSummonDB, i)
end
end
elseif (Check_TargetInRange()) then
DEFAULT_CHAT_FRAME:AddMessage("|cff9482c9RaidSummon|r : <" .. name .. "> has been summoned already (|cffff0000in range|r)")
-- Remove the already summoned target
for i, v in ipairs (RaidSummonDB) do
if v == name then
SendAddonMessage(MSG_PREFIX_REMOVE, name, "RAID")
table.remove(RaidSummonDB, i)
RaidSummon_UpdateList()
end
end
else
-- TODO: Detect if spell is aborted/cancelled : use SpellStopCasting if sit ("You must be standing to do that")
CastSpellByName("Ritual of Summoning")
-- Send Raid Message
if RaidSummonOptions.zone then
if GetSubZoneText() == "" then
message = message .. zone_message
whisper_message = base_whisper_message .. zone_message
else
message = message .. subzone_message
whisper_message = whisper_message .. subzone_message
end
end
if RaidSummonOptions.shards then
message = message .. shards_message
end
SendChatMessage(message, "RAID")
-- Send Whisper Message
if RaidSummonOptions.whisper then
SendChatMessage(whisper_message, "WHISPER", nil, name)
end
-- Remove the summoned target
for i, v in ipairs (RaidSummonDB) do
if v == name then
SendAddonMessage(MSG_PREFIX_REMOVE, name, "RAID")
table.remove(RaidSummonDB, i)
RaidSummon_UpdateList()
end
end
end
else
DEFAULT_CHAT_FRAME:AddMessage("|cff9482c9RaidSummon|r : Player is in combat")
end
else
DEFAULT_CHAT_FRAME:AddMessage("|cff9482c9RaidSummon|r : <" .. tostring(name) .. "> not found in raid. UnitID: " .. tostring(UnitID))
SendAddonMessage(MSG_PREFIX_REMOVE, name, "RAID")
RaidSummon_UpdateList()
end
else
DEFAULT_CHAT_FRAME:AddMessage("|cff9482c9RaidSummon|r : no raid found")
end
elseif button == "RightButton" then
for i, v in ipairs (RaidSummonDB) do
if v == name then
SendAddonMessage(MSG_PREFIX_REMOVE, name, "RAID")
table.remove(RaidSummonDB, i)
RaidSummon_UpdateList()
end
end
end
RaidSummon_UpdateList()
end
function RaidSummon_UpdateList()
RaidSummon_BrowseDB = {}
--only Update and show if Player is Warlock
if (UnitClass("player") == "Warlock") then
--get raid member data
local raidnum = GetNumRaidMembers()
if (raidnum > 0) then
for raidmember = 1, raidnum do
local rName, rRank, rSubgroup, rLevel, rClass = GetRaidRosterInfo(raidmember)
--check raid data for RaidSummon data
for i, v in ipairs (RaidSummonDB) do
--if player is found fill BrowseDB
if v == rName then
RaidSummon_BrowseDB[i] = {}
RaidSummon_BrowseDB[i].rName = rName
RaidSummon_BrowseDB[i].rClass = rClass
RaidSummon_BrowseDB[i].rIndex = i
if rClass == "Warlock" then
RaidSummon_BrowseDB[i].rVIP = true
else
RaidSummon_BrowseDB[i].rVIP = false
end
end
end
end
--sort warlocks first
table.sort(RaidSummon_BrowseDB, function(a,b) return tostring(a.rVIP) > tostring(b.rVIP) end)
end
for i=1,10 do
if RaidSummon_BrowseDB[i] then
getglobal("RaidSummon_NameList"..i.."TextName"):SetText(RaidSummon_BrowseDB[i].rName)
--set class color
if RaidSummon_BrowseDB[i].rClass == "Druid" then
local c = RaidSummon_GetClassColour("DRUID")
getglobal("RaidSummon_NameList"..i.."TextName"):SetTextColor(c.r, c.g, c.b, 1)
elseif RaidSummon_BrowseDB[i].rClass == "Hunter" then
local c = RaidSummon_GetClassColour("HUNTER")
getglobal("RaidSummon_NameList"..i.."TextName"):SetTextColor(c.r, c.g, c.b, 1)
elseif RaidSummon_BrowseDB[i].rClass == "Mage" then
local c = RaidSummon_GetClassColour("MAGE")
getglobal("RaidSummon_NameList"..i.."TextName"):SetTextColor(c.r, c.g, c.b, 1)
elseif RaidSummon_BrowseDB[i].rClass == "Paladin" then
local c = RaidSummon_GetClassColour("PALADIN")
getglobal("RaidSummon_NameList"..i.."TextName"):SetTextColor(c.r, c.g, c.b, 1)
elseif RaidSummon_BrowseDB[i].rClass == "Priest" then
local c = RaidSummon_GetClassColour("PRIEST")
getglobal("RaidSummon_NameList"..i.."TextName"):SetTextColor(c.r, c.g, c.b, 1)
elseif RaidSummon_BrowseDB[i].rClass == "Rogue" then
local c = RaidSummon_GetClassColour("ROGUE")
getglobal("RaidSummon_NameList"..i.."TextName"):SetTextColor(c.r, c.g, c.b, 1)
elseif RaidSummon_BrowseDB[i].rClass == "Shaman" then
local c = RaidSummon_GetClassColour("SHAMAN")
getglobal("RaidSummon_NameList"..i.."TextName"):SetTextColor(c.r, c.g, c.b, 1)
elseif RaidSummon_BrowseDB[i].rClass == "Warlock" then
local c = RaidSummon_GetClassColour("WARLOCK")
getglobal("RaidSummon_NameList"..i.."TextName"):SetTextColor(c.r, c.g, c.b, 1)
elseif RaidSummon_BrowseDB[i].rClass == "Warrior" then
local c = RaidSummon_GetClassColour("WARRIOR")
getglobal("RaidSummon_NameList"..i.."TextName"):SetTextColor(c.r, c.g, c.b, 1)
end
getglobal("RaidSummon_NameList"..i):Show()
else
getglobal("RaidSummon_NameList"..i):Hide()
end
end
if not RaidSummonDB[1] then
if RaidSummon_RequestFrame:IsVisible() then
RaidSummon_RequestFrame:Hide()
end
else
ShowUIPanel(RaidSummon_RequestFrame, 1)
end
end
end
--Slash Handler
function RaidSummon_SlashCommand(msg)
if msg == "help" then
DEFAULT_CHAT_FRAME:AddMessage("RaidSummon usage:")
DEFAULT_CHAT_FRAME:AddMessage("/rs or /raidsummon { help | show | zone | whisper | shards | debug }")
DEFAULT_CHAT_FRAME:AddMessage(" - |cff9482c9help|r: prints out this help")
DEFAULT_CHAT_FRAME:AddMessage(" - |cff9482c9show|r: shows the current summon list")
DEFAULT_CHAT_FRAME:AddMessage(" - |cff9482c9zone|r: toggles zoneinfo in /ra and /w")
DEFAULT_CHAT_FRAME:AddMessage(" - |cff9482c9whisper|r: toggles the usage of /w")
DEFAULT_CHAT_FRAME:AddMessage(" - |cff9482c9shards|r: toggles shards count when you announce a summon in /ra")
DEFAULT_CHAT_FRAME:AddMessage("To drag the frame use left mouse button")
elseif msg == "show" then
for i, v in ipairs(RaidSummonDB) do
DEFAULT_CHAT_FRAME:AddMessage(tostring(v))
end
elseif msg == "zone" then
if RaidSummonOptions["zone"] == true then
RaidSummonOptions["zone"] = false
DEFAULT_CHAT_FRAME:AddMessage("RaidSummon - zoneinfo: |cffff0000disabled|r")
elseif RaidSummonOptions["zone"] == false then
RaidSummonOptions["zone"] = true
DEFAULT_CHAT_FRAME:AddMessage("RaidSummon - zoneinfo: |cff00ff00enabled|r")
end
elseif msg == "whisper" then
if RaidSummonOptions["whisper"] == true then
RaidSummonOptions["whisper"] = false
DEFAULT_CHAT_FRAME:AddMessage("RaidSummon - whisper: |cffff0000disabled|r")
elseif RaidSummonOptions["whisper"] == false then
RaidSummonOptions["whisper"] = true
DEFAULT_CHAT_FRAME:AddMessage("RaidSummon - whisper: |cff00ff00enabled|r")
end
elseif msg == "shards" then
if RaidSummonOptions["shards"] == true then
RaidSummonOptions["shards"] = false
DEFAULT_CHAT_FRAME:AddMessage("RaidSummon - shards: |cffff0000disabled|r")
elseif RaidSummonOptions["shards"] == false then
RaidSummonOptions["shards"] = true
DEFAULT_CHAT_FRAME:AddMessage("RaidSummon - shards: |cff00ff00enabled|r")
end
elseif msg == "debug" then
if RaidSummonOptions["debug"] == true then
RaidSummonOptions["debug"] = false
DEFAULT_CHAT_FRAME:AddMessage("RaidSummon - debug: |cffff0000disabled|r")
elseif RaidSummonOptions["debug"] == false then
RaidSummonOptions["debug"] = true
DEFAULT_CHAT_FRAME:AddMessage("RaidSummon - debug: |cff00ff00enabled|r")
end
else
if RaidSummon_RequestFrame:IsVisible() then
RaidSummon_RequestFrame:Hide()
else
RaidSummon_UpdateList()
ShowUIPanel(RaidSummon_RequestFrame, 1)
end
end
end
--class color
function RaidSummon_GetClassColour(class)
if (class) then
local color = RAID_CLASS_COLORS[class]
if (color) then
return color
end
end
return {r = 0.5, g = 0.5, b = 1}
end
--raid member
function RaidSummon_GetRaidMembers()
local raidnum = GetNumRaidMembers()
if (raidnum > 0) then
RaidSummon_UnitIDDB = {}
for i = 1, raidnum do
local rName, rRank, rSubgroup, rLevel, rClass = GetRaidRosterInfo(i)
RaidSummon_UnitIDDB[i] = {}
if (not rName) then
rName = "unknown"..i
end
RaidSummon_UnitIDDB[i].rName = rName
RaidSummon_UnitIDDB[i].rClass = rClass
RaidSummon_UnitIDDB[i].rIndex = i
end
end
end
-- FindItem function from SuperMacro to get the total number of Soul Shards
function FindItem(item)
if (not item) then return end
item = string.lower(ItemLinkToName(item))
local link
for i = 1,23 do
link = GetInventoryItemLink("player",i)
if (link) then
if (item == string.lower(ItemLinkToName(link))) then
return i, nil, GetInventoryItemTexture('player', i), GetInventoryItemCount('player', i)
end
end
end
local count, bag, slot, texture
local totalcount = 0
for i = 0,NUM_BAG_FRAMES do
for j = 1,MAX_CONTAINER_ITEMS do
link = GetContainerItemLink(i,j)
if (link) then
if (item == string.lower(ItemLinkToName(link))) then
bag, slot = i, j
texture, count = GetContainerItemInfo(i,j)
totalcount = totalcount + count
end
end
end
end
return bag, slot, texture, totalcount
end
-- Checks if the target is in range (28 yards)
function Check_TargetInRange()
if not (GetUnitName("target")==nil) then
local t = UnitName("target")
if (CheckInteractDistance("target", 4)) then
return true
else
return false
end
end
end