-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWaitlist.lua
More file actions
235 lines (200 loc) · 9.08 KB
/
Waitlist.lua
File metadata and controls
235 lines (200 loc) · 9.08 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
do
local players = {}
local function AddPlayer(self, name, whispered)
if(GetNumGroupMembers() == 0) then
EPGPWaitlist:Print("You must be in a raid to have a waitlist.")
return
end
name = name:lower()
msgName = name:lower()
-- Check this player is in the guild
if not EPGPWaitlist.guildlist:IsGuildMember(name) then
if(whispered) then
SendChatMessage("This player is not in the guild. Your alts and main must be in the guild to use the waitlist.", "WHISPER", nil, name);
end
EPGPWaitlist:Print(EPGPWaitlist:Capitalize(name) .." requested to be on the waitlist, but is not in the guild.")
return false
end
local onlineStatus = EPGPWaitlist.guildlist:GetOnlineStatus(name) -- The online status from last guild roster update
-- Check if the player name is an alt, then get their main's name.
if EPGPWaitlist.guildlist:IsAlt(name) then
name = EPGPWaitlist.guildlist:GetAltsMain(name)
-- Check that the main is in the guild
if not EPGPWaitlist.guildlist:IsGuildMember(name) then
if(whispered) then
SendChatMessage(EPGPWaitlist:Capitalize(name) .. " is not in the guild. Check that the spelling is correct in your public note.", "WHISPER", nil, name);
end
EPGPWaitlist:Print(EPGPWaitlist:Capitalize(name) .." requested to be on the waitlist, but is not in the guild.")
return false
end
end
-- Check if player is already on waitlist
if self:IsWaitlisted(name) then
if(whispered) then
SendChatMessage(EPGPWaitlist:Capitalize(name) .. " is already on the waitlist.", "WHISPER", nil, name)
end
EPGPWaitlist:Print(EPGPWaitlist:Capitalize(name) .." is already on the waitlist.")
return false
-- Check if this player is in the raid
elseif EPGPWaitlist.raidlist:IsInRaid(name) then
if(whispered) then
SendChatMessage("You are in the raid. You may not be on the waitlist while in the raid.", "WHISPER", nil, name)
end
EPGPWaitlist:Print(EPGPWaitlist:Capitalize(name) .." is already in the raid.")
return false
end
-- Add player
players[name] = EPGPWaitlist:Player(name, onlineStatus) -- Creates a new player object
EPGPWaitlist:Print(EPGPWaitlist:Capitalize(name) .. " has been added to the waitlist.")
-- Add player to save variables if it doesnt exist already
local bool = false
for idx,player in ipairs(EPGPWaitlist.config.waitlistedPlayers) do
if(player == name) then
bool = true
end
end
if( not bool ) then
tinsert(EPGPWaitlist.config.waitlistedPlayers, name) -- Add player to saved variables
end
if(whispered) then
SendChatMessage(EPGPWaitlist:Capitalize(name) .. " has been added to the waitlist.", "WHISPER", nil, msgName)
end
end
local function RemovePlayer(self, name, whispered)
local name = name:lower()
local main = name -- Player to remove from waitlist
local msg = "" -- Message to be whispered/printed
if(GetNumGroupMembers() == 0) then
EPGPWaitlist:Print("You must be in a raid to have a waitlist.")
return
elseif players[name] == nil then
if(whispered) then
SendChatMessage("You are not on the waitlist.", "WHISPER", nil, name)
end
return
end
-- Check if player is an alt
if EPGPWaitlist.guildlist:IsAlt(name) then
-- Get their main's name
main = EPGPWaitlist.guildlist:GetAltsMain(name)
-- Check if they are on the waitlist
elseif self:IsWaitlisted(main) == nil then
msg = EPGPWaitlist:Capitalize(main) .." is not on the waitlist."
-- Remove player
else
self:RemoveFromWaitlist(main)
msg = EPGPWaitlist:Capitalize(main) .. " has been removed from the waitlist."
end
-- Send messages
if(whispered) then
SendChatMessage(msg, "WHISPER", nil, name)
end
end
function MassEPAward(self, event_name, names, reason, amount)
reason = "Waitlist - " .. reason
local awarded = false -- Only announce if we actually award a player
EPGPWaitlist:GuildRosterUpdateEventHandler() -- Update the guild roster before awarding so offline durations are current
-- Generate announce message
local msg = "EPGP: "
if amount > -1 then
msg = msg .. "+"
end
msg = msg .. amount .. " EP (" .. reason .. ") to "
-- Award EP to every member on the waitlist.
-- WARNING: EPGP uses the LibGuildStorage to handle officer notes. This will prevent the
-- IncEPBy from executing when the state of the GuildStorage object is not "CURRENT". I
-- believe this signify's the officer notes as being "fresh". When EPGP rewards a Mass
-- EP Award, it ignores the state of GuildStorage because "we know what we are doing"?
-- Since we are tagging this with the Mass EP Award, it should be fine to do the same.
for idx,player in pairs(players) do
if player.online or (player.lastUpdated - player.lastOnline < EPGPWaitlist.config.offlineTimeout) then
EPGP:IncEPBy(EPGPWaitlist:Capitalize(idx), reason, amount, true) -- Increment as a "mass" ep award
msg = msg .. " " .. EPGPWaitlist:Capitalize(idx) .. "," -- append the player name
awarded = true
else
EPGPWaitlist:Print(idx .. " is offline and lost the EP Award.")
end
end
-- Announce to the guild, removing the final comma
if awarded then
SendChatMessage(msg:sub(1,-2), "GUILD")
end
end
local function IsWaitlisted(self, name)
if players[name] ~= nil then
return true
end
return false
end
local function RemoveFromWaitlist(self, name)
if players[name] ~= nil then
players[name] = nil
if #EPGPWaitlist.config.waitlistedPlayers > 0 then
for idx,player in ipairs(EPGPWaitlist.config.waitlistedPlayers) do
if player == name then
tremove(EPGPWaitlist.config.waitlistedPlayers, idx) -- Remove player from saved variables
end
end
end
return true
end
return false
end
local function List(self)
EPGPWaitlist:GuildRosterUpdateEventHandler() -- Update the guild roster before awarding so offline durations are current
for idx,player in pairs(players) do
local msg = ""
msg = msg .. player.name .. "'s status is: "
if player.online then
msg = msg .. "Online"
else
local timeSeconds = player.lastUpdated - player.lastOnline
local timeHours = math.floor(timeSeconds / 60 / 60)
local timeMinutes = math.floor(timeSeconds / 60) - timeHours * 60
timeSeconds = timeSeconds % 60
msg = msg .. "Offline" .. " ("
if timeHours > 0 then
msg = msg .. timeHours .. "h"
end
if timeMinutes > 0 then
msg = msg .. timeMinutes .. "m"
end
if timeSeconds > 0 then
msg = msg .. timeSeconds .. "s"
end
msg = msg .. ")"
end
if player.alt ~= nil then
msg = msg .. " (" .. player.alt ..") "
end
EPGPWaitlist:Print(msg)
end
end
local function RemoveAll(self)
wipe(players) -- Wipe the players table
wipe(EPGPWaitlist.config.waitlistedPlayers) -- Wipe the saved variables
EPGPWaitlist:Print("Waitlist has been wiped.")
end
local function UpdatePlayerStatus(self, name, time, isOnline, isAlt, altName)
if isAlt then
players[name]:updateOnlineTimeAlt(time, altName)
elseif isOnline then
players[name]:updateOnlineTime(time)
else
players[name]:updateOfflineTime(time)
end
end
function EPGPWaitlist:Waitlist()
local obj = {
AddPlayer = AddPlayer,
RemovePlayer = RemovePlayer,
IsWaitlisted = IsWaitlisted,
RemoveFromWaitlist = RemoveFromWaitlist,
List = List,
RemoveAll = RemoveAll,
UpdatePlayerStatus = UpdatePlayerStatus,
MassEPAward = MassEPAward
}
return obj
end
end