-
Notifications
You must be signed in to change notification settings - Fork 0
/
GCGambler.lua
519 lines (479 loc) · 14.7 KB
/
GCGambler.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
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
-- GCGambler by Myrx and Triumvirate of <Gentlemens Club> Korgath US
-- Version 0.3
-- (robozeo) updated to 4.0 (thanks to vulture of ropetown)
-- (robozeo) added a damn close button!
-- Version 0.2
-- (Myrx) Fixed a bug where minimum roll value was not being checked
-- (Myrx) Fixed a bug where you could start a game of 1-1
-- (Myrx) Added logic to prompt for tiebreakers
-- (TODO) Every player ties
-- Version 0.1
-- Initial release version
--[[
local GCGambler = {
["active"] = 1,
["strings"] = { },
["lowtie"] = { },
["hightie"] = { },
["lastroll"] = 100,
["stats"] = { }
}
]]--
local AcceptOnes = "false"
local AcceptRolls = "false"
local totalrolls = 0
local tierolls = 0;
local theMax
local lowname = ""
local highname = ""
local low = 0
local high = 0
local tie = 0
local highbreak = 0;
local lowbreak = 0;
local tiehigh = 0;
local tielow = 0;
local channel_str = "";
function GCGambler_OnLoad(this)
DEFAULT_CHAT_FRAME:AddMessage("|cffffff00<Gentlemens Club Gambler> loaded /gcg to use");
--[[
if GCGambler.active == nil then
GCGambler_Reset();
end
]]--
GCGambler_Frame:Show();
GCGambler_Frame:CreateTitleRegion();
this:RegisterEvent("CHAT_MSG_CHANNEL");
this:RegisterEvent("CHAT_MSG_SYSTEM");
this:RegisterEvent("PLAYER_ENTERING_WORLD");
this:RegisterForDrag("LeftButton");
GCGambler_ROLL_Button:Disable();
GCGambler_AcceptOnes_Button:Enable();
GCGambler_LASTCALL_Button:Disable();
end
function GCGambler_OnEvent(self, event, ...)
arg1,arg2 = ...;
if (event == "PLAYER_ENTERING_WORLD") then
if(not GCGambler) then
GCGambler = {
["active"] = 1,
["strings"] = { },
["lowtie"] = { },
["hightie"] = { }
}
end
if(not GCGambler["lastroll"]) then GCGambler["lastroll"] = 100; end
if(not GCGambler["stats"]) then GCGambler["stats"] = { }; end
if(not GCGambler["lastchan"]) then GCGambler["lastchan"] = 2; end
GCGambler_EditBox:SetText(""..GCGambler["lastroll"]);
GCGambler_ChannelBox:SetText(""..GCGambler["lastchan"]);
end
if ((event == "CHAT_MSG_CHANNEL")and AcceptOnes=="true") then
if (tonumber(tostring(arg1),10) == 1) then
GCGambler_Add(tostring(arg2));
if (not GCGambler_LASTCALL_Button:IsEnabled() and totalrolls == 1) then
GCGambler_LASTCALL_Button:Enable();
end
if totalrolls == 2 then
GCGambler_AcceptOnes_Button:Disable();
GCGambler_AcceptOnes_Button:SetText("Accept Ones");
end
--SendChatMessage(format("%s%s%s","[GCG] ", tostring(arg2), " Pressed 1"),"CHANNEL",GetDefaultLanguage("player"),"6");
end
end
if (event == "CHAT_MSG_SYSTEM" and AcceptRolls=="true") then
local temp1 = tostring(arg1);
GCGambler_ParseRoll(temp1);
end
end
function GCGambler_ResetStats()
GCGambler["stats"] = { };
end
function GCGambler_OnClickRESET()
DEFAULT_CHAT_FRAME:AddMessage("|cffffff00GCG stats have now been reset");
GCGambler_ResetStats();
msgPrint = 1;
end
function GCGambler_OnClickSTATS()
local sortlistname = {};
local sortlistamount = {};
local n = 0;
local i, j;
for i, j in pairs(GCGambler["stats"]) do
sortlistname[n] = i;
sortlistamount[n] = j;
n = n + 1;
end
if(n == 0) then
DEFAULT_CHAT_FRAME:AddMessage("No stats yet!!");
return;
end
for i = 0, n-1 do
for j = i+1, n-1 do
if(sortlistamount[j] > sortlistamount[i]) then
sortlistamount[i], sortlistamount[j] = sortlistamount[j], sortlistamount[i];
sortlistname[i], sortlistname[j] = sortlistname[j], sortlistname[i];
end
end
end
SendChatMessage("--- GCG Stats ---", "CHANNEL",GetDefaultLanguage("player"),channel_str);
for i = 0, n-1 do
sortsign = "won";
if(sortlistamount[i] < 0) then sortsign = "lost"; end
SendChatMessage(string.format("%s %s %d total", sortlistname[i], sortsign, math.abs(sortlistamount[i])), "CHANNEL",GetDefaultLanguage("player"),channel_str);
end
end
function GCGambler_OnClickROLL()
if (totalrolls >1) then
if (AcceptRolls == "true") then
if table.getn(GCGambler.strings) ~= 0 then
--if tie == 0 then
GCGambler_List();
--end
end
return;
end
AcceptOnes = "false";
AcceptRolls = "true";
if (tie == 0) then
SendChatMessage("[GCG] Roll now!","CHANNEL",GetDefaultLanguage("player"), 7);
end
if (lowbreak == 1) then
SendChatMessage(format("%s%d%s", "[GCG] Low end tiebreaker! Roll 1-", theMax, " now!"),"CHANNEL",GetDefaultLanguage("player"),channel_str);
GCGambler_List();
end
if (highbreak == 1) then
SendChatMessage(format("%s%d%s", "[GCG] High end tiebreaker! Roll 1-", theMax, " now!"),"CHANNEL",GetDefaultLanguage("player"),channel_str);
GCGambler_List();
end
GCGambler_EditBox:ClearFocus();
end
if (totalrolls <2) then
SendChatMessage("[GCG] Not enough Players!","CHANNEL",GetDefaultLanguage("player"),channel_str);
end
end
function GCGambler_OnClickLASTCALL()
SendChatMessage("[GCG] Last Call","CHANNEL",GetDefaultLanguage("player"),channel_str);
GCGambler_EditBox:ClearFocus();
GCGambler_LASTCALL_Button:Disable();
GCGambler_ROLL_Button:Enable();
end
function GCGambler_OnClickACCEPTONES()
if GCGambler_EditBox:GetText() ~= "" and GCGambler_EditBox:GetText() ~= "1" then
GCGambler_Reset();
GCGambler_ROLL_Button:Disable();
GCGambler_LASTCALL_Button:Disable();
AcceptOnes = "true";
channel_str = GCGambler_ChannelBox:GetText();
SendChatMessage(
format(
"%s%s%s",
"[GCG] Roll 1-",
GCGambler_EditBox:GetText(),
" Press 1"
),
"CHANNEL",
GetDefaultLanguage("player"),
channel_str
);
GCGambler["lastroll"] = GCGambler_EditBox:GetText();
theMax = tonumber(GCGambler_EditBox:GetText());
low = theMax+1;
tielow = theMax+1;
GCGambler_EditBox:ClearFocus();
GCGambler_AcceptOnes_Button:SetText("New Game");
GCGambler_LASTCALL_Button:Disable();
else
message("Please enter a number to roll from.");
end
end
function GCGambler_Report()
local goldowed = high - low
lowname = lowname:gsub("^%l", string.upper)
highname = highname:gsub("^%l", string.upper)
local string3 = strjoin(" ", "[GCG]", lowname, "owes", highname, goldowed,"gold.")
GCGambler["stats"][highname] = (GCGambler["stats"][highname] or 0) + goldowed;
GCGambler["stats"][lowname] = (GCGambler["stats"][lowname] or 0) - goldowed;
SendChatMessage(string3,"CHANNEL",GetDefaultLanguage("player"),channel_str);
GCGambler_Reset();
GCGambler_AcceptOnes_Button:SetText("Accept Ones");
end
function GCGambler_Tiebreaker()
--Everyone has rolled at this point
tierolls = 0;
totalrolls = 0;
tie = 1;
if table.getn(GCGambler.lowtie) == 1 then
GCGambler.lowtie = {};
end
if table.getn(GCGambler.hightie) == 1 then
GCGambler.hightie = {};
end
totalrolls = table.getn(GCGambler.lowtie) + table.getn(GCGambler.hightie);
tierolls = totalrolls;
if (table.getn(GCGambler.hightie) == 0 and table.getn(GCGambler.lowtie) == 0) then
GCGambler_Report();
else
AcceptRolls = "false";
if table.getn(GCGambler.lowtie) > 0 then
lowbreak = 1;
highbreak = 0;
tielow = theMax+1;
tiehigh = 0;
GCGambler.strings = GCGambler.lowtie;
GCGambler.lowtie = {};
GCGambler_OnClickROLL();
end
if table.getn(GCGambler.hightie) > 0 and table.getn(GCGambler.strings) == 0 then
lowbreak = 0;
highbreak = 1;
tielow = theMax+1;
tiehigh = 0;
GCGambler.strings = GCGambler.hightie;
GCGambler.hightie = {};
GCGambler_OnClickROLL();
end
end
end
function GCGambler_ParseRoll(temp2)
local temp1 = strlower(temp2);
local player, junk, roll, range = strsplit(" ", temp1);
if junk == "rolls" and GCGambler_Check(player)==1 then
minRoll, maxRoll = strsplit("-",range);
minRoll = tonumber(strsub(minRoll,2));
maxRoll = tonumber(strsub(maxRoll,1,-2));
roll = tonumber(roll);
if (maxRoll == theMax and minRoll == 1) then
if (tie == 0) then
if (roll == high) then
if table.getn(GCGambler.hightie) == 0 then
GCGambler_AddTie(highname, GCGambler.hightie);
end
GCGambler_AddTie(player, GCGambler.hightie);
end
if (roll>high) then
highname = player
high = roll
GCGambler.hightie = {};
--GCGambler_AddTie(player, GCGambler.hightie);
end
if (roll == low) then
if table.getn(GCGambler.lowtie) == 0 then
GCGambler_AddTie(lowname, GCGambler.lowtie);
end
GCGambler_AddTie(player, GCGambler.lowtie);
end
if (roll<low) then
lowname = player
low = roll
GCGambler.lowtie = {};
--GCGambler_AddTie(player, GCGambler.lowtie);
end
else
if (lowbreak == 1) then
if (roll == tielow) then
if table.getn(GCGambler.lowtie) == 0 then
GCGambler_AddTie(lowname, GCGambler.lowtie);
end
GCGambler_AddTie(player, GCGambler.lowtie);
end
if (roll<tielow) then
lowname = player
tielow = roll;
GCGambler.lowtie = {};
--GCGambler_AddTie(player, GCGambler.lowtie);
end
end
if (highbreak == 1) then
if (roll == tiehigh) then
if table.getn(GCGambler.hightie) == 0 then
GCGambler_AddTie(highname, GCGambler.hightie);
end
GCGambler_AddTie(player, GCGambler.hightie);
end
if (roll>tiehigh) then
highname = player
tiehigh = roll;
GCGambler.hightie = {};
--GCGambler_AddTie(player, GCGambler.hightie);
end
end
end
GCGambler_Remove(tostring(player));
if table.getn(GCGambler.strings) == 0 then
if tierolls == 0 then
GCGambler_Report();
else
GCGambler_Tiebreaker();
end
end
end
end
end
function GCGambler_Check(player)
for i=1, table.getn(GCGambler.strings) do
if strlower(GCGambler.strings[i]) == tostring(player) then
return 1
end
end
return 0
end
function GCGambler_List()
for i=1, table.getn(GCGambler.strings) do
local string3 = strjoin(" ", "[GCG]", tostring(GCGambler.strings[i]):gsub("^%l", string.upper),"still needs to roll.")
SendChatMessage(string3,"CHANNEL",GetDefaultLanguage("player"),channel_str);
end
end
function GCGambler_Add(name)
if (name ~= nil or name ~= "") then
local found = 0;
for i=1, table.getn(GCGambler.strings) do
if GCGambler.strings[i] == name then
found = 1;
--local string3 = strjoin(" ", "[GCG]", tostring(name),"was already found in the database.")
--SendChatMessage(string3,"CHANNEL",GetDefaultLanguage("player"),"6");
end
end
if found == 0 then
table.insert(GCGambler.strings, name)
totalrolls = totalrolls+1
--local string3 = strjoin(" ", "[GCG]", GCGambler.strings[table.getn(GCGambler.strings)],"has been added to the database.")
--SendChatMessage(string3,"CHANNEL",GetDefaultLanguage("player"),"6");
end
end
end
function GCGambler_AddTie(name, tietable)
if (name ~= nil or name ~= "") then
local found = 0;
for i=1, table.getn(tietable) do
if tietable[i] == name then
found = 1;
--local string3 = strjoin(" ", "[GCG]", tostring(name),"was already found in the database.")
--SendChatMessage(string3,"CHANNEL",GetDefaultLanguage("player"),"6");
end
end
if found == 0 then
table.insert(tietable, name)
tierolls = tierolls+1
totalrolls = totalrolls+1
--local string3 = strjoin(" ", "[GCG]", tostring(name),"was already found in the database.")
--SendChatMessage(string3,"CHANNEL",GetDefaultLanguage("player"),"6");
end
end
end
function GCGambler_Remove(name)
for i=1, table.getn(GCGambler.strings) do
if GCGambler.strings[i] ~= nil then
if strlower(GCGambler.strings[i]) == name then
table.remove(GCGambler.strings, i)
--local string3 = strjoin(" ", "[GCG]", tostring(name),"has been removed from database.")
--SendChatMessage(string3,"CHANNEL",GetDefaultLanguage("player"),"6");
end
end
end
end
function GCGambler_RemoveTie(name, tietable)
for i=1, table.getn(tietable) do
if tietable[i] ~= nil then
if strlower(tietable[i]) == name then
table.remove(tietable, i)
--local string3 = strjoin(" ", "[GCG]", tostring(name),"has been removed from database.")
--SendChatMessage(string3,"CHANNEL",GetDefaultLanguage("player"),"6");
end
end
end
end
function GCGambler_Reset()
--[[
GCGambler = {
["active"] = 1,
["strings"] = { },
["lowtie"] = { },
["hightie"] = { },
["lastroll"] = 100,
["stats"] = { },
}
]]--
GCGambler["active"] = 1;
GCGambler["strings"] = { };
GCGambler["lowtie"] = { };
GCGambler["hightie"] = { };
AcceptOnes = "false"
AcceptRolls = "false"
totalrolls = 0
theMax = 0
tierolls = 0;
lowname = ""
highname = ""
low = theMax
high = 0
tie = 0
highbreak = 0;
lowbreak = 0;
tiehigh = 0;
tielow = 0;
GCGambler_ROLL_Button:Disable();
GCGambler_AcceptOnes_Button:Enable();
GCGambler_LASTCALL_Button:Disable();
end
function GCGambler_EditBox_OnLoad()
GCGambler_EditBox:SetNumeric("true");
GCGambler_EditBox:SetAutoFocus("false");
--[[
if(GCGambler and GCGambler["lastroll"]) then
GCGambler_EditBox:SetText(""..GCGambler["lastroll"]);
else
GCGambler_EditBox:SetText("100");
end
]]--
end
function GCGambler_ChannelBox_OnLoad()
GCGambler_ChannelBox:SetNumeric("true");
GCGambler_ChannelBox:SetAutoFocus("false");
--[[
if(GCGambler and GCGambler["lastroll"]) then
GCGambler_EditBox:SetText(""..GCGambler["lastroll"]);
else
GCGambler_EditBox:SetText("100");
end
]]--
end
function GCGambler_SlashCmd(msg)
local msg = msg:lower()
local msgPrint = 0;
if (msg == "" or msg == nil) then
DEFAULT_CHAT_FRAME:AddMessage("|cffffff00Following commands for /gcg:");
DEFAULT_CHAT_FRAME:AddMessage("|cffffff00show - Shows the frame");
DEFAULT_CHAT_FRAME:AddMessage("|cffffff00hide - Hides the frame");
DEFAULT_CHAT_FRAME:AddMessage("|cffffff00reset - Resets the AddOn");
DEFAULT_CHAT_FRAME:AddMessage("|cffffff00resetstats - Resets the stats");
msgPrint = 1;
end
if (msg == "hide") then
GCGambler_Frame:Hide();
msgPrint = 1;
end
if (msg == "show") then
GCGambler_Frame:Show();
msgPrint = 1;
end
if (msg == "reset") then
DEFAULT_CHAT_FRAME:AddMessage("|cffffff00GCG has now been reset");
GCGambler_Reset();
GCGambler_AcceptOnes_Button:SetText("Accept Ones");
msgPrint = 1;
end
if (msg == "resetstats") then
DEFAULT_CHAT_FRAME:AddMessage("|cffffff00GCG stats have now been reset");
GCGambler_ResetStats();
msgPrint = 1;
end
if (msgPrint == 0) then
DEFAULT_CHAT_FRAME:AddMessage("|cffffff00Invalid argument for command /gcg");
end
end
SLASH_GCGAMBLER1 = "/gambler";
SLASH_GCGAMBLER2 = "/gcg";
SLASH_GCGAMBLER3 = "/rollgame";
SLASH_GCGAMBLER4 = "/GCGambler";
SlashCmdList["GCGAMBLER"] = GCGambler_SlashCmd