-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEventHandler.lua
280 lines (208 loc) · 9.21 KB
/
EventHandler.lua
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
StriLi.EventHandler = { frame = nil };
function StriLi.EventHandler:init()
if self.frame == nil then
self.frame = CreateFrame("FRAME");
end
self.frame:SetScript("OnEvent", function(_, event, ...)
self:OnEvent(event, ...)
end);
self.frame:RegisterEvent("ADDON_LOADED");
self.frame:RegisterEvent("PLAYER_LOGOUT");
self.frame:RegisterEvent("PARTY_MEMBERS_CHANGED");
self.frame:RegisterEvent("PARTY_MEMBER_DISABLE");
self.frame:RegisterEvent("PARTY_MEMBER_ENABLE");
self.frame:RegisterEvent("CHAT_MSG_ADDON");
self.frame:RegisterEvent("CHAT_MSG_WHISPER");
end
function StriLi.EventHandler:OnEvent(event, ...)
if event == "ADDON_LOADED" and arg1 == "StriLi" then
StriLi.startup = true;
StriLi_initAddon();
StriLi.MainFrame:init();
StriLi.ItemHistory:initFromRawData(StriLi_ItemHistory);
StriLi.LootRules:init();
StriLi_OptionFrame_init();
if StriLi_VersionEncryptToNumber(StriLi_LatestVersionEncrypt) > StriLi_VersionEncryptToNumber(StriLi.VersionEncrypt) then
local versionFrame = CreateFrame("FRAME", "StriLi_VersionFrame", UIParent, "StriLi_CopyVersionFrame_Template");
local editBox = versionFrame:GetChildren():GetChildren();
StriLi_VersionFrame_FontString:SetText();
editBox:SetText("https://github.com/sba5827/StriLi");
editBox:HighlightText();
versionFrame:Show();
editBox:SetScript("OnEscapePressed", function(_) versionFrame:Hide() end);
end
delayedFunctionCall(20.0, function ()
self:OnPartyMembersChanged();
StriLi.startup = false;
print("|cff00ffffStriLi "..StriLi.Lang.version.." " .. StriLi_VersionEncryptToNumber(StriLi.VersionEncrypt) .. " "..StriLi.Lang.loaded.."|r");
if (not StriLi_isVersionValid(StriLi.VersionEncrypt)) then
print("|cff00ffff ".."This does not seem like a valid version of StriLi. Checkout https://github.com/sba5827/StriLi.")
else
print("|cff00ffff ".."This does seem like a valid version of StriLi.")
end
end)
elseif event == "PARTY_MEMBERS_CHANGED" or event == "PARTY_MEMBER_DISABLE" or event == "PARTY_MEMBER_ENABLE" then
self:OnPartyMembersChanged();
elseif event == "PLAYER_LOGOUT" then
StriLi_finalizeAddon(); -- Ensures that all important data will be saved
elseif event == "CHAT_MSG_SYSTEM" then
self.chatMsgSystem_cbFnc(...);
elseif event == "CHAT_MSG_ADDON" then
StriLi.CommunicationHandler:On_CHAT_MSG_ADDON(...);
elseif event == "CHAT_MSG_WHISPER" then
self:OnWhisper(...);
end
end
function StriLi.EventHandler:OnPartyMembersChanged()
local numOfMembers = GetNumRaidMembers();
if numOfMembers < 1 and not StriLi_newRaidGroup then
self:OnRaidLeft();
elseif numOfMembers < 1 and StriLi_newRaidGroup then
-- just entered or left a Group no Raid
if not (StriLi.master:get() == "") then
StriLi.master:set("");
end
elseif numOfMembers > 1 and StriLi_newRaidGroup then
self:OnJoiningNewRaidGroup();
elseif numOfMembers > 1 then
self:addNewPlayers();
end
StriLi.CommunicationHandler:ShoutVersion();
StriLi.CommunicationHandler:sendMasterChanged(StriLi.master:get());
end
function StriLi.EventHandler:OnRaidLeft()
if StriLi.confirmFrame ~= nil then
StriLi.confirmFrame:hide();
end
StriLi.confirmFrame = ConfirmDialogFrame:new(nil, StriLi.Lang.Confirm.RaidLeftResetData,
function()
StriLi.MainFrame:resetData();
end,
nil);
StriLi.confirmFrame:show();
StriLi_newRaidGroup = true;
StriLi.master:set("");
end
function StriLi.EventHandler:OnJoiningNewRaidGroup()
StriLi.CommunicationHandler:checkForMaster(function(master)
local _, rank = GetRaidRosterInfo(UnitInRaid("player")+1);
if master == "" and rank > 0 then
local newMaster = UnitName("player");
if StriLi.CommunicationHandler:sendMasterChanged(newMaster) then
StriLi.master:set(newMaster);
else
error(StriLi.Lang.ErrorMsg.MasterInitFail);
end
else
StriLi.master:set(master);
end
end);
StriLi_newRaidGroup = false;
if RaidMembersDB:getSize() > 0 then
if StriLi.confirmFrame ~= nil then
StriLi.confirmFrame:hide();
end
StriLi.confirmFrame = ConfirmDialogFrame:new(nil, StriLi.Lang.Confirm.NewRaidResetData,
function()
StriLi.MainFrame:resetData();
StriLi.CommunicationHandler:sendSycRequest();
end,
function()
self:addNewPlayers();
StriLi.CommunicationHandler:sendSycRequest();
end);
StriLi.confirmFrame:show();
else
self:addNewPlayers();
StriLi.CommunicationHandler:sendSycRequest();
end
end
function StriLi.EventHandler:enable_CHAT_MSG_SYSTEM_event(cbFnc)
self.frame:RegisterEvent("CHAT_MSG_SYSTEM");
self.chatMsgSystem_cbFnc = cbFnc;
end
function StriLi.EventHandler:disable_CHAT_MSG_SYSTEM_event()
self.frame:UnregisterEvent("CHAT_MSG_SYSTEM");
self.chatMsgSystem_cbFnc = nil;
end
function StriLi.EventHandler:addNewPlayers()
local numOfMembers = GetNumRaidMembers();
local masterIsInRaid = false;
for i = 1, numOfMembers do
local name, _, subgroup = GetRaidRosterInfo(i);
if (name == nil) then
return ;
end
if not (StriLiOptions["IgnoreGroup"..subgroup]) then
if StriLi.master:get() == name then
masterIsInRaid = true;
end
local _, englishClass = UnitClass("raid" .. tostring(i));
local existingMember = RaidMembersDB:checkForMember(name);
if not existingMember then
RaidMembersDB:add(name, englishClass);
StriLi.MainFrame:addPlayer({ name, RaidMembersDB:get(name) });
end
StriLi.CommunicationHandler:checkIfUserHasStriLi(name, function(userHasStriLi)
if userHasStriLi and not (StriLi.master:get() == name) and not RaidMembersDB:isMemberAssist(name) then
StriLi.MainFrame.rows[name]:setStatus(RowFrameStatus_t.HasStriLi);
elseif userHasStriLi and not (StriLi.master:get() == name) and RaidMembersDB:isMemberAssist(name) then
StriLi.MainFrame.rows[name]:setStatus(RowFrameStatus_t.StriLiAssist);
elseif userHasStriLi and (StriLi.master:get() == name) then
StriLi.MainFrame.rows[name]:setStatus(RowFrameStatus_t.StriLiMaster);
end
end);
end
end
if not masterIsInRaid then
if StriLi.MainFrame.rows[StriLi.master:get()] ~= nil then
StriLi.MainFrame.rows[StriLi.master:get()]:setStatus(RowFrameStatus_t.None);
end
StriLi.master:set("");
local _t = math.random()*10;
self.frame:SetScript("OnUpdate",function(_, elapsed)
_t = _t -elapsed;
if _t < 0.0 then
StriLi.CommunicationHandler:checkForMaster(function(master)
if UnitInRaid("player") == nil then return end;
masterIsInRaid = false;
for i = 1, numOfMembers do
local name = GetRaidRosterInfo(i);
if (name == nil) then
return ;
end
if name == master then
masterIsInRaid = true;
end
end
local _, rank = GetRaidRosterInfo(UnitInRaid("player")+1)
if not masterIsInRaid and rank > 0 then
local newMaster = UnitName("player");
if StriLi.CommunicationHandler:sendMasterChanged(newMaster) then
StriLi.master:set(newMaster);
else
error(StriLi.Lang.ErrorMsg.MasterInitFail);
end
else
StriLi.master:set(master);
end
end);
self.frame:SetScript("OnUpdate", nil);
end
end)
end
end
function StriLi.EventHandler:OnWhisper(...)
local message, author = arg1, arg2;
message = string.lower(message);
if RaidMembersDB:checkForMember(author) and StriLi_GetPlayerRank(author) > -1 and StriLiOptions["WhisperTallyMarks"] then
if string.match(message,"%s*strich") and not string.match(message,"%S+strich") or
string.match(message,"%s*stroke") and not string.match(message,"%S+stroke") or
string.match(message,"%s*tally mark") and not string.match(message,"%S+tally mark") or
string.match(message,"%s*strili") and not string.match(message,"%S+strili") or
string.match(message,"%s*trazo") and not string.match(message,"%S+trazo")
then
RaidMembersDB:postAllDataAsWhisper(author);
end
end
end