Repository navigation
Expand file tree
/
Copy pathCore.lua
More file actions
5964 lines (4762 loc) · 221 KB
/
Copy pathCore.lua
File metadata and controls
5964 lines (4762 loc) · 221 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
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
--[==[
Copyright ©2022 Samuel Thomas Pain
The contents of this addon, excluding third-party resources, are
copyrighted to their authors with all rights reserved.
This addon is free to use and the authors hereby grants you the following rights:
1. You may make modifications to this addon for private use only, you
may not publicize any portion of this addon.
2. Do not modify the name of this addon, including the addon folders.
3. This copyright notice shall be included in all copies or substantial
portions of the Software.
All rights not explicitly addressed in this license are reserved by
the copyright holders.
]==]--
local addonName, Guildbook = ...
Guildbook.addonLoaded = false
local AceComm = LibStub:GetLibrary("AceComm-3.0")
local LibDeflate = LibStub:GetLibrary("LibDeflate")
local LibSerialize = LibStub:GetLibrary("LibSerialize")
local LCI = LibStub:GetLibrary("LibCraftInfo-1.0")
local Tradeskills = CreateFromMixins(CallbackRegistryMixin);
local Roster = CreateFromMixins(CallbackRegistryMixin);
local Database = CreateFromMixins(CallbackRegistryMixin);
local Character = CreateFromMixins(CallbackRegistryMixin);
local Comms = CreateFromMixins(CallbackRegistryMixin);
---------------------------------------------------------------------------------------------------------------------------------------------------------------
--variables
---------------------------------------------------------------------------------------------------------------------------------------------------------------
local locale = GetLocale()
local L = Guildbook.Locales
Guildbook.PLAYER_FACTION = nil;
local TOOLTIP_DIVIDER_WIDE = "|TInterface/COMMON/UI-TooltipDivider:8:250|t"
Guildbook.PlayerMixin = nil
Guildbook.player = {}
Guildbook.COMMS_DELAY = 0.0
Guildbook.COMM_LOCK_COOLDOWN = 20.0
Guildbook.GUILD_NAME = nil;
Guildbook.Colours = {
Blue = CreateColor(0.1, 0.58, 0.92, 1),
Orange = CreateColor(0.79, 0.6, 0.15, 1),
Yellow = CreateColor(1.0, 0.82, 0, 1),
Green = CreateColor(84/255,174/255,45/255),
LightRed = CreateColor(216/255,69/255,75/255),
BlizzBlue = CreateColor(0,191/255,243/255),
Grey = CreateColor(0.5,0.5,0.5),
}
for class, t in pairs(Guildbook.Data.Class) do
Guildbook.Colours[class] = CreateColor(t.RGB[1], t.RGB[2], t.RGB[3], 1)
end
---------------------------------------------------------------------------------------------------------------------------------------------------------------
--slash commands
---------------------------------------------------------------------------------------------------------------------------------------------------------------
SLASH_GUILDBOOK1 = '/guildbook'
SLASH_GUILDBOOK2 = '/gbk'
SLASH_GUILDBOOK3 = '/gb'
SlashCmdList['GUILDBOOK'] = function(msg)
--print("["..msg.."]")
if msg == 'open' then
GuildbookUI:Show()
elseif GuildbookUI[msg] then
GuildbookUI:OpenTo(msg)
elseif msg == "version" and Guildbook.version then
Guildbook:PrintMessage(Guildbook.version)
elseif msg == "test" then
end
end
--[[
/////////////////////////////////////////////////////////////////
@class Database
the database class provides functions to update the account wide
saved variables and the per character saved variables
whenever a value is changed a callback is triggered
/////////////////////////////////////////////////////////////////
]]
Database:GenerateCallbackEvents({
"OnCharacterTableChanged", -- only this clients UI needs to listen to this
--"OnCharacterTradeskillRecipesChanged", -- and this
"OnPlayerCharacterTableChanged",
"OnPlayerCharacterTradeskillsInfoChanged",
"OnPlayerCharacterTradeskillRecipesChanged",
"OnGuildbookConfigChanged",
})
Database.currentGuildName = nil;
--to save spamming data we use basic queue/timer system, these bool values determine if a callback is queued or not
Database.onCharacterTableChanged_IsTriggered = false;
Database.onPlayerCharacterTableChanged_IsTriggered = false;
Database.onPlayerCharacterTradeskillsInfoChanged_IsTriggered = false;
Database.onPlayerCharacterTradeskillRecipesChanged_IsTriggered = false;
--Database.onCharacterTradeskillRecipesChanged_IsTriggered = false;
function Database:SetupGuildRosterCache()
if type(self.currentGuildName) == "string" then
if type(GUILDBOOK_GLOBAL.GuildRosterCache) == "table" then
if not GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName] then
GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName] = {}
Guildbook.DEBUG("databaseMixin", "SetupGuildRosterCache", string.format("set up cache for %s", self.currentGuildName))
end
end
end
end
function Database:UpdateGuildbookConfig(setting, newValue)
--DevTools_Dump({setting, newValue})
if GUILDBOOK_GLOBAL then
if GUILDBOOK_GLOBAL.config then
if GUILDBOOK_GLOBAL.config[setting] ~= nil then
GUILDBOOK_GLOBAL.config[setting] = newValue;
Guildbook.DEBUG("databaseMixin", "Database:UpdateGuildbookConfig", string.format("set %s to new value %s", setting, tostring(newValue)))
self:TriggerEvent("OnGuildbookConfigChanged", self, GUILDBOOK_GLOBAL.config)
else
GUILDBOOK_GLOBAL.config[setting] = newValue;
Guildbook.DEBUG("databaseMixin", "Database:UpdateGuildbookConfig", string.format("created new config setting for %s set value as %s", setting, tostring(newValue)))
self:TriggerEvent("OnGuildbookConfigChanged", self, GUILDBOOK_GLOBAL.config)
end
end
end
end
function Database:DeleteCharacterFromCache(guid, character)
if self.currentGuildName and GUILDBOOK_GLOBAL and GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName] and GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName][guid] then
Guildbook.DEBUG("databaseMixin", "Database:DeleteCharacterFromCache", string.format("deleting character %s", character.Name or "unknown character"), character)
GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName][guid] = nil;
end
end
function Database:CharacterExists(guid)
if self.currentGuildName and GUILDBOOK_GLOBAL and GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName] and GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName][guid] then
return true;
end
return false;
end
function Database:FindCharacterAlts(guid)
local alts = {};
if self.currentGuildName and GUILDBOOK_GLOBAL and GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName] then
for _guid, character in pairs(GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName]) do
if character.MainCharacter == guid then
table.insert(alts, character)
end
end
end
return alts;
end
function Database:AddNewCharacter(guid, nameRealm, level, class, race, gender, publicNote, rankName)
if self.currentGuildName and GUILDBOOK_GLOBAL and GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName] then
local character = {
Name = Ambiguate(nameRealm, "none"),
Class = class,
Level = level,
Race = race,
Gender = gender,
PublicNote = publicNote,
OfficerNote = "",
RankName = rankName,
MainSpec = '-',
OffSpec = '-',
MainSpecIsPvP = false,
OffSpecIsPvP = false,
Profession1 = '-',
Profession1Level = 0,
Profession2 = '-',
Profession2Level = 0,
FishingLevel = 0,
CookingLevel = 0,
FirstAidLevel = 0,
MainCharacter = '-',
Availability = {
Monday = nil,
Tuesday = nil,
Wednesday = nil,
Thursday = nil,
Friday = nil,
Saturday = nil,
Sunday = nil,
},
CalendarEvents = {},
Talents = {
primary = {},
},
PaperDollStats = {
Current = {},
},
Inventory = {
Current = {},
},
profile = {},
Alts = {},
}
GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName][guid] = character;
Guildbook.DEBUG("databaseMixin", "AddNewCharacter", string.format(">>> added %s", nameRealm))
end
end
---update a character table in the account wide saved var (guild roster cache) - t[guid][key] = info
---@param guid string the target character guid - used as a key
---@param key string the field to update
---@param info any the new data to set
function Database:UpdateCharacterTable(guid, key, info)
if self.currentGuildName and GUILDBOOK_GLOBAL and GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName] and GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName][guid] then
local characterTable = GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName][guid];
characterTable[key] = info;
Guildbook.DEBUG("databaseMixin", "Database:UpdateCharacterTable", string.format("updated %s for %s", key, characterTable.Name), info)
---to avoid multiple triggers we add a small queue system
if self.onCharacterTableChanged_IsTriggered == false then
C_Timer.After(1.5, function()
self:TriggerEvent("OnCharacterTableChanged", self, guid, characterTable)
self.onCharacterTableChanged_IsTriggered = false;
end)
self.onCharacterTableChanged_IsTriggered = true;
end
end
end
---a specific function to be used during the roster scan that takes in basic character info and updates in 1 go
---@param rankName any
---@param level any
---@param race any
---@param gender any
---@param publicNote any
function Database:UpdateCharacterTable_RosterScan(guid, rankName, level, race, gender, publicNote)
if self.currentGuildName and GUILDBOOK_GLOBAL and GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName] and GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName][guid] then
local characterTable = GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName][guid];
characterTable.RankName = rankName;
characterTable.Race = race;
characterTable.Level = tonumber(level);
characterTable.PublicNote = publicNote;
characterTable.Gender = gender;
-- Guildbook.DEBUG("databaseMixin", "Database:UpdateCharacterTable_RosterScan", string.format("updated %s", characterTable.Name), {
-- ["rank"] = rankName,
-- ["level"] = level,
-- ["race"] = race,
-- ["gender"] = gender,
-- ["public note"] = publicNote,
-- })
end
end
function Database:UpdateCharacterTradeskillRecipes(guid, tradeskill, recipes)
if self.currentGuildName and GUILDBOOK_GLOBAL and GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName] and GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName][guid] then
local characterTable = GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName][guid];
characterTable[tradeskill] = recipes;
Guildbook.DEBUG("databaseMixin", "Database:UpdateCharacterTradeskillRecipes", string.format("updated %s for %s", tradeskill, characterTable.Name), recipes)
---this function should be moved into the tradeskill class and possibly re worked ???
Guildbook:RequestTradeskillData()
end
end
---fetch character info using guid and key
---@param guid string the characters GUID
---@param key string the key to fetch
---@return any
function Database:GetCharacterInfo(guid, key)
if self.currentGuildName and GUILDBOOK_GLOBAL and GUILDBOOK_GLOBAL['GuildRosterCache'] and GUILDBOOK_GLOBAL['GuildRosterCache'][self.currentGuildName] and GUILDBOOK_GLOBAL['GuildRosterCache'][self.currentGuildName][guid] then
local characterName = GUILDBOOK_GLOBAL['GuildRosterCache'][self.currentGuildName][guid].Name
Guildbook.DEBUG("databaseMixin", "Database:GetCharacterInfo", string.format("found %s for %s", key, characterName), {
character = characterName,
key = key,
value = GUILDBOOK_GLOBAL['GuildRosterCache'][self.currentGuildName][guid][key],
})
return GUILDBOOK_GLOBAL['GuildRosterCache'][self.currentGuildName][guid][key];
else
--local characterName = GUILDBOOK_GLOBAL['GuildRosterCache'][self.currentGuildName][guid].Name or "no name or character table"
Guildbook.DEBUG("databaseMixin", "Database:GetCharacterInfo", string.format("unable to find %s", key))
return false;
end
return false;
end
function Database:FetchCharacterTableByGUID(guid)
if type(guid) ~= "string" then
Guildbook.DEBUG("databaseMixin", "Database:FetchCharacterTableByGUID", "guid is not of type string", {guid = guid})
return;
end
--removed the debug here as it can be spammy
if self.currentGuildName and GUILDBOOK_GLOBAL and GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName] and GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName][guid] then
--Guildbook.DEBUG("databaseMixin", "Database:FetchCharacterTableByGUID", string.format("found character table for %s", GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName][guid].Name))
return GUILDBOOK_GLOBAL.GuildRosterCache[self.currentGuildName][guid];
elseif guid:find("Player-") then
local localizedClass, englishClass, localizedRace, englishRace, sex, name, realm = GetPlayerInfoByGUID(guid)
Guildbook.DEBUG("databaseMixin", "Database:FetchCharacterTableByGUID", string.format("unable to find character table for %s-%s", name or "no-name", realm or "no-realm"))
return false;
end
return false;
end
--- THIS WAS SUCH A DUMB IDEA AND I DO NOT KNOW WHY I DID IT THIS WAY AS A BETTER OPTION WOULD BE t[key][tab] !!!!!!!!!!!!!!!!!!!!!!!
--- so this next function is kinda backwards atm, i should fix it but meh
---update the per character saved variable table
---@param key string the table key to update
---@param info any the new value
---@param tab string optional, a child table of GUILDBOOK_CHARACTER to update, ie GUILDBOOK_CHARACTER[tab][key] = info
function Database:UpdatePlayerCharacterTable(key, info, tab)
if not GUILDBOOK_CHARACTER then
GUILDBOOK_CHARACTER = Guildbook.Data.DefaultCharacterSettings;
end
local t = nil;
if type(tab) ~= "string" then
t = GUILDBOOK_CHARACTER;
Guildbook.DEBUG("databaseMixin", "Database:UpdatePlayerCharacterTable", "using the GUILDBOOK_CHARACTER table")
else
if GUILDBOOK_CHARACTER[tab] then
if type(GUILDBOOK_CHARACTER[tab]) == "table" then
t = GUILDBOOK_CHARACTER[tab];
Guildbook.DEBUG("databaseMixin", "Database:UpdatePlayerCharacterTable", string.format("using GUILDBOOK_CHARACTER[%s] table", tab))
else
GUILDBOOK_CHARACTER[tab] = {}
t = GUILDBOOK_CHARACTER[tab];
Guildbook.DEBUG("databaseMixin", "Database:UpdatePlayerCharacterTable", string.format("GUILDBOOK_CHARACTER[%s] table did NOT exists, created and using new table", tab))
end
else
GUILDBOOK_CHARACTER[tab] = {};
t = GUILDBOOK_CHARACTER[tab];
Guildbook.DEBUG("databaseMixin", "Database:UpdatePlayerCharacterTable", string.format("%s does NOT exist, created GUILDBOOK_CHARACTER[%s] table", tab, tab))
end
end
if type(t) ~= "table" then
Guildbook.DEBUG("databaseMixin", "Database:UpdatePlayerCharacterTable", string.format("table not found for key: %s, opt tab: %s > db update cancelled", key, tab or "-"), {
["key"] = key,
["info"] = info,
["tab"] = tab or "-",
})
return;
end
if t then
t[key] = nil;
t[key] = info;
Guildbook.DEBUG("databaseMixin", "Database:UpdatePlayerCharacterTable", string.format("set or updated %s", key), info)
---to avoid multiple triggers in < 1s we add a small queue system
if self.onPlayerCharacterTableChanged_IsTriggered == false then
C_Timer.After(3.0, function()
self:TriggerEvent("OnPlayerCharacterTableChanged", self, GUILDBOOK_CHARACTER)
self.onPlayerCharacterTableChanged_IsTriggered = false;
end)
self.onPlayerCharacterTableChanged_IsTriggered = true;
end
end
end
function Database:UpdatePlayerCharacterTradeskillsInfo(prof1, prof1Level, prof1Spec, prof2, prof2Level, prof2Spec, fishing, cooking, firstAid)
if not GUILDBOOK_CHARACTER then
GUILDBOOK_CHARACTER = Guildbook.Data.DefaultCharacterSettings;
end
if type(prof1) == "string" then
GUILDBOOK_CHARACTER.Profession1 = prof1;
end
if type(prof1Level) == "number" then
GUILDBOOK_CHARACTER.Profession1Level = prof1Level;
end
if type(prof1Spec) == "number" then
GUILDBOOK_CHARACTER.Profession1Spec = prof1Spec;
end
if type(prof2) == "string" then
GUILDBOOK_CHARACTER.Profession2 = prof2;
end
if type(prof2Level) == "number" then
GUILDBOOK_CHARACTER.Profession2Level = prof2Level;
end
if type(prof2Spec) == "number" then
GUILDBOOK_CHARACTER.Profession2Spec = prof2Spec;
end
if type(fishing) == "number" then
GUILDBOOK_CHARACTER.FishingLevel = fishing;
end
if type(cooking) == "number" then
GUILDBOOK_CHARACTER.CookingLevel = cooking;
end
if type(firstAid) == "number" then
GUILDBOOK_CHARACTER.FirstAidLevel = firstAid;
end
Guildbook.DEBUG("databaseMixin", "Database:UpdatePlayerCharacterTradeskillsInfo", "updated player character tradeskills info", {prof1, prof1Level, prof1Spec, prof2, prof2Level, prof2Spec, fishing, cooking, firstAid})
---to avoid multiple triggers we use a queue system, as players could power level professions lets increase the queue timer to 10s
if self.onPlayerCharacterTradeskillsInfoChanged_IsTriggered == false then
C_Timer.After(10.0, function()
self:TriggerEvent("OnPlayerCharacterTradeskillsInfoChanged", self)
self.onPlayerCharacterTradeskillsInfoChanged_IsTriggered = false;
end)
self.onPlayerCharacterTradeskillsInfoChanged_IsTriggered = true;
end
end
function Database:UpdatePlayerCharacterTradeskillRecipes(prof, recipes)
if not GUILDBOOK_CHARACTER then
GUILDBOOK_CHARACTER = Guildbook.Data.DefaultCharacterSettings;
end
GUILDBOOK_CHARACTER[prof] = recipes;
Guildbook.DEBUG("databaseMixin", "Database:UpdatePlayerCharacterTradeskillRecipes", string.format("updated or set recipes for %s", prof), recipes)
---to avoid multiple triggers we use a queue system, as players could power level professions lets increase the queue timer to 10s
if self.onPlayerCharacterTradeskillRecipesChanged_IsTriggered == false then
C_Timer.After(10.0, function()
self:TriggerEvent("OnPlayerCharacterTradeskillRecipesChanged", self, prof) --we just need the prof name to use to find the data
self.onPlayerCharacterTradeskillRecipesChanged_IsTriggered = false;
end)
self.onPlayerCharacterTradeskillRecipesChanged_IsTriggered = true;
end
end
function Database:Init()
CallbackRegistryMixin.OnLoad(self)
---setup the UI callback
self:RegisterCallback("OnCharacterTableChanged", GuildbookUI.OnCharacterTableChanged, GuildbookUI)
-- the database MUST always use the players guild NOT whatever guild is being viewed
if IsInGuild() and GetGuildInfo("player") then
local guildName, _, _, _ = GetGuildInfo('player')
self.currentGuildName = guildName;
self:SetupGuildRosterCache()
end
-- self.listener = CreateFrame("FRAME")
-- self.listener:SetScript("OnEvent", function(_, event, ...)
-- end)
end
Guildbook.Database = Database;
--[[
/////////////////////////////////////////////////////////////////
@class Classes
this class would be used to handle info etc for the character classes, textures, spec names, icons, colours etc
/////////////////////////////////////////////////////////////////
]]
local Classes = {}
Classes.Specializations = {
["DEATHKNIGHT"] = {
{
["Frost (DPS)"] = {
role = "DPS",
talentBackground = "DeathKnightFrost",
atlas = "",
},
["Frost (Tank)"] = {
role = "DPS",
talentBackground = "DeathKnightFrost"
},
["Blood"] = {
role = "Tank",
talentBackground = "DeathKnightBlood"
},
["Unholy"] = {
role = "DPS",
talentBackground = "DeathKnightUnholy"
},
},
},
}
--[[
/////////////////////////////////////////////////////////////////
@class Tradeskills
/////////////////////////////////////////////////////////////////
]]
--local Tradeskills = {}
Tradeskills:GenerateCallbackEvents({
"OnRecipeItemDataReceived", --hmm?
});
Tradeskills.CurrentLocale = GetLocale()
Tradeskills.TradeskillNames = {
["Alchemy"] = 171,
["Blacksmithing"] = 164,
["Enchanting"] = 333,
["Engineering"] = 202,
["Inscription"] = 773,
["Jewelcrafting"] = 755,
["Leatherworking"] = 165,
["Tailoring"] = 197,
["Mining"] = 186,
["Herbalism"] = 182,
["Skinning"] = 393,
["Cooking"] = 185,
}
Tradeskills.SpecializationSpellsIDs = {
--Alchemy:
[28672] = 171,
[28677] = 171,
[28675] = 171,
--Engineering:
[20222] = 202,
[20219] = 202,
--Tailoring:
[26798] = 197,
[26797] = 197,
[26801] = 197,
--Blacksmithing:
[9788] = 164,
[17039] = 164,
[17040] = 164,
[17041] = 164,
[9787] = 164,
--Leatherworking:
[10656] = 165,
[10658] = 165,
[10660] = 165,
}
Tradeskills.TradeskillIDsToLocaleName = {
enUS = {
[164] = "Blacksmithing",
[165] = "Leatherworking",
[171] = "Alchemy",
[182] = "Herbalism",
[185] = "Cooking",
[186] = "Mining",
[197] = "Tailoring",
[202] = "Engineering",
[333] = "Enchanting",
[356] = "Fishing",
[393] = "Skinning",
[755] = "Jewelcrafting",
[773] = "Inscription",
[129] = "First Aid"
},
deDE = {
[164] = "Schmiedekunst",
[165] = "Lederverarbeitung",
[171] = "Alchimie",
[182] = "Kräuterkunde",
[185] = "Kochkunst",
[186] = "Bergbau",
[197] = "Schneiderei",
[202] = "Ingenieurskunst",
[333] = "Verzauberkunst",
[356] = "Angeln",
[393] = "Kürschnerei",
[755] = "Juwelenschleifen",
[773] = "Inschriftenkunde",
[129] = "Erste Hilfe",
},
frFR = {
[164] = "Forge",
[165] = "Travail du cuir",
[171] = "Alchimie",
[182] = "Herboristerie",
[185] = "Cuisine",
[186] = "Minage",
[197] = "Couture",
[202] = "Ingénierie",
[333] = "Enchantement",
[356] = "Pêche",
[393] = "Dépeçage",
[755] = "Joaillerie",
[773] = "Calligraphie",
[129] = "Secourisme",
},
esMX = {
[164] = "Herrería",
[165] = "Peletería",
[171] = "Alquimia",
[182] = "Herboristería",
[185] = "Cocina",
[186] = "Minería",
[197] = "Sastrería",
[202] = "Ingeniería",
[333] = "Encantamiento",
[356] = "Pesca",
[393] = "Desuello",
[755] = "Joyería",
[773] = "Inscripción",
[129] = "Primeros auxilios",
},
-- discovered this locale exists also maybe esAL ?
esES = {
[164] = "Herrería",
[165] = "Peletería",
[171] = "Alquimia",
[182] = "Herboristería",
[185] = "Cocina",
[186] = "Minería",
[197] = "Sastrería",
[202] = "Ingeniería",
[333] = "Encantamiento",
[356] = "Pesca",
[393] = "Desuello",
[755] = "Joyería",
[773] = "Inscripción",
[129] = "Primeros auxilios",
},
ptBR = {
[164] = "Ferraria",
[165] = "Couraria",
[171] = "Alquimia",
[182] = "Herborismo",
[185] = "Culinária",
[186] = "Mineração",
[197] = "Alfaiataria",
[202] = "Engenharia",
[333] = "Encantamento",
[356] = "Pesca",
[393] = "Esfolamento",
[755] = "Joalheria",
[773] = "Escrivania",
[129] = "Primeiros Socorros",
},
ruRU = {
[164] = "Кузнечное дело",
[165] = "Кожевничество",
[171] = "Алхимия",
[182] = "Травничество",
[185] = "Кулинария",
[186] = "Горное дело",
[197] = "Портняжное дело",
[202] = "Инженерное дело",
[333] = "Наложение чар",
[356] = "Рыбная ловля",
[393] = "Снятие шкур",
[755] = "Ювелирное дело",
[773] = "Начертание",
[129] = "Первая помощь",
},
zhCN = {
[164] = "锻造",
[165] = "制皮",
[171] = "炼金术",
[182] = "草药学",
[185] = "烹饪",
[186] = "采矿",
[197] = "裁缝",
[202] = "工程学",
[333] = "附魔",
[356] = "钓鱼",
[393] = "剥皮",
[755] = "珠宝加工",
[773] = "铭文",
[129] = "急救",
},
zhTW = {
[164] = "鍛造",
[165] = "製皮",
[171] = "鍊金術",
[182] = "草藥學",
[185] = "烹飪",
[186] = "採礦",
[197] = "裁縫",
[202] = "工程學",
[333] = "附魔",
[356] = "釣魚",
[393] = "剝皮",
[755] = "珠寶設計",
[773] = "銘文學",
[129] = "急救", --Worked on PTR -Belrand
},
koKR = {
[164] = "대장기술",
[165] = "가죽세공",
[171] = "연금술",
[182] = "약초채집",
[185] = "요리",
[186] = "채광",
[197] = "재봉술",
[202] = "기계공학",
[333] = "마법부여",
[356] = "낚시",
[393] = "무두질",
[755] = "보석세공",
[773] = "주문각인",
[129] = "응급치료",
},
}
Tradeskills.TradeskillLocaleNameToID = tInvert(Tradeskills.TradeskillIDsToLocaleName[Tradeskills.CurrentLocale])
function Tradeskills:GetEnglishNameFromID(tradeskillID)
if self.TradeskillIDsToLocaleName.enUS[tradeskillID] then
return self.TradeskillIDsToLocaleName.enUS[tradeskillID];
end
end
function Tradeskills:GetEnglishNameFromTradeskillName(tradeskillName)
local tradeskillID = self.TradeskillLocaleNameToID[tradeskillName]
if tradeskillID then
local tradeskill = self:GetEnglishNameFromID(tradeskillID)
return tostring(tradeskill);
end
return false;
end
function Tradeskills:RequestRecipeInfo()
end
function Tradeskills:FindCharactersWithRecipe(recipe)
local charactersWithRecipe = {}
local sorting = {}
if recipe.enchant == true then
for k, guid in ipairs(Guildbook.charactersWithEnchantRecipe[recipe.itemID]) do
table.insert(sorting, {
guid = guid,
online = Roster.onlineStatus[guid].isOnline and 1 or 0,
})
end
else
for k, guid in ipairs(Guildbook.charactersWithRecipe[recipe.itemID]) do
table.insert(sorting, {
guid = guid,
online = Roster.onlineStatus[guid].isOnline and 1 or 0,
})
end
end
table.sort(sorting, function(a,b)
return a.online > b.online
end)
for k, character in ipairs(sorting) do
table.insert(charactersWithRecipe, character.guid)
end
return charactersWithRecipe;
end
---load the characters tradeskills, currently this is triggered by the new home tab member listview
---@param prof string the profession to load recipes for or `allRecipes` for all of the characters recipes
---@param character table optional character table to use, overrides the guid arg
function Tradeskills:LoadGuildMemberTradeskills(prof, character)
--hide the selected texture and flush the listviews
for _, button in ipairs(GuildbookTradeskillProfessionListview.profButtons) do
button.selected:Hide()
end
GuildbookUI.tradeskills.tradeskillItemsListview.DataProvider:Flush()
GuildbookUI.tradeskills.tradeskillItemsCharacterListview.DataProvider:Flush()
if prof == "Enchanting" then
if not Guildbook.tradeskillEnchantRecipesKeys then
return;
end
if next(Guildbook.tradeskillEnchantRecipesKeys) == nil then
GuildbookUI:SetInfoText("tradeskill enchant recipes not processed yet, key mapping not ready")
return
end
else
if not Guildbook.tradeskillRecipesKeys then
return;
end
if next(Guildbook.tradeskillRecipesKeys) == nil then
GuildbookUI:SetInfoText("tradeskill recipes not processed yet, key mapping not ready")
return
end
end
if type(character) ~= "table" then
return
end
if prof == "Enginnering" then prof = "Engineering" end -- fix it back due to blizz spelling error
local recipes = {}
if prof ~= "allRecipes" and character[prof] then
for itemID, _ in pairs(character[prof]) do
if prof == "Enchanting" then
local key = Guildbook.tradeskillEnchantRecipesKeys[itemID]
table.insert(recipes, Guildbook.tradeskillRecipes[key])
else
local key = Guildbook.tradeskillRecipesKeys[itemID]
table.insert(recipes, Guildbook.tradeskillRecipes[key])
end
end
---if no prof is given then load all the characters recipes
elseif prof == "allRecipes" then
local prof1 = character.Profession1
if prof1 and character[prof1] then
for itemID, _ in pairs(character[prof1]) do
if prof1 == "Enchanting" then
local key = Guildbook.tradeskillEnchantRecipesKeys[itemID]
table.insert(recipes, Guildbook.tradeskillRecipes[key])
else
local key = Guildbook.tradeskillRecipesKeys[itemID]
table.insert(recipes, Guildbook.tradeskillRecipes[key])
end
end
end
local prof2 = character.Profession2
if prof2 and character[prof2] then
for itemID, _ in pairs(character[prof2]) do
if prof2 == "Enchanting" then
local key = Guildbook.tradeskillEnchantRecipesKeys[itemID]
table.insert(recipes, Guildbook.tradeskillRecipes[key])
else
local key = Guildbook.tradeskillRecipesKeys[itemID]
table.insert(recipes, Guildbook.tradeskillRecipes[key])
end
end
end
end
if recipes and next(recipes) ~= nil then
GuildbookUI:SetInfoText(string.format("found %s recipes for %s [%s]", #recipes, prof, character.Name))
table.sort(recipes, function(a,b)
if type(a.expansion) ~= "number" and type(b.expansion) ~= "number" then
return a.rarity > b.rarity;
end
if a.expansion == b.expansion then
if a.rarity == b.rarity then
return a.name < b.name
else
return a.rarity > b.rarity
end
else
return a.expansion > b.expansion
end
end)
GuildbookUI.tradeskills.tradeskillItemsListview.DataProvider:InsertTable(recipes)
-- the items in this list need to be changed to take a character name
--GuildbookUI.tradeskills.tradeskillItemsCharacterListview.DataProvider:InsertTable({guid}) -- why?
end
GuildbookUI:OpenTo("tradeskills")
end
function Tradeskills:Init()
CallbackRegistryMixin.OnLoad(self)
end
Guildbook.Tradeskills = Tradeskills;
--[[
/////////////////////////////////////////////////////////////////
@class Roster
/////////////////////////////////////////////////////////////////
]]
--local Roster = CreateFromMixins(CallbackRegistryMixin)
Roster:GenerateCallbackEvents({
"OnGuildRosterScan",
"OnMemberStatusChanged",
"OnMemberJoin",
"OnMemberLeave",
"OnGuildSelectionChanged",
})
Roster.currentPlayerRealm = nil;
Roster.currentGuildName = nil;
Roster.onlineStatus = {};
Roster.guidToCharacterNameRealm = {}; --?
Roster.characterNameRealmToGUID = {}; --?
Roster.scanMembersTicker = nil;
Roster.scanMembersTickerActive = false;
function Roster:ScanMembers()