-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
CensusPlusWotlk.lua
5581 lines (5111 loc) · 183 KB
/
CensusPlusWotlk.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
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[ CensusPlusWotlk for World of Warcraft(tm).]]
--local regionKey = GetCVar("portal") == "public-test" and "PTR" or GetCVar("portal")
--Note: file layout structured for use with NotePad++ as editor using Lua(WoW) language definition
--[[ CensusPlusWotlk
--A WoW UI customization Originally by Cooper Sellers
--Current Development Scarecr0w12(Jacob Bowen)
]]
local addon_name, addon_tableID = ... -- Addon_name contains the Addon name which must be the same as the container folder name... addon_tableID is a common private table for all .lua files in the directory.
local CPp = addon_tableID --short cut name for private shared table.
local checksum = LibStub:GetLibrary("LibChecksum-1.0", true)
CPp.InterfaceVersion = "Captain Placeholder"; -- random value.. must not match CensusPlus_VERSION string.
local g_CensusPlusTZOffset = -999;
CPp.LocaleSet = false; -- not used?
CPp.TZWarningSent = false; -- not used?
-- Bindings
BINDING_NAME_CensusPlusWotlk_MANUALWHO = 'Issue a manual /who request'
BINDING_HEADER_CensusPlusWotlk = 'CensusPlusWotlk'
-- Constants
local CensusPlus_Version_Major = "0"; -- changing this number will force a saved data purge
local CensusPlus_Version_Minor = "9"; -- changing this number will force a saved data purge
local CensusPlus_Version_Maint = "17"; -- changing this number will force a saved data purge
local CensusPlus_SubVersion = "";
local CensusPlus_VERSION = CensusPlus_Version_Major .. "." .. CensusPlus_Version_Minor .. "." .. CensusPlus_Version_Maint;
local CensusPlus_VERSION_FULL = CensusPlus_VERSION --.."."..CensusPlus_SubVersion ;
local CensusPlus_PTR = GetCVar("portal") == "public-test" and "PTR"; -- enable true for PTR testing enable false for live use
local CensusPlus_MAXBARHEIGHT = 128; -- Length of blue bars
local CensusPlus_NUMGUILDBUTTONS = 10; -- How many guild buttons are on the UI?
local MAX_CHARACTER_LEVEL = 80; -- Maximum level a PC can attain testing only comment out for live
local EXPANSIONLEVEL = GetAccountExpansionLevel()
local MAX_CHARACTER_LEVEL_EXP = MAX_PLAYER_LEVEL_TABLE[2];
local MIN_CHARACTER_LEVEL = 10; -- Minimum observed level returned by /who command (undocumented and barely acknowledged.)
local MAX_WHO_RESULTS = 49; -- Maximum number of who results the server will return
CensusPlus_GUILDBUTTONSIZEY = 16; -- pixil height of guild name lines
local CensusPlus_UPDATEDELAY = 5; -- Delay time between /who messages
local CensusPlus_UPDATEDELAY2 = 10 -- Delay time from who request to database updated
local CP_MAX_TIMES = 50;
--local g_ServerPrefix = ""; -- US VERSION!!
--local g_ServerPrefix = "EU-"; -- EU VERSION!!
-- debug flags for remote QA testing of version upgrades.
local CP_api = "api"
local CP_letterselect = 2 -- default letter selector pattern... valid options 1 and 2.. testing only
local CensusPlus_WHOPROCESSOR = CP_api -- default processing of who request to full wholib CP_api --
local CensusPLus_DEBUGWRITES = false -- don't add debug into to censusplus.lua output.
local CP_g_queue_count = 0 -- process speed checking avg time to process 1 queue
-- Global scope variables
CensusPlus_Database = {}; -- Database of all CensusPlusWotlk results
--removed CensusPlus_BGInfo = {}; -- Battleground info
CensusPlus_PerCharInfo = {}; -- Per character settings
CensusPlus_Unhandled = {};
CensusPlus_JobQueue = {}; -- The queue of pending jobs
local g_TrackUnhandled = false;
CPp.Options_Holder = {} -- table is populated with existing option settings when Options panel is opened.. cancel resets live options to these settings.
CPp.Options_Holder["AccountWide"] = {}
CPp.Options_Holder["CCOverrides"] = {}
-- File scope variables
local g_addon_loaded = false
local g_player_loaded = false
local g_stealth = false; -- Stealth mode switch
local g_Verbose = false; -- Verbose mode switch
local g_Options_confirm_txt = false; -- enable chatty confirm of options until user no longer desires
CPp.AutoCensus = false; -- AutoCensus mode switch
local g_Options_Scope = "AW" -- options are AW or CO
CPp.AutoStartTimer = 30 -- default Slider value in Options
local g_FinishSoundNumber = 1 -- default finish sound..
local g_PlayFinishSound = false -- mode switch
local g_CensusPlusInitialized = false; -- Is CensusPlusWotlk initialized?
local g_CurrentJob = {}; -- Current job being executed
CPp.IsCensusPlusInProgress = false; -- Is a CensusPlusWotlk in progress?
local g_CensusPlusPaused = false -- Is CensusPlusWotlk in progress paused?
CPp.CensusPlusManuallyPaused = false; -- Is CensusPlusWotlk in progress manually paused?
local CensusPlayerOnly = false -- true if player requests via /census me
CensusPlus_JobQueue.g_NumNewCharacters = 0; -- How many new characters found this CensusPlusWotlk
CensusPlus_JobQueue.g_NumUpdatedCharacters = 0; -- How many characters were updated during this CensusPlusWotlk
local g_MobXPByLevel = {}; -- XP earned for killing
local g_CharacterXPByLevel = {}; -- XP required to advance through the given level
local g_TotalCharacterXPPerLevel = {}; -- Total XP required to attain the given level
CensusPlus_Guilds = {}; -- All known guild
local g_TotalCharacterXP = 0; -- Total character XP for currently selected search
local g_Consecutive = 0; -- Current consecutive same realm/faction run count
local g_TotalCount = 0; -- Total number of characters which meet search criteria
local g_RaceCount = {}; -- Totals for each race given search criteria
local g_ClassCount = {}; -- Totals for each class given search criteria
local g_LevelCount = {}; -- Totals for each level given search criteria
local g_AccumulatorCount = 0;
local g_AccumulatorXPTotal = 0;
local g_AccumulateGuildTotals = true; -- switch for guild work when scanning characters
CensusPlus_JobQueue.g_TempCount = {};
CPp.GuildSelected = 0; -- Search criteria: Currently selected guild, 0 indicates none
CPp.RaceSelected = 0; -- Search criteria: Currently selected race, 0 indicates none
CPp.ClassSelected = 0; -- Search criteria: Currently selected class, 0 indicates none
CPp.LevelSelected = 0;
local current_realm = 0;
local g_LastOnUpdateTime = 0; -- Last time OnUpdate was called
local g_WaitingForWhoUpdate = false; -- Are we waiting for a who update event?
local g_factionGroup = "Neutral" -- Faction of character running census. used to select/verify correct faction of race
local g_WhoAttempts = 0; -- Counter for detecting stuck who results
local g_MiniOnStart = 1; -- Flag to have the mini-censusP displayed on startup
local g_CompleteCensusStarted = false; -- Flag for counter
local g_TakeHour = 0; -- Our timing hour
local g_ResetHour = true; -- Rest hour
local g_VariablesLoaded = false; -- flag to tell us if vars are loaded
CPp.FirstLoad = false -- Flag to handle (hide) various database rebuild messages on initial database creation
local g_FirstRun = true;
local g_wasPurged = false
local whoquery_answered = false;
local whoquery_active = false
CPp.LastCensusRun = time() -- (CPp.AutoStartTrigger * 60) -- timer used if auto census is turned on
CPp.LastManualWho = time()
local g_Pre_SFX = nil;
local CP_updatingGuild = nil;
local g_CurrentlyInBG = false;
local g_CurrentlyInBG_Msg = false;
local g_InternalSearchName = nil;
local g_InternalSearchLevel = nil;
local g_InternalSearchCount = 0;
CPp.EnableProfiling = false;
local CP_profiling_timerstart = 0
local CP_profiling_timediff = 0
local g_CensusPlus_StartTime = 0;
local g_CensusWhoOverrideMsg = nil;
local g_WaitingForOverrideUpdate = false;
local g_ProblematicMessageShown = false;
local g_PratLoaded = false;
-- Battleground info
CENSUSPLUS_CURRENT_BATTLEFIELD_QUEUES = {};
local g_AccumulatedPruneData = {};
local g_RaceClassList = {}; -- Used to pick the right icon
g_RaceClassList[CENSUSPLUS_DRUID] = 10;
g_RaceClassList[CENSUSPLUS_HUNTER] = 11;
g_RaceClassList[CENSUSPLUS_MAGE] = 12;
g_RaceClassList[CENSUSPLUS_PRIEST] = 13;
g_RaceClassList[CENSUSPLUS_ROGUE] = 14;
g_RaceClassList[CENSUSPLUS_WARLOCK] = 15;
g_RaceClassList[CENSUSPLUS_WARRIOR] = 16;
g_RaceClassList[CENSUSPLUS_SHAMAN] = 17;
g_RaceClassList[CENSUSPLUS_PALADIN] = 18;
g_RaceClassList[CENSUSPLUS_DEATH_KNIGHT] = 30;
g_RaceClassList[CENSUSPLUS_DWARF] = 20;
g_RaceClassList[CENSUSPLUS_GNOME] = 21;
g_RaceClassList[CENSUSPLUS_HUMAN] = 22;
g_RaceClassList[CENSUSPLUS_NIGHTELF] = 23;
g_RaceClassList[CENSUSPLUS_ORC] = 24;
g_RaceClassList[CENSUSPLUS_TAUREN] = 25;
g_RaceClassList[CENSUSPLUS_TROLL] = 26;
g_RaceClassList[CENSUSPLUS_UNDEAD] = 27;
g_RaceClassList[CENSUSPLUS_DRAENEI] = 28;
g_RaceClassList[CENSUSPLUS_BLOODELF] = 29;
CensusPlus_JobQueue.g_TimeDatabase = {}; -- Time database
local function CensusPlus_Zero_g_TimeDatabase()
CensusPlus_JobQueue.g_TimeDatabase = nil;
CensusPlus_JobQueue.g_TimeDatabase = {};
CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_DRUID] = 0;
CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_HUNTER] = 0;
CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_MAGE] = 0;
CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_PRIEST] = 0;
CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_ROGUE] = 0;
CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_WARLOCK] = 0;
CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_WARRIOR] = 0;
CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_SHAMAN] = 0;
CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_PALADIN] = 0;
CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_DEATH_KNIGHT] = 0;
end
CensusPlus_Zero_g_TimeDatabase();
-- These two DO NOT need to be localized
local CENSUSPlus_HORDE = "Horde";
local CENSUSPlus_ALLIANCE = "Alliance";
local g_FactionCheck = {};
g_FactionCheck[CENSUSPLUS_ORC] = CENSUSPlus_HORDE;
g_FactionCheck[CENSUSPLUS_TAUREN] = CENSUSPlus_HORDE;
g_FactionCheck[CENSUSPLUS_TROLL] = CENSUSPlus_HORDE;
g_FactionCheck[CENSUSPLUS_UNDEAD] = CENSUSPlus_HORDE;
g_FactionCheck[CENSUSPLUS_BLOODELF] = CENSUSPlus_HORDE;
g_FactionCheck[CENSUSPLUS_DWARF] = CENSUSPlus_ALLIANCE;
g_FactionCheck[CENSUSPLUS_GNOME] = CENSUSPlus_ALLIANCE;
g_FactionCheck[CENSUSPLUS_HUMAN] = CENSUSPlus_ALLIANCE;
g_FactionCheck[CENSUSPLUS_NIGHTELF] = CENSUSPlus_ALLIANCE;
g_FactionCheck[CENSUSPLUS_DRAENEI] = CENSUSPlus_ALLIANCE;
-- Print a string to the chat frame
local function CensusPlus_Msg(msg)
if (msg == nil) then
msg = " NIL ";
end
if (not (g_stealth)) then
ChatFrame1:AddMessage(CENSUSPLUS_TEXT .. " " .. msg, 1.0, 1.0, 0.5);
end
end
local function CensusPlus_WhoMsg(msg)
if (msg == nil) then
msg = " NIL ";
end
ChatFrame1:AddMessage(CENSUSPLUS_TEXT .. " " .. WHO .. ": " .. msg, 0.8, 0.8, 0.1);
end
local function CensusPlus_Msg2(msg)
if (msg == nil) then
msg = " NIL ";
end
if (not (g_stealth)) then
ChatFrame2:AddMessage(CENSUSPLUS_TEXT .. ": " .. msg, 0.5, 1.0, 1.0);
end
end
--- PTR debug messages
local channel = 0
local channelName = " "
local channelReady = false
local instanceID = 0
local language = nil -- nil = common for faction
local HortonBug = false
local HortonFingers = false
local HortonChannel = "Hortondebug"
local function HortonChatMsg(hotair)
DEFAULT_CHAT_FRAME:AddMessage(hotair, 0.7, 0.5, 0.7)
end
local function HortonChannelMsg(hotair)
SendChatMessage(hotair, "CHANNEL", language, channel)
-- chattype = CHANNEL
-- language = COMMON
-- channel = channel
end
-- local says = HortonChannelMsg
local says = HortonChatMsg -- work around for incomplete work on Starter client sigh
local chat = HortonChatMsg
local function HortonChannelSetup()
channel, channelName, instanceID = GetChannelName(HortonChannel)
ChatFrame_AddChannel(DEFAULT_CHAT_FRAME, channel)
channelReady = true
says("Horton finds his very own channel")
says("Horton turned on the chatlog")
end
function CensusPlus_GetUniqueRealmName()
local realmname = GetRealmName()
local guid = UnitGUID("player")
local realmid = string.match(guid, "^Player%-(%d+)")
return realmid .. "_" .. realmname
end
-- Set up confirmation boxes
StaticPopupDialogs["CP_PURGE_CONFIRM"] = {
text = CENSUSPLUS_PURGE_LOCAL_CONFIRM,
button1 = YES,
button2 = NO,
OnAccept = function()
CensusPlus_DoPurge()
end,
-- sound = "levelup2",
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
showAlert = 1
}
-- Set up Continue after override box .. no longer valid
StaticPopupDialogs["CP_CONTINUE_CENSUS"] = {
text = CENSUSPlus_OVERRIDE_COMPLET_PAUSED,
button1 = CENSUSPlus_CONTINUE,
OnAccept = function()
CPp.CensusPlusManuallyPaused = false
CensusPlusTakeButton:SetText(CENSUSPLUS_PAUSE)
end,
-- sound = "levelup2",
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
showAlert = 1
}
-- Insert a job at the end of the job queue
local function InsertJobIntoQueue(job)
--CensusPlus_DumpJob( job )
table.insert(CensusPlus_JobQueue, job)
end
-- Initialize the tables of constants for XP calculations
local function InitConstantTables()
-- XP earned for killing
for i = 1, MAX_CHARACTER_LEVEL, 1 do
g_MobXPByLevel[i] = i
end
-- XP required to advance through the given level
for i = 1, MAX_CHARACTER_LEVEL, 1 do
g_CharacterXPByLevel[i] = ((8 * i * g_MobXPByLevel[i]) / 100) * 100
end
-- Total XP required to attain the given level
local totalCharacterXP = 0
for i = 1, MAX_CHARACTER_LEVEL, 1 do
--g_TotalCharacterXPPerLevel[i] = totalCharacterXP;
--totalCharacterXP = totalCharacterXP + g_CharacterXPByLevel[i];
val = (i * 5) / MAX_CHARACTER_LEVEL
g_TotalCharacterXPPerLevel[i] = math.exp(val)
end
end
-- Return a table of races for the input faction
function CensusPlus_GetFactionRaces(faction)
local ret = {};
if (faction == CENSUSPlus_HORDE) then
ret = { CENSUSPLUS_ORC, CENSUSPLUS_TAUREN, CENSUSPLUS_TROLL, CENSUSPLUS_UNDEAD, CENSUSPLUS_BLOODELF };
elseif (faction == CENSUSPlus_ALLIANCE) then
ret = { CENSUSPLUS_DWARF, CENSUSPLUS_GNOME, CENSUSPLUS_HUMAN, CENSUSPLUS_NIGHTELF, CENSUSPLUS_DRAENEI };
end
return ret;
end
-- Return a table of classes for the input faction
-- the following function hasn't really been needed since Burning Crusade xPac v2.03..
-- but might (not likely) be needed in the future.
function CensusPlus_GetFactionClasses(faction)
-- this is last in first out list... add new classes to front of list.
local ret = {};
if (faction == CENSUSPlus_HORDE) then
ret = { CENSUSPLUS_WARRIOR, CENSUSPLUS_PALADIN, CENSUSPLUS_HUNTER, CENSUSPLUS_ROGUE, CENSUSPLUS_PRIEST,
CENSUSPLUS_SHAMAN,
CENSUSPLUS_MAGE, CENSUSPLUS_WARLOCK, CENSUSPLUS_DRUID, CENSUSPLUS_DEATH_KNIGHT };
elseif (faction == CENSUSPlus_ALLIANCE) then
ret = { CENSUSPLUS_WARRIOR, CENSUSPLUS_PALADIN, CENSUSPLUS_HUNTER, CENSUSPLUS_ROGUE, CENSUSPLUS_PRIEST,
CENSUSPLUS_SHAMAN, CENSUSPLUS_MAGE, CENSUSPLUS_WARLOCK, CENSUSPLUS_DRUID, CENSUSPLUS_DEATH_KNIGHT };
end
return ret;
end
-- Return a table of classes for the input race
local function GetRaceClasses(race)
local ret = {};
if (race == CENSUSPLUS_ORC) then
ret = { CENSUSPLUS_WARRIOR, CENSUSPLUS_HUNTER, CENSUSPLUS_ROGUE, CENSUSPLUS_SHAMAN, CENSUSPLUS_WARLOCK,
CENSUSPLUS_DEATH_KNIGHT }
elseif (race == CENSUSPLUS_TAUREN) then
ret = { CENSUSPLUS_WARRIOR, CENSUSPLUS_HUNTER, CENSUSPLUS_SHAMAN, CENSUSPLUS_DRUID, CENSUSPLUS_DEATH_KNIGHT }
elseif (race == CENSUSPLUS_TROLL) then
ret = { CENSUSPLUS_WARRIOR, CENSUSPLUS_HUNTER, CENSUSPLUS_ROGUE, CENSUSPLUS_PRIEST, CENSUSPLUS_SHAMAN, CENSUSPLUS_MAGE,
CENSUSPLUS_DEATH_KNIGHT }
elseif (race == CENSUSPLUS_UNDEAD) then
ret = { CENSUSPLUS_WARRIOR, CENSUSPLUS_ROGUE, CENSUSPLUS_PRIEST, CENSUSPLUS_MAGE, CENSUSPLUS_WARLOCK,
CENSUSPLUS_DEATH_KNIGHT }
elseif (race == CENSUSPLUS_BLOODELF) then
ret = { CENSUSPLUS_PALADIN, CENSUSPLUS_HUNTER, CENSUSPLUS_ROGUE, CENSUSPLUS_PRIEST, CENSUSPLUS_MAGE, CENSUSPLUS_WARLOCK,
CENSUSPLUS_DEATH_KNIGHT }
elseif (race == CENSUSPLUS_DWARF) then
ret = { CENSUSPLUS_WARRIOR, CENSUSPLUS_PALADIN, CENSUSPLUS_HUNTER, CENSUSPLUS_ROGUE, CENSUSPLUS_PRIEST,
CENSUSPLUS_DEATH_KNIGHT }
elseif (race == CENSUSPLUS_GNOME) then
ret = { CENSUSPLUS_WARRIOR, CENSUSPLUS_ROGUE, CENSUSPLUS_MAGE, CENSUSPLUS_WARLOCK, CENSUSPLUS_DEATH_KNIGHT }
elseif (race == CENSUSPLUS_HUMAN) then
ret = { CENSUSPLUS_WARRIOR, CENSUSPLUS_PALADIN, CENSUSPLUS_ROGUE, CENSUSPLUS_PRIEST, CENSUSPLUS_MAGE,
CENSUSPLUS_WARLOCK, CENSUSPLUS_DEATH_KNIGHT }
elseif (race == CENSUSPLUS_NIGHTELF) then
ret = { CENSUSPLUS_WARRIOR, CENSUSPLUS_HUNTER, CENSUSPLUS_ROGUE, CENSUSPLUS_PRIEST, CENSUSPLUS_DRUID,
CENSUSPLUS_DEATH_KNIGHT }
elseif (race == CENSUSPLUS_DRAENEI) then
ret = { CENSUSPLUS_WARRIOR, CENSUSPLUS_PALADIN, CENSUSPLUS_HUNTER, CENSUSPLUS_PRIEST, CENSUSPLUS_SHAMAN,
CENSUSPLUS_MAGE, CENSUSPLUS_DEATH_KNIGHT }
end
return ret
end
-- Return common letters found in zone names
-- only used for census splitting by zone
local function GetZoneLetters()
return { "a", "e", "i", "o", "u", "z", "y", "w", "mountain", "lands", "gulch", "valley", "basin" }
end
-- Return common letters found in names, may override this for other languages
-- Worst case scenario is to do it for every letter in the alphabet
--[[
see http://www.warcraftrealms.com/forum/viewtopic.php?t=4819&start=40
Advantage: as seen from data sample
removing the last 3 selectors "mkc" returned about same counts as current set..
adding the "mkc" making the selector count the same increased found unique names by %0.17
disavantage: as seen from data sample
current selector will generates a duplicate name hit of 3.27 duplicates /unique name
alternate selector will generate a duplicate name hit of 4.04 duplicates /unique name
shortened alternate will generate duplicate name hit of 3.47 duplicates /unique name
]]
local function GetNameLetters()
return { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z" }
end
local function GetNameLetters1()
return { "a", "e", "r", "i", "n", "o", "l", "s", "t", "h", "d", "u", "m", "k", "c" }
end
local function GetNameLetters2()
return { "a", "e", "i", "o", "u", "z", "y" }
end
local function GetNameLetters3()
return { "a", "e", "r", "i", "n", "o", "l", "s", "t", "h", "d", "u", "m", "k", "c", "y" }
end
-- Called when the main window is shown
function CensusPlus_OnShow() -- referenced by CensusPlusWotlk.xml
-- Initialize if this is the first OnShow event
if g_CensusPlusInitialized and g_VariablesLoaded then
CensusPlus_UpdateView()
end
end
-- Toggle hidden status
function CensusPlus_Toggle()
if CensusPlusWotlk:IsVisible() then
CensusPlusWotlk:Hide()
else
CensusPlusWotlk:Show()
end
end
-- Toggle options pane
-- referenced by CensusPlusWotlk.xml
function CensusPlus_ToggleOptions(self)
PlaySound(856, "Master")
if not InterfaceOptionsFrame:IsShown() then
InterfaceOptionsFrame:Show()
end
InterfaceOptionsFrame_OpenToCategory("CensusPlusWotlk")
-- CensusPlusSetCheckButtonState()
end
-- referenced by CensusPlusWotlk.xml
function CensusPlus_OnLoad(self)
-- Update the version number
CensusPlusText:SetText(
"CensusPlusWotlk v" .. CensusPlus_VERSION
)
CensusPlusText2:SetText(CENSUSPLUS_UPLOAD)
-- Init constant tables
InitConstantTables()
-- Register for events
self:RegisterEvent("ADDON_LOADED")
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
-- Called once on load
-- SLASH_CensusPlusVerbose1 = "/censusverbose";
-- SlashCmdList["CensusPlusVerbose"] = CensusPlus_Verbose_toggle("alter");
SLASH_CensusPlusCMD1 = "/CensusPlus"
SLASH_CensusPlusCMD2 = "/Census+"
SLASH_CensusPlusCMD3 = "/Census"
SlashCmdList["CensusPlusCMD"] = CensusPlus_Command
CensusPlus_CheckForBattleground()
-- Set up an empty frame for updates
local updateFrame = CreateFrame("Frame")
updateFrame:SetScript("OnUpdate", CensusPlus_OnUpdate)
CensusPlusWhoButton:SetScript("OnClick", function(self, button, down)
-- As we have not specified the button argument to SetBindingClick,
-- the binding will be mapped to a LeftButton click.
ManualWho()
end)
end
function InitializeExperimental()
hookWorldClicks = CensusPlus_Database["Info"]["UseWorldFrameClicks"]
if hookWorldClicks then
WorldFrame:HookScript("OnMouseDown", function(self, button)
ManualWho()
end)
WorldFrame:HookScript("OnMouseUp", function(self, button)
ManualWho()
end)
local f = Test or CreateFrame("Frame", "Test", UIParent)
f:HookScript("OnMouseWheel", function(self)
ManualWho()
end)
f:HookScript("OnKeyDown", function(self, button)
ManualWho()
f:SetPropagateKeyboardInput(true)
end)
end
end
function CP_ProcessWhoEvent(query, result, complete)
if (CPp.IsCensusPlusInProgress ~= true) then return end
local numWhoResults = 0
local cpdb_complete_flag = ""
whoquery_answered = true
numWhoResults = C_FriendList.GetNumWhoResults()
if (g_Verbose == true) then
CensusPlus_Msg(
CENSUSPLUS_WHOQUERY .. " " .. query .. ", " .. CENSUSPLUS_FOUND .. " " .. numWhoResults .. cpdb_complete_flag
)
--CensusPlus_Msg(CENSUSPLUS_WHOQUERY.." "..query);
end
if (numWhoResults == 0) then
--print("no results returned")
local whoText = CensusPlus_CreateWhoText(g_CurrentJob)
if whoText and whoText == query then
g_WaitingForWhoUpdate = false
whoquery_active = false
whoquery_answered = false
end
-- remove job from the queue
table.remove(CensusPlus_JobQueue)
return
end
CensusPlus_ProcessWhoResults(result, numWhoResults)
if (numWhoResults > MAX_WHO_RESULTS) then
-- Who list is overflowed, split the query to make the return smaller
local minLevel = g_CurrentJob.m_MinLevel
local maxLevel = g_CurrentJob.m_MaxLevel
local race = g_CurrentJob.m_Race
local class = g_CurrentJob.m_Class
local letter = g_CurrentJob.m_Letter
local zoneLetter = g_CurrentJob.m_zoneLetter
if (minLevel < maxLevel) then
-- The level range is greater than a single level, so split it in half and submit the two jobs
local pivot = math.floor((minLevel + maxLevel) / 2);
local jobLower = CensusPlus_CreateJob(minLevel, pivot, nil, nil, nil)
InsertJobIntoQueue(jobLower)
local jobUpper = CensusPlus_CreateJob(pivot + 1, maxLevel, nil, nil, nil)
InsertJobIntoQueue(jobUpper)
else
-- We cannot split the level range any more
local factionGroup = UnitFactionGroup("player")
local level = minLevel
if (race == nil) then
-- This job does not specify race, so split it that way, making jobs for each race]
local thisFactionRaces =
CensusPlus_GetFactionRaces(factionGroup)
local numRaces = #thisFactionRaces
for i = 1, numRaces, 1 do
local job =
CensusPlus_CreateJob(
level,
level,
thisFactionRaces[i],
nil,
nil,
nil
)
InsertJobIntoQueue(job)
end
else
if (class == nil) then
-- This job does not specify class, so split it that way, making jobs for each class
local thisRaceClasses = GetRaceClasses(race)
local numClasses = #thisRaceClasses
for i = 1, numClasses, 1 do
local job =
CensusPlus_CreateJob(
level,
level,
race,
thisRaceClasses[i],
nil,
nil
)
InsertJobIntoQueue(job)
end
else
useName = CensusPlus_Database["Info"]["UseNameSearch"];
if (letter == nil and useName == true) then
-- There are too many characters with a single level, class and race
local letters = {}
if CP_letterselect == 0 then
letters = GetNameLetters()
elseif CP_letterselect == 1 then
letters = GetNameLetters1()
elseif CP_letterselect == 2 then
letters = GetNameLetters2()
elseif CP_letterselect == 3 then
letters = GetNameLetters3()
end
for i = 1, #letters, 1 do
local job =
CensusPlus_CreateJob(
level,
level,
race,
class,
letters[i],
nil
)
InsertJobIntoQueue(job)
end
else
useZone = CensusPlus_Database["Info"]["UseZoneSearch"];
if (zoneLetter == nil and useZone == true) then
--
-- This job does not specify zone, so split it that way, making more jobs
--
local zoneLetters = GetZoneLetters();
for i = 1, #zoneLetters, 1 do
local job =
CensusPlus_CreateJob(
level,
level,
race,
class,
letter,
zoneLetters[i]
)
InsertJobIntoQueue(job);
end
else
-- There are too many characters with a single level, class, race and letter, give up
local whoText = CensusPlus_CreateWhoText(g_CurrentJob)
if (g_Verbose == true) then
CensusPlus_Msg(format(CENSUSPLUS_TOOMANY, whoText))
end
end
end
end
end
end
end
local whoText = CensusPlus_CreateWhoText(g_CurrentJob)
if whoText == query then
g_WaitingForWhoUpdate = false
end
end
-- CensusPlusWotlk command
function CensusPlus_Command(param)
local jcmdend = 0
local jvalend = 0
local jfolend = 0
local command = nil
local value = nil
local nameval = nil
local followon = nil
local levelon = 0
local _ = nil
if (param ~= nil) then
param = string.lower(param)
_, jcmdend, command = string.find(param, "(%w+)")
if (command == "options") then
CensusPlus_ToggleOptions()
elseif (command == "take") then
CENSUSPLUS_TAKE_OnClick()
elseif (command == "me") then
CensusPlayerOnly = true
CENSUSPLUS_TAKE_OnClick()
elseif (command == "stop") then
CENSUSPLUS_STOPCENSUS()
elseif (command == "serverprune") then
_, jvalend, value = string.find(param, "(%w+)", jcmdend + 1) -- alphanumeric selector used to warn of bad input
if (value ~= nil) then
value = tonumber(value)
if (value ~= nil) then
CENSUSPLUS_PRUNEData(value, 1) -- value isn't a number .. bad user input
else
CENSUSPLUS_PRUNEData(0, 1)
end -- value is nil
else
CENSUSPLUS_PRUNEData(0, 1)
end
elseif (command == "verbose") then
CensusPlus_Verbose_toggle("alter")
elseif (command == "stealth") then
CensusPlus_Stealth_toggle("alter")
elseif (command == "prune") then
_, jvalend, value = string.find(param, "(%w+)", jcmdend + 1) -- alphanumeric selector used to warn of bad input
if (value ~= nil) then
value = tonumber(value)
if (value ~= nil) then
CENSUSPLUS_PRUNEData(value, nil) -- value isn't a number .. bad user input
else
CENSUSPLUS_PRUNEData(30, nil)
end -- value is nil
else
CENSUSPLUS_PRUNEData(30, nil)
end
elseif (command == "timer") then
_, jvalend, value = string.find(param, "(%d+)", jcmdend + 1) -- decimal seletor works here, if bad input just reset timer
if (value ~= nil) then
value = tonumber(value)
end
CensusPlus_TimerSet(self, value, true)
elseif (command == "who") then -- get 2nd term
_, jvalend, nameval = string.find(param, "(%w+)", jcmdend + 1) --alphanumeric selector used to give warning of bad input
if (nameval ~= nil) then -- nameval found non nil
_, jfalend, followon = string.find(param, "(%a+)", jcmdend + 1) -- see if same match is found as alpha only
if (nameval == followon) then -- alpha world so get 3rd term
_, jfalend, followon =
string.find(param, "(%w+)", jvalend + 1) --alphanumeric selector used to give warning of bad input
if (followon == nil) then -- no 3rd term found
CensusPlus_InternalWho(string.lower(nameval), nil) -- 3rd term found
else
levelon = tonumber(followon)
CensusPlus_InternalWho(
string.lower(nameval),
string.lower(levelon)
)
end -- 2nd term is a number -- 3rd term is NOT a number
else
CensusPlus_Msg(CENSUSPLUS_CMDERR_WHO2NUM)
end -- 2nd term is nil -- 2nd term is ""
else
CensusPlus_Msg(CENSUSPLUS_CMDERR_WHO2)
end
elseif (param == "debug") then
if (HortonBug == false) then
chat("Horton puts trunk in Rabbit hole and blows real hard")
HortonChannelSetup()
JoinTemporaryChannel(HortonChannel)
LoggingChat(true)
HortonBug = true
says("Hello HortonChannel")
else
says("Horton turns off the chatlog")
LoggingChat(false)
HortonBug = false
end
else
CensusPlus_DisplayUsage()
end
else
CensusPlus_DisplayUsage()
end
end
function CensusPlus_Verbose(self)
--print(CensusPlus_Database["Info"]["Verbose"])
--print(CensusPlus_PerCharInfo["Verbose"])
if ((CensusPlus_PerCharInfo["Verbose"] == nil) and (CensusPlus_Database["Info"]["Verbose"] == true)) then
CensusPlus_Verbose_toggle("On")
elseif ((CensusPlus_PerCharInfo["Verbose"] == nil) and (CensusPlus_Database["Info"]["Verbose"] == false)) then
CensusPlus_Verbose_toggle("Off")
elseif (CensusPlus_PerCharInfo["Verbose"] == true) then
CensusPlus_Verbose_toggle("On")
elseif (CensusPlus_PerCharInfo["Verbose"] == false) then
CensusPlus_Verbose_toggle("Off")
else
end
end
function CensusPlus_Verbose_toggle(state)
if (state == "alter") then
if (g_Verbose == true) then
g_Verbose = false
CensusPlus_Msg(CENSUSPLUS_VERBOSEOFF)
else
g_Verbose = true
g_stealth = false
CensusPlus_Msg(CENSUSPLUS_VERBOSEON)
end
elseif (state == "On") then
g_Verbose = true
g_stealth = false
if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
CensusPlus_Msg(CENSUSPLUS_VERBOSEON)
end
elseif (state == "Off") then
g_Verbose = false
if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
CensusPlus_Msg(CENSUSPLUS_VERBOSEOFF)
end
end
end
local function CensusPlus_Stealth(self)
--print(CensusPlus_Database["Info"]["Stealth"])
--print(CensusPlus_PerCharInfo["Stealth"])
if ((CensusPlus_PerCharInfo["Stealth"] == nil) and (CensusPlus_Database["Info"]["Stealth"] == true)) then
CensusPlus_Stealth_toggle("On")
elseif ((CensusPlus_PerCharInfo["Stealth"] == nil) and (CensusPlus_Database["Info"]["Stealth"] == false)) then
CensusPlus_Stealth_toggle("Off")
elseif (CensusPlus_PerCharInfo["Stealth"] == true) then
CensusPlus_Stealth_toggle("On")
elseif (CensusPlus_PerCharInfo["Stealth"] == false) then
CensusPlus_Stealth_toggle("Off")
else
end
end
function CensusPlus_Stealth_toggle(state)
if (state == "alter") then
if (g_stealth == true) then
g_stealth = false
CensusPlus_Msg(CENSUSPLUS_STEALTHOFF)
else
g_Verbose = false
CensusPlus_Msg(CENSUSPLUS_STEALTHON)
g_stealth = true
end
elseif (state == "On") then
g_Verbose = false
if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
CensusPlus_Msg(CENSUSPLUS_STEALTHON)
end
g_stealth = true
elseif (state == "Off") then
g_stealth = false
if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
CensusPlus_Msg(CENSUSPLUS_STEALTHOFF)
end
end
end
local function CensusPlus_CensusButtonShown(self)
--print(CensusPlus_Database["Info"]["CensusButtonShown"])
--print(CensusPlus_PerCharInfo["CensusButtonShown"])
if ((CensusPlus_PerCharInfo["CensusButtonShown"] == nil) and (CensusPlus_Database["Info"]["CensusButtonShown"] == true)
) then
CensusPlus_CensusButtonShown_toggle("On")
--_G[CensusButton:GetName().."Text"]:SetText("C+")
elseif (
(CensusPlus_PerCharInfo["CensusButtonShown"] == nil) and (CensusPlus_Database["Info"]["CensusButtonShown"] == false)) then
CensusPlus_CensusButtonShown_toggle("Off")
elseif (CensusPlus_PerCharInfo["CensusButtonShown"] == true) then
--CensusButton:SetText("30")
CensusPlus_CensusButtonShown_toggle("On")
elseif (CensusPlus_PerCharInfo["CensusButtonShown"] == false) then
CensusPlus_CensusButtonShown_toggle("Off")
else
end
end
function CensusPlus_CensusButtonShown_toggle(state)
if (state == "alter") then
if (g_CensusButtonShown == true) then
g_CensusButtonShown = false
CensusPlus_Msg(CENSUSPLUS_CENSUSBUTTONSHOWNOFF)
CensusButtonFrame:Hide()
else
g_CensusButtonShown = true
CensusPlus_Msg(CENSUSPLUS_CENSUSBUTTONSHOWNON)
CensusButtonFrame:Show()
end
elseif (state == "On") then
g_CensusButtonShown = true
if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
CensusPlus_Msg(CENSUSPLUS_CENSUSBUTTONSHOWNON)
end
CensusButtonFrame:Show()
elseif (state == "Off") then
g_CensusButtonShown = false
if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
CensusPlus_Msg(CENSUSPLUS_CENSUSBUTTONSHOWNOFF)
end
CensusButtonFrame:Hide()
end
end
local function CensusPlus_CensusButtonAnimi(self)
--print(CensusPlus_Database["Info"]["CensusButtonAnimi"])
--print(CensusPlus_PerCharInfo["CensusButtonAnimi"])
if ((CensusPlus_PerCharInfo["CensusButtonAnimi"] == nil) and (CensusPlus_Database["Info"]["CensusButtonAnimi"] == true)
) then
CensusPlus_CensusButtonAnimi_toggle("On")
--_G[CensusButton:GetName().."Text"]:SetText("C+")
elseif (
(CensusPlus_PerCharInfo["CensusButtonAnimi"] == nil) and (CensusPlus_Database["Info"]["CensusButtonAnimi"] == false)) then
--print("CensusButtonAnimi 2")
CensusPlus_CensusButtonAnimi_toggle("Off")
elseif (CensusPlus_PerCharInfo["CensusButtonAnimi"] == true) then
--CensusButton:SetText("30")
CensusPlus_CensusButtonAnimi_toggle("On")
elseif (CensusPlus_PerCharInfo["CensusButtonAnimi"] == false) then
CensusPlus_CensusButtonAnimi_toggle("Off")
else
end
end
function CensusPlus_CensusButtonAnimi_toggle(state)
if (state == "alter") then
if (g_CensusButtonAnimi == true) then
g_CensusButtonAnimi = false
CensusPlus_Msg(CENSUSPLUS_CENSUSBUTTONANIMIOFF)
CensusButton:SetNormalFontObject(GameFontNormal)
CensusButton:SetText("C+")
else
g_CensusButtonAnimi = true
CensusPlus_Msg(CENSUSPLUS_CENSUSBUTTONANIMION)
end
--CensusButtonFrame:Show()
elseif (state == "On") then
g_CensusButtonAnimi = true
if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
CensusPlus_Msg(CENSUSPLUS_CENSUSBUTTONANIMION)
end
--CensusButtonFrame:Show()
elseif (state == "Off") then
g_CensusButtonAnimi = false
if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
CensusPlus_Msg(CENSUSPLUS_CENSUSBUTTONANIMIOFF)
end
CensusButton:SetNormalFontObject(GameFontNormal)
CensusButton:SetText("C+")
end
end
function CensusPlus_FinishSound(state)
--print(CensusPlus_Database["Info"]["PlayFinishSound"])
--print(CensusPlus_PerCharInfo["PlayFinishSound"])
if ((CensusPlus_PerCharInfo["PlayFinishSound"] == nil) and (CensusPlus_Database["Info"]["PlayFinishSound"] == true)) then
CensusPlus_FinishSound_toggle("On")
--_G[CensusButton:GetName().."Text"]:SetText("C+")
elseif (
(CensusPlus_PerCharInfo["PlayFinishSound"] == nil) and (CensusPlus_Database["Info"]["PlayFinishSound"] == false)) then
CensusPlus_FinishSound_toggle("Off")
elseif (CensusPlus_PerCharInfo["PlayFinishSound"] == true) then
--CensusButton:SetText("30")
CensusPlus_FinishSound_toggle("On")
elseif (CensusPlus_PerCharInfo["PlayFinishSound"] == false) then
CensusPlus_FinishSound_toggle("Off")
else
end
end
function CensusPlus_FinishSound_toggle(state)
if (state == "alter") then
if (g_PlayFinishSound == true) then
g_PlayFinishSound = false
CensusPlus_Msg(CENSUSPLUS_PLAYFINISHSOUNDOFF)
else
g_PlayFinishSound = true
CensusPlus_Msg(CENSUSPLUS_PLAYFINISHSOUNDON)
end
elseif (state == "On") then
g_PlayFinishSound = true
if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
CensusPlus_Msg(CENSUSPLUS_PLAYFINISHSOUNDON)
end
elseif (state == "Off") then
g_PlayFinishSound = false
if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
CensusPlus_Msg(CENSUSPLUS_PLAYFINISHSOUNDOFF)
end
end
end
-- CensusPlusWotlk Auto Census set flag
local function CensusPlus_SetAutoCensus(self)
--print(CensusPlus_Database["Info"]["AutoCensus"])
--print(CensusPlus_PerCharInfo["AutoCensus"])
if ((CensusPlus_PerCharInfo["AutoCensus"] == nil) and (CensusPlus_Database["Info"]["AutoCensus"] == true)) then