-
Notifications
You must be signed in to change notification settings - Fork 2
/
Generalist.lua
executable file
·2250 lines (1748 loc) · 70.7 KB
/
Generalist.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
require "Window"
require "GameLib"
require "PlayerPathLib"
require "Item"
require "Money"
-- Module Definition
local Generalist = {}
-- Constants
local kcrEnabledColor = ApolloColor.new("UI_BtnTextHoloNormal")
local kcrDisabledColor = ApolloColor.new("Disabled")
local kstrToolTip = "<P Font=\"CRB_InterfaceSmall\" TextColor=\"white\">%s</P>"
-- Maps the SlotId from the CharacterUI to the string representation.
local karrSlotIdToString = {
[0] = "ChestSlot",
[1] = "LegsSlot",
[2] = "HeadSlot",
[3] = "ShoulderSlot",
[4] = "FeetSlot",
[5] = "HandsSlot",
[6] = "ToolSlot",
[7] = "AttachmentSlot",
[8] = "SupportSlot",
[10] = "ImplantSlot",
[11] = "GadgetSlot",
[15] = "ShieldSlot",
[16] = "WeaponSlot",
[17] = "BagSlot0",
[18] = "BagSlot1",
[19] = "BagSlot2",
[20] = "BagSlot3",
}
local karrClassToIcon =
{
[GameLib.CodeEnumClass.Warrior] = "IconSprites:Icon_Windows_UI_CRB_Warrior",
[GameLib.CodeEnumClass.Engineer] = "IconSprites:Icon_Windows_UI_CRB_Engineer",
[GameLib.CodeEnumClass.Esper] = "IconSprites:Icon_Windows_UI_CRB_Esper",
[GameLib.CodeEnumClass.Medic] = "IconSprites:Icon_Windows_UI_CRB_Medic",
[GameLib.CodeEnumClass.Stalker] = "IconSprites:Icon_Windows_UI_CRB_Stalker",
[GameLib.CodeEnumClass.Spellslinger] = "IconSprites:Icon_Windows_UI_CRB_Spellslinger",
}
local karrClassToString =
{
[GameLib.CodeEnumClass.Warrior] = "Warrior",
[GameLib.CodeEnumClass.Engineer] = "Engineer",
[GameLib.CodeEnumClass.Esper] = "Esper",
[GameLib.CodeEnumClass.Medic] = "Medic",
[GameLib.CodeEnumClass.Stalker] = "Stalker",
[GameLib.CodeEnumClass.Spellslinger] = "Spellslinger",
}
local karrPathToIcon = {
[PlayerPathLib.PlayerPathType_Explorer] = "CRB_PlayerPathSprites:spr_Path_Explorer_Stretch",
[PlayerPathLib.PlayerPathType_Soldier] = "CRB_PlayerPathSprites:spr_Path_Soldier_Stretch",
[PlayerPathLib.PlayerPathType_Settler] = "CRB_PlayerPathSprites:spr_Path_Settler_Stretch",
[PlayerPathLib.PlayerPathType_Scientist] = "CRB_PlayerPathSprites:spr_Path_Scientist_Stretch",
}
local karrPathToString = {
[PlayerPathLib.PlayerPathType_Explorer] = Apollo.GetString("PlayerPathExplorer"),
[PlayerPathLib.PlayerPathType_Soldier] = Apollo.GetString("PlayerPathSoldier"),
[PlayerPathLib.PlayerPathType_Settler] = Apollo.GetString("PlayerPathSettler"),
[PlayerPathLib.PlayerPathType_Scientist] = Apollo.GetString("PlayerPathScientist"),
}
local karrCurrency =
{
{
eType = Money.CodeEnumCurrencyType.Renown,
strTitle = Apollo.GetString("CRB_Renown"),
strDescription = Apollo.GetString("CRB_Renown_Desc")
},{
eType = Money.CodeEnumCurrencyType.ElderGems,
strTitle = Apollo.GetString("CRB_Elder_Gems"),
strDescription = Apollo.GetString("CRB_Elder_Gems_Desc")
},{
eType = Money.CodeEnumCurrencyType.Prestige,
strTitle = Apollo.GetString("CRB_Prestige"),
strDescription = Apollo.GetString("CRB_Prestige_Desc")
},{
eType = Money.CodeEnumCurrencyType.CraftingVouchers,
strTitle = Apollo.GetString("CRB_Crafting_Vouchers"),
strDescription = Apollo.GetString("CRB_Crafting_Voucher_Desc")
}
}
local ktContractStatus = {
Available = 0,
Accepted = 1,
Achieved = 2,
Completed = 3,
}
local origItemToolTipForm = nil
-- Mapping of recipes whose names don't match the items they create.
-- The key is the ID of the recipe item; the value is the correct title of the item
-- created by the recipe.
--
local kGenBogusRecipes = {
[18761] = 'Spider Stir Fry',
[29632] = 'Enhanced Spider Stir-Fry',
-- Reported by one of our users, but Jabbithole's info on these is weird
-- so I want to corroborate.
--
-- [36086] = 'Galeras Adaptive Vanguard System',
-- [36085] = 'Galehorn Roanhide Chaps',
}
-----------------------------------------------------------------------------------------------
-- Initialization
-----------------------------------------------------------------------------------------------
function Generalist:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
o.tItems = {}
o.altData = {}
o.recipeBogus = kGenBogusRecipes
o.wndSelectedListItem = nil
return o
end
function Generalist:Init()
local bHasConfigureFunction = false
local strConfigureButtonText = ""
local tDependencies = {}
Apollo.RegisterAddon(self, bHasConfigureFunction, strConfigureButtonText, tDependencies)
end
-----------------------------------------------------------------------------------------------
-- Generalist OnLoad
-----------------------------------------------------------------------------------------------
function Generalist:OnLoad()
self.xmlDoc = XmlDoc.CreateFromFile("Generalist.xml")
self.version = XmlDoc.CreateFromFile("toc.xml"):ToTable().Version
self.xmlDoc:RegisterCallback("OnDocLoaded", self)
self:HookToolTip()
end
-- Hooks into the ToolTip Addon and adds additional callbacks so we can inject
-- our custom tooltip messages for tracking everything.
function Generalist:HookToolTip()
local TT = Apollo.GetAddon("ToolTips")
if TT == nil then
Print("Sorry, but Generalist managed to load before the ToolTips addon loaded.")
Print("You will not have Generalist information about inventory and alts which can learn schematics embedded in your tooltips.")
Print("Please do /reloadui if you would like to fix this.")
return
end
-- Preserve the original callbacks call
local origCreateCallNames = TT.CreateCallNames
TT.CreateCallNames = function(luaCaller)
origCreateCallNames(luaCaller)
origItemToolTipForm = Tooltip.GetItemTooltipForm
Tooltip.GetItemTooltipForm = function(luaCaller, wndControl, item, bStuff, nCount)
return self.ItemToolTip(luaCaller,wndControl,item,bStuff,nCount)
end
end
end
-----------------------------------------------------------------------------------------------
-- Generalist OnDocLoaded
-----------------------------------------------------------------------------------------------
function Generalist:OnDocLoaded()
if self.xmlDoc ~= nil and self.xmlDoc:IsLoaded() then
-- Set up the main window
self.wndMain = Apollo.LoadForm(self.xmlDoc, "GeneralistForm", nil, self)
if self.wndMain == nil then
Apollo.AddAddonErrorText(self, "Could not load the main window for some reason.")
return
end
-- item list window
self.charList = self.wndMain:FindChild("CharList")
-- keep the main window hidden for now
self.wndMain:Show(false, true)
-- put the version number in the title bar
self.wndMain:FindChild("Backing"):FindChild("Title"):SetText("Generalist v" .. self.version)
-- if the xmlDoc is no longer needed, you should set it to nil
-- self.xmlDoc = nil
-- Register the slash command
Apollo.RegisterSlashCommand("gen", "OnGeneralistOn", self)
-- Register handlers for events, slash commands and timer, etc.
-- e.g. Apollo.RegisterEventHandler("KeyDown", "OnKeyDown", self)
-- Update my info on logout
Apollo.RegisterEventHandler("LogOut", "UpdateCurrentCharacter", self)
-- Get ourselves into the Interface menu
Apollo.RegisterEventHandler("InterfaceMenuListHasLoaded", "OnInterfaceMenuListHasLoaded", self)
Apollo.RegisterEventHandler("ToggleGeneralist", "OnGeneralistOn", self)
-- Update my tradeskills when I learn a new one
Apollo.RegisterEventHandler("TradeskillAchievementComplete", "GetTradeskills", self)
Apollo.RegisterEventHandler("TradeSkills_Learned", "GetTradeskills", self)
Apollo.RegisterEventHandler("CraftingSchematicLearned", "GetTradeskills", self)
-- Update my inventory when I loot stuff
Apollo.RegisterEventHandler("LootedItem", "GetCharInventory", self)
Apollo.RegisterEventHandler("LootedMoney", "GetCharCash", self)
-- Or when other "item" events happen
Apollo.RegisterEventHandler("ItemAdded", "GetCharInventory", self)
Apollo.RegisterEventHandler("ItemRemoved", "GetCharInventory", self)
Apollo.RegisterEventHandler("ItemModified", "GetCharInventory", self)
-- Update my level if I ding
Apollo.RegisterEventHandler("PlayerLevelChange", "GetCharLevel", self)
-- Update my decor if I crate something
Apollo.RegisterEventHandler("ItemSentToCrate", "GetCharDecor", self)
-- Update my dyes if I learn one
Apollo.RegisterEventHandler("DyeLearned", "GetCharDyes", self)
-- Update contracts if something changes
Apollo.RegisterEventHandler("ContractBoardClose", "GetCharContracts", self)
Apollo.RegisterEventHandler("ContractBoardOpen", "GetCharContracts", self)
Apollo.RegisterEventHandler("ContractObjectiveUpdated", "GetCharContracts", self)
Apollo.RegisterEventHandler("ContractStateChanged", "GetCharContracts", self)
-- Register a timer until we can load player info
self.timer = ApolloTimer.Create(2, true, "OnTimer", self)
-- And register for the event of changing worlds so we can restart the timer
Apollo.RegisterEventHandler("ChangeWorld", "OnChangeWorld", self)
end
end
---------------------------------------------------------------------------------------------------
-- Timer function. Used to keep trying to get the player unit on load
-- until GameLib has caught up and we have it.
---------------------------------------------------------------------------------------------------
function Generalist:OnTimer()
-- Get the current character's name
local unitPlayer = GameLib.GetPlayerUnit()
-- Return if nil, because GameLib isn't ready.
if unitPlayer == nil then
return
end
-- If we didn't return, that means we got the player, and it's time to
-- update their info and switch the timer off.
--
self.timer = nil
self:UpdateCurrentCharacter()
end
---------------------------------------------------------------------------------------------------
-- Timer when we change worlds
---------------------------------------------------------------------------------------------------
function Generalist:OnChangeWorld()
-- Restart the timer until we can load player info
self.timer = ApolloTimer.Create(2, true, "OnTimer", self)
end
---------------------------------------------------------------------------------------------------
-- Add us to interface menu
---------------------------------------------------------------------------------------------------
function Generalist:OnInterfaceMenuListHasLoaded()
Event_FireGenericEvent("InterfaceMenuList_NewAddOn", "Generalist",
{"ToggleGeneralist", "", "ChatLogSprites:CombatLogSaveLogBtnNormal"})
end
-----------------------------------------------------------------------------------------------
-- Main slash command (or clicking us in the interface window)
-----------------------------------------------------------------------------------------------
-- on SlashCommand "/gen"
function Generalist:OnGeneralistOn()
-- show the window
self.wndMain:Invoke()
-- populate the character list
self:PopulateCharList()
end
-----------------------------------------------------------------------------------------------
-- Close window button functions. These don't get simpler.
-----------------------------------------------------------------------------------------------
function Generalist:OnCancel()
self.wndMain:Show(false,true)
end
function Generalist:OnDetailClose()
-- Close the detail window
self.wndDetail:Show(false,true)
end
function Generalist:OnSearchClose()
-- Close the search window
self.wndSearch:Show(false,true)
end
function Generalist:OnContractsClose()
-- Close the contracts window
self.wndContracts:Show(false,true)
end
-----------------------------------------------------------------------------------------------
-- Populate list of characters
-----------------------------------------------------------------------------------------------
function Generalist:PopulateCharList()
-- make sure the list is empty to start with
self:DestroyCharList()
-- next, add the current character to the table, and/or update its data
self:UpdateCurrentCharacter()
-- Get the current character's faction
local factID = GameLib.GetPlayerUnit():GetFaction()
-- Build list of characters of this faction
local a = {}
for name in pairs(self.altData) do
-- Only add characters of this faction to the list
if self.altData[name].faction == factID then
table.insert(a, name)
end
end
-- Sort the list (alphabetically)
table.sort(a)
-- Now loop through the faction list and add those characters to the list item.
-- Track total cash and levels as we go.
--
local totalCash = 0
local totalLevel = 0
local cc
local name
for counter, name in ipairs(a) do
self:AddCharToList(name,counter)
-- Add this character's money to the total
if self.altData[name].cash ~= nil then
totalCash = totalCash + self.altData[name].cash
end
-- And level
totalLevel = totalLevel + self.altData[name].level
cc = counter
end
-- Now, add the total cash/levels entry
cc = cc+1
local wnd = Apollo.LoadForm(self.xmlDoc, "CharListEntry", self.charList, self)
self.tItems[cc] = wnd
wnd:FindChild("CharGold"):SetAmount(totalCash,true)
wnd:FindChild("CharLevel"):SetText(totalLevel)
wnd:FindChild("CharName"):SetText("[Total]")
wnd:FindChild("CharClass"):Show(false)
wnd:FindChild("CharPath"):Show(false)
-- now all the chars and total are added,
-- call ArrangeChildrenVert to list out the list items vertically
--
self.charList:ArrangeChildrenVert()
end
-- Clear the character list
--
function Generalist:DestroyCharList()
-- destroy all the wnd inside the list
for idx,wnd in ipairs(self.tItems) do
wnd:Destroy()
end
-- clear the list item array
self.tItems = {}
self.wndSelectedListItem = nil
end
--
-- Add alt's entry into the item list at a particular index
--
function Generalist:AddCharToList(name,i)
-- load the window item for the list item
local wnd = Apollo.LoadForm(self.xmlDoc, "CharListEntry", self.charList, self)
-- keep track of the window item created
self.tItems[i] = wnd
local entry = self.altData[name]
-- give it a piece of data to refer to
local wndItemText = wnd:FindChild("CharName")
if wndItemText then -- make sure the text wnd exist
-- Character's Name
wndItemText:SetText(name) -- set the item wnd's text to alt's name
--wndItemText:SetTextColor(kcrNormalText)
-- Character's Level
wnd:FindChild("CharLevel"):SetText(tostring(entry.level))
-- Character's Class, as icon with tooltip
wnd:FindChild("CharClass"):SetSprite(karrClassToIcon[entry.class])
if karrClassToString[entry.class] ~= nil then
wnd:FindChild("CharClass"):SetTooltip(string.format(kstrToolTip, karrClassToString[entry.class]))
end
-- Character's Gold
if entry.cash ~= nil then
wnd:FindChild("CharGold"):SetAmount(entry.cash, true)
else
wnd:FindChild("CharGold"):Show(false)
end
-- Character's zone
wnd:FindChild("CharZone"):SetText(entry.zone)
-- Character's Path
wnd:FindChild("CharPath"):SetSprite(karrPathToIcon[entry.path])
if karrPathToString[entry.path] ~= nil then
wnd:FindChild("CharPath"):SetTooltip(string.format(kstrToolTip, karrPathToString[entry.path]))
end
end
wnd:SetData(i)
end
-----------------------------------------------------------------------------------------------
-- Add the current character to the data structure and update their info
-----------------------------------------------------------------------------------------------
function Generalist:UpdateCurrentCharacter()
-- Get the current character's name
local unitPlayer = GameLib.GetPlayerUnit()
if unitPlayer == nil then
return
end
local myName = unitPlayer:GetName()
-- Is there an entry for this player in the table?
-- Add an empty entry if not.
--
if self.altData[myName] == nil then
self.altData[myName] = {}
end
-- Now update the entry. First, the basics.
--
self.altData[myName].faction = unitPlayer:GetFaction()
self.altData[myName].class = unitPlayer:GetClassId()
self.altData[myName].path = PlayerPathLib.GetPlayerPathType()
self.altData[myName].zone = GetCurrentZoneName()
-- Update the character's level
self:GetCharLevel()
-- Update the character's cash
self:GetCharCash()
-- Update the character's list of unlocked AMPs.
self:GetUnlockedAmps()
-- Update the character's list of known tradeskills and schematics
self:GetTradeskills()
-- Update the character's equipped gear
self:GetCharEquipment()
-- Update the character's inventory
self:GetCharInventory()
-- Currency
self:GetCharCurrency()
-- Dyes
self:GetCharDyes()
-- Rep
self:GetCharReputations()
-- Decor
self:GetCharDecor()
-- Contracts
self:GetCharContracts()
end
-----------------------------------------------------------------------------------------------
-- Functions for storing particular parts of the current character's data
-----------------------------------------------------------------------------------------------
----------------------------
-- Character's level
----------------------------
function Generalist:GetCharLevel()
local unitPlayer = GameLib.GetPlayerUnit()
if unitPlayer == nil then return end
local myName = unitPlayer:GetName()
if self.altData[myName] == nil then self.altData[myName] = {} end
self.altData[myName].level = unitPlayer:GetLevel()
end
----------------------------
-- Character's cash
----------------------------
function Generalist:GetCharCash()
local unitPlayer = GameLib.GetPlayerUnit()
if unitPlayer == nil then return end
local myName = unitPlayer:GetName()
if self.altData[myName] == nil then self.altData[myName] = {} end
self.altData[myName].cash = GameLib.GetPlayerCurrency():GetAmount()
end
----------------------------
-- Character's inventory
----------------------------
function Generalist:GetCharInventory()
local unitPlayer = GameLib.GetPlayerUnit()
if unitPlayer == nil then return end
local myName = unitPlayer:GetName()
if self.altData[myName] == nil then self.altData[myName] = {} end
-- Hash for storing our complete inventory
local myInv = {}
-- Inventory hash format will be:
-- {
-- itemDbIdNumber = {name, count, location},
-- anotherItemDbIdNumber = {name, count, location},
-- }
-- Get the big inventory hash, and loop through it.
--
local inv = GameLib.GetPlayerUnit():GetInventoryItems()
for _,invBag in ipairs(inv) do
-- Get the DB ID# of the item
local id = invBag.itemInBag:GetItemId()
local name = invBag.itemInBag:GetName()
-- Have we encountered any of this item yet?
if myInv[id] == nil then
-- Nope, it's new. Put it in the hash.
myInv[id] = {}
myInv[id].location = 1
myInv[id].name = name
myInv[id].count = invBag.itemInBag:GetStackCount()
else
-- Nope, we already saw another stack of it. Add this one to it.
myInv[id].count = myInv[id].count + invBag.itemInBag:GetStackCount()
end
end -- of loop through inventory bags
-- The tradeskill bag structure is much more complicated,
-- having categories.
--
local supply = GameLib.GetPlayerUnit():GetSupplySatchelItems()
for category,contents in pairs(supply) do
-- Now loop through the items in the category.
for _,thing in ipairs(contents) do
-- The ID of the thing
local id = thing.itemMaterial:GetItemId()
local name = thing.itemMaterial:GetName()
-- Now it's a similar song-and-dance to the bit where
-- we looped through the inventory bags, but we use a
-- different variable.
-- Have we encountered any of this item yet?
if myInv[id] == nil then
-- Nope, it's new. Put it in the hash.
myInv[id] = {}
myInv[id].location = 2
myInv[id].name = name
myInv[id].count = thing.nCount
else
-- Nope, we already saw another stack of it. Add this one to it.
myInv[id].count = myInv[id].count + thing.nCount
myInv[id].location = bit32.bor(2,myInv[id].location)
end
end -- of loop through things in a supply category
end -- of loop through supply categories
-- Now we have to get equipment as well!
local eq = GameLib.GetPlayerUnit():GetEquippedItems()
for key, itemEquipped in pairs(eq) do
-- the item's ID
local id = itemEquipped:GetItemId()
local name = itemEquipped:GetName()
if myInv[id] == nil then
-- Nope, it's new. Put it in the hash.
myInv[id] = {}
myInv[id].location = 4
myInv[id].name = name
myInv[id].count = 1
else
-- We already saw a stack of it. Add this one to it.
myInv[id].count = myInv[id].count + 1
myInv[id].location = bit32.bor(4,myInv[id].location)
end
end
-- Finally, set our data
self.altData[myName].inventory = myInv
end
----------------------------
-- Character's currencies
----------------------------
function Generalist:GetCharCurrency()
-- If possible, get my name.
local unitPlayer = GameLib.GetPlayerUnit()
if unitPlayer == nil then return end
local myName = unitPlayer:GetName()
if self.altData[myName] == nil then self.altData[myName] = {} end
-- The table to store currency.
local currency = {}
-- Loop through currencies
for idx = 1, #karrCurrency do
local tData = karrCurrency[idx]
local cType = tData.eType
local theAmount = GameLib.GetPlayerCurrency(tData.eType):GetAmount()
if theAmount ~= nil then
currency[cType] = theAmount
end
end -- of loop through currencies
self.altData[myName].currency = currency
end
----------------------------
-- Character's unlocked amps
----------------------------
function Generalist:GetUnlockedAmps()
-- If possible, get my name.
local unitPlayer = GameLib.GetPlayerUnit()
if unitPlayer == nil then return end
local myName = unitPlayer:GetName()
if self.altData[myName] == nil then self.altData[myName] = {} end
-- Get AMPs
local amps = AbilityBook.GetEldanAugmentationData(AbilityBook.GetCurrentSpec()).tAugments
if amps == nil then return end
-- Loop through and save the ones which have an item which unlocks them.
local unlocked = {}
for _,ampEntry in ipairs(amps) do
if ampEntry.nItemIdUnlock ~= 0 then
if ampEntry.bUnlocked == true then
table.insert(unlocked, ampEntry)
end
end
end
-- And store in the main table.
self.altData[myName].unlocked = unlocked
end
----------------------------
-- Character's reputations
----------------------------
function Generalist:GetCharReputations()
-- If possible, get my name.
local unitPlayer = GameLib.GetPlayerUnit()
if unitPlayer == nil then return end
local myName = unitPlayer:GetName()
if self.altData[myName] == nil then self.altData[myName] = {} end
-- Get reputations
local tReputations = GameLib.GetReputationInfo()
if not tReputations then
return
end
-- Blow away old entries
self.altData[myName].reputation = {}
-- The new list
local repTable = {}
local repList = {}
-- First, get simple list of all faction names, parents, and values
local facParent = {}
local hasChildren = {}
for idx, tFaction in pairs(tReputations) do
if tFaction.strParent ~= '' then
facParent[tFaction.strName] = tFaction.strParent
hasChildren[tFaction.strParent] = 1
-- Print (tFaction.strParent .. " is parent of " .. tFaction.strName)
end
-- But is this a real rep?
repList[tFaction.strName] = 1
end
-- Loop through them again
for idx, tFaction in pairs(tReputations) do
-- Get the name
local fac
-- We only care if it has a value.
if tFaction.nCurrent ~= nil then
-- Is it a real rep? i.e. does it have a legit top level?
local realRep = 0
-- If it has no parent, then it's a top level faction
if tFaction.strParent == '' then
-- We only include it if it has kids too.
-- This will exclude "Holiday".
--
if hasChildren[tFaction.strName] ~= nil then
fac = tFaction.strName
realRep = 1
end
else
-- Is its parent a real rep?
if repList[tFaction.strParent] ~= nil then
-- Does it have a grandparent?
if facParent[tFaction.strParent] == nil then
-- No. But its parent is legit. So do it.
fac = tFaction.strParent .. ":\n" .. tFaction.strName
realRep = 1
else
-- It has both. Is the grandparent real?
if repList[facParent[tFaction.strParent]] ~= nil then
-- Yup, gramps is legit. So do it.
realRep = 1
fac = facParent[tFaction.strParent]
fac = fac .. ": " .. tFaction.strParent .. ":\n" .. tFaction.strName
end -- is grandparent real?
end -- does it have a grandparent?
end -- is parent real?
end -- does it have a parent?
-- Still here? If it's a real rep, add it.
if realRep == 1 then
local tRep = {}
tRep.level = tFaction.nLevel
tRep.value = tFaction.nCurrent
tRep.name = fac
table.insert(repTable, tRep)
end
end -- does it have a value?
end -- of loop over Factions
-- Now sort the list
table.sort(repTable, function (a,b) return a.name < b.name end)
-- And store it
self.altData[myName].reputation = repTable
end -- of gathering rep
----------------------------
-- Character's decor
----------------------------
function Generalist:GetCharDecor()
-- If possible, get my name.
local unitPlayer = GameLib.GetPlayerUnit()
if unitPlayer == nil then return end
local myName = unitPlayer:GetName()
if self.altData[myName] == nil then self.altData[myName] = {} end
-- Return if we're not on our own property.
if not HousingLib.IsOnMyResidence() then
return
end
-- Temp decor table.
local theDecor = {}
local libResidence = HousingLib.GetResidence()
-- Get placed decor.
local tDecor = libResidence:GetPlacedDecorList()
-- Loop through it.
for _,tItem in ipairs(tDecor) do
local name = tItem:GetName()
if theDecor[name] == nil then
theDecor[name] = {}
theDecor[name] = 1
else
theDecor[name] = theDecor[name] + 1
end
end
-- Get crated decor.
tDecor = libResidence:GetDecorCrateList()
-- Loop through it.
for _,tItem in ipairs(tDecor) do
local name = tItem.strName
if theDecor[name] == nil then
theDecor[name] = {}
theDecor[name] = tItem.nCount
else
theDecor[name] = theDecor[name] + tItem.nCount
end
end
-- And save it.
self.altData[myName].decor = theDecor
end
----------------------------
-- Character's tradeskills
----------------------------
function Generalist:GetTradeskills()
-- If possible, get my name.
local unitPlayer = GameLib.GetPlayerUnit()
if unitPlayer == nil then return end
local myName = unitPlayer:GetName()
if self.altData[myName] == nil then self.altData[myName] = {} end
-- Schematics table
if self.altData[myName].schematics == nil then
self.altData[myName].schematics = {}
end
-- Table of active/inactive skills
local activityTable = {}
-- Table of skill tiers
local tierTable = {}
-- Table of all my tradeskills
local ts = {}
-- Get my tradeskills and loop through them
local tsk = CraftingLib:GetKnownTradeskills()
-- Loop over the list
for _,tSkill in ipairs(tsk) do
local id = tSkill.eId
-- Add skill to table
table.insert(ts, tSkill)
-- Is the skill active?
local isActive = CraftingLib.GetTradeskillInfo(id).bIsActive
activityTable[id] = isActive
-- Tier?
tierTable[id] = CraftingLib.GetTradeskillInfo(id).eTier
-- Is this skill still active?
if isActive == true then
-- Schematics for this skill
local skillSchem = CraftingLib.GetSchematicList(id)
-- Sort them by their name
table.sort(skillSchem, function(a,b)
if a.strName ~= nil and b.strName ~= nil then
return a.strName < b.strName
else
return 0
end
end)
-- Add list of schematics
self.altData[myName].schematics[id] = skillSchem
else -- skill is not active
if self.altData[myName].schematics[tSkill.eId] ~= nil then
end
end -- whether tradeskill is active
end
-- And store the list
self.altData[myName].tradeSkills = ts
-- Store activity table
self.altData[myName].skillActive = activityTable
-- Store tier table
self.altData[myName].skillTier = tierTable
end
----------------------------
-- Character's equipped items
----------------------------
function Generalist:GetCharEquipment()
-- If possible, get my name.
local unitPlayer = GameLib.GetPlayerUnit()
if unitPlayer == nil then return end
local myName = unitPlayer:GetName()
if self.altData[myName] == nil then self.altData[myName] = {} end
-- Start the bag index correctly
local bagIndex = GameLib.CodeEnumEquippedItems.Bag0
local eq = unitPlayer:GetEquippedItems()
local equipment = {}
self.altData[myName].fullItem = {}
self.altData[myName].chatLink = {}
for key, itemEquipped in pairs(eq) do
-- What slot does this item go in?
local theSlot = itemEquipped:GetSlot()
-- Is this a bag?
if theSlot == GameLib.CodeEnumEquippedItems.Bag0 then
-- Use the next bag index instead of the slot the item "goes in"
theSlot = bagIndex
-- And increment the bag index
bagIndex = bagIndex + 1
end
equipment[theSlot] = itemEquipped:GetItemId()
self.altData[myName].fullItem[theSlot] = itemEquipped
self.altData[myName].chatLink[theSlot] = itemEquipped:GetChatLinkString()
end
self.altData[myName].equipment = equipment
end
----------------------------
-- Character's dyes
----------------------------
function Generalist:GetCharDyes()
-- If possible, get my name.
local unitPlayer = GameLib.GetPlayerUnit()
if unitPlayer == nil then return end
local myName = unitPlayer:GetName()
if self.altData[myName] == nil then self.altData[myName] = {} end
-- Get list of dyes
local dyes = GameLib.GetKnownDyes()
-- Return if I couldn't get them or there are none
if dyes == nil then return end
-- Sort the dyes