forked from alarofrunetotem/GarrisonCommander
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGarrisonCommander.lua
3263 lines (3190 loc) · 107 KB
/
GarrisonCommander.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
local me, ns = ...
local toc=select(4,GetBuildInfo())
local pp=print
ns.Configure()
local _G=_G
local HD=false
local tremove=tremove
local setmetatable=setmetatable
local getmetatable=getmetatable
local type=type
local GetAddOnMetadata=GetAddOnMetadata
local CreateFrame=CreateFrame
local wipe=wipe
local format=format
local tostring=tostring
local collectgarbage=collectgarbage
--@debug@
--local collectgarbage=function() end
--@end-debug@
local GMM=false
local MP=false
local MPGoodGuy=false
local MPSwitch
local dbg=false
local trc=false
local pin=false
local baseHeight
local minHeight
local addon=addon --#addon
local LE_FOLLOWER_TYPE_GARRISON_6_0=Enum.GarrisonFollowerType.FollowerType_6_0
local LE_FOLLOWER_TYPE_SHIPYARD_6_2=Enum.GarrisonFollowerType.FollowerType_6_2
local LE_FOLLOWER_TYPE_GARRISON_7_0=Enum.GarrisonFollowerType.FollowerType_7_0
local LE_FOLLOWER_TYPE_GARRISON_8_0=Enum.GarrisonFollowerType.FollowerType_8_0
local LE_GARRISON_TYPE_6_0=Enum.GarrisonType.Type_6_0
local LE_GARRISON_TYPE_6_2=Enum.GarrisonType.Type_6_2
local LE_GARRISON_TYPE_7_0=Enum.GarrisonType.Type_7_0
local LE_GARRISON_TYPE_8_0=Enum.GarrisonType.Type_8_0
local GARRISON_MISSION_AVAILABILITY1=GARRISON_MISSION_AVAILABILITY..'\n %s'
local GARRISON_MISSION_AVAILABILITY2=GARRISON_MISSION_ENVIRONMENT:sub(1,10)..GARRISON_MISSION_AVAILABILITY..':|r %s'
local GARRISON_MISSION_ID=GARRISON_MISSION_ENVIRONMENT:sub(1,10)..'MissionID:|r |cffffffff%s|r'
local fakeinfo={followerID=false}
local fakeframe={}
local mainframes={
[LE_FOLLOWER_TYPE_GARRISON_6_0]="GarrisonMissionFrame",
[LE_FOLLOWER_TYPE_SHIPYARD_6_2]="GarrisonShipyardFrame",
}
ns.bigscreen=true
local tprint=print
local backdrop = {
--bgFile="Interface\\TutorialFrame\\TutorialFrameBackground",
bgFile="Interface\\DialogFrame\\UI-DialogBox-Background-Dark",
edgeFile="Interface\\Tooltips\\UI-Tooltip-Border",
tile=true,
tileSize=16,
edgeSize=16,
insets={bottom=7,left=7,right=7,top=7}
}
local dialog = {
bgFile="Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile="Interface\\DialogFrame\\UI-DialogBox-Border",
tile=true,
tileSize=32,
edgeSize=32,
insets={bottom=5,left=5,right=5,top=5}
}
local function tcopy(obj, seen)
if type(obj) ~= 'table' then return obj end
if seen and seen[obj] then return seen[obj] end
local s = seen or {}
local res = setmetatable({}, getmetatable(obj))
s[obj] = res
for k, v in pairs(obj) do res[tcopy(k, s)] = tcopy(v, s) end
return res
end
local widgetsForKey={}
local parties
local missionCompleteOrder=122514
local lastTab
local new, del, copy =ns.new,ns.del,ns.copy
local function capitalize(s)
s=tostring(s)
return strupper(s:sub(1,1))..strlower(s:sub(2))
end
--- upvalues
--
--local AVAILABLE=AVAILABLE -- "Available"
local BUTTON_INFO=GARRISON_MISSION_TOOLTIP_NUM_REQUIRED_FOLLOWERS.. " " .. GARRISON_MISSION_PERCENT_CHANCE
--local ENVIRONMENT_SUBHEADER=ENVIRONMENT_SUBHEADER -- "Environment"
local G=C_Garrison
--local GARRISON_BUILDING_SELECT_FOLLOWER_TITLE=GARRISON_BUILDING_SELECT_FOLLOWER_TITLE -- "Select a Follower";
--local GARRISON_BUILDING_SELECT_FOLLOWER_TOOLTIP=GARRISON_BUILDING_SELECT_FOLLOWER_TOOLTIP -- "Click here to assign a Follower";
--local GARRISON_FOLLOWERS=GARRISON_FOLLOWERS -- "Followers"
--local GARRISON_FOLLOWER_CAN_COUNTER=GARRISON_FOLLOWER_CAN_COUNTER -- "This follower can counter:"
--local GARRISON_FOLLOWER_EXHAUSTED=GARRISON_FOLLOWER_EXHAUSTED -- "Recovering (1 Day)"
--local GARRISON_FOLLOWER_INACTIVE=GARRISON_FOLLOWER_INACTIVE --"Inactive"
--local GARRISON_FOLLOWER_IN_PARTY=GARRISON_FOLLOWER_IN_PARTY
--local GARRISON_FOLLOWER_ON_MISSION=GARRISON_FOLLOWER_ON_MISSION -- "On Mission"
--local GARRISON_FOLLOWER_WORKING=GARRISON_FOLLOWER_WORKING -- "Working
local GARRISON_MISSION_PERCENT_CHANCE="%d%%"-- GARRISON_MISSION_PERCENT_CHANCE
--local GARRISON_MISSION_SUCCESS=GARRISON_MISSION_SUCCESS -- "Success"
--local GARRISON_MISSION_TOOLTIP_NUM_REQUIRED_FOLLOWERS=GARRISON_MISSION_TOOLTIP_NUM_REQUIRED_FOLLOWERS -- "%d Follower mission";
--local GARRISON_PARTY_NOT_FULL_TOOLTIP=GARRISON_PARTY_NOT_FULL_TOOLTIP -- "You do not have enough followers on this mission."
--local GARRISON_MISSION_CHANCE=GARRISON_MISSION_CHANCE -- Chanche
--local GARRISON_FOLLOWER_BUSY_COLOR=GARRISON_FOLLOWER_BUSY_COLOR
--local GARRISON_FOLLOWER_INACTIVE_COLOR=GARRISON_FOLLOWER_INACTIVE_COLOR
--local GARRISON_CURRENCY=GARRISON_CURRENCY --824
local GARRISON_FOLLOWER_MAX_UPGRADE_QUALITY=GARRISON_FOLLOWER_MAX_UPGRADE_QUALITY[LE_FOLLOWER_TYPE_GARRISON_6_0]
local GARRISON_FOLLOWER_MAX_LEVEL=40
local GARRISON_CURRENCY=GARRISON_CURRENCY
local GetMoneyString=GetMoneyString
local SHORTDATE=SHORTDATE.. " %s"
local LEVEL=LEVEL -- Level
local MISSING=ADDON_MISSING
local NOT_COLLECTED=NOT_COLLECTED -- not collected
local GMF=GMF
local GSF=GSF
-- Frames shortcut
local GMFRewardPage= GMF.MissionComplete
local GMFMissions= GMF.MissionTab.MissionList
local GMFRewardSplash= GMF.MissionTab.MissionList.CompleteDialog
local GMFMissionsListScrollFrame= GMF.MissionTab.MissionList.ScropllBox
local GMFMissionsListScrollFrameScrollChild= GMF.MissionTab.MissionList.ScrollBox.scrollChild
local GMFFollowers= GMF.FollowerList
local GMFMissionFrameFollowers= GMFFollowers
local GMFFollowersListScrollFrame= GMFFollowers.listScroll
local GMFFollowersListScrollFrameScrollChild= GMFFollowers.ScrollBox.scrollChild
local GMFMissionPage= GMF.MissionTab.MissionPage
--dictionary
local IGNORE_UNAIVALABLE_FOLLOWERS=IGNORE.. ' ' .. UNAVAILABLE
local IGNORE_UNAIVALABLE_FOLLOWERS_DETAIL= GARRISON_FOLLOWER_ON_MISSION ..',' .. GARRISON_FOLLOWER_WORKING .. ' ' .. GARRISON_FOLLOWERS .. '. ' .. GARRISON_FOLLOWER_INACTIVE .. " are always ignored"
local PARTY=PARTY -- "Party"
local SPELL_TARGET_TYPE1_DESC=capitalize(SPELL_TARGET_TYPE1_DESC) -- any
local SPELL_TARGET_TYPE4_DESC=capitalize(SPELL_TARGET_TYPE4_DESC) -- party member
local ANYONE='('..SPELL_TARGET_TYPE1_DESC..')'
local UNKNOWN_CHANCE=GARRISON_MISSION_PERCENT_CHANCE:gsub('%%d%%%%',UNKNOWN)
IGNORE_UNAIVALABLE_FOLLOWERS=capitalize(IGNORE_UNAIVALABLE_FOLLOWERS)
IGNORE_UNAIVALABLE_FOLLOWERS_DETAIL=capitalize(IGNORE_UNAIVALABLE_FOLLOWERS_DETAIL)
local UNKNOWN=UNKNOWN -- Unknown
local TYPE=TYPE -- Type
local ALL=ALL -- All
local MAXMISSIONS=8
local MINPERC=20
local BUSY_MESSAGE_FORMAT=L["Only first %1$d missions with over %2$d%% chance of success are shown"]
local BUSY_MESSAGE=format(BUSY_MESSAGE_FORMAT,MAXMISSIONS,MINPERC)
local GarrisonFollowerPortrait_Set=GarrisonFollowerPortrait_Set
if not GarrisonFollowerPortrait_Set then
GarrisonFollowerPortrait_Set=function(portrait, iconFileID)
if (iconFileID == nil or iconFileID == 0) then
-- unknown icon file ID; use the default silhouette portrait
portrait:SetTexture("Interface\\Garrison\\Portraits\\FollowerPortrait_NoPortrait");
else
portrait:SetToFileData(iconFileID);
end
end
end
local function splitFormat(base)
local i,s=base:find("|4.*:.*;")
if (not i) then
return base,base
end
local m0,m1=base:match("|4(.*):(.*);")
local G=base
local G1=G:sub(1,i-1)..m0..G:sub(s+1)
local G2=G:sub(1,i-1)..m1..G:sub(s+1)
return G1,G2
end
local function ShowTT(this)
GameTooltip:SetOwner(this, "ANCHOR_TOPRIGHT")
GameTooltip:SetText(this.tooltip)
GameTooltip:Show()
end
local function FadeTT(this)
GameTooltip:Fade()
end
local function HideTT(this)
GameTooltip:Hide()
end
local GARRISON_DURATION_DAY,GARRISON_DURATION_DAYS=splitFormat(GARRISON_DURATION_DAYS) -- "%d |4day:days;";
local GARRISON_DURATION_DAY_HOURS,GARRISON_DURATION_DAYS_HOURS=splitFormat(GARRISON_DURATION_DAYS_HOURS) -- "%d |4day:days; %d hr";
local GARRISON_DURATION_HOURS=GARRISON_DURATION_HOURS -- "%d hr";
local GARRISON_DURATION_HOURS_MINUTES=GARRISON_DURATION_HOURS_MINUTES -- "%d hr %d min";
local GARRISON_DURATION_MINUTES=GARRISON_DURATION_MINUTES -- "%d min";
local GARRISON_DURATION_SECONDS=GARRISON_DURATION_SECONDS -- "%d sec";
local AGE_HOURS="Expires in " .. GARRISON_DURATION_HOURS_MINUTES
local AGE_DAYS="Expires in " .. GARRISON_DURATION_DAYS_HOURS
-- Panel sizes
local BIGSIZEW=1220
local BIGSIZEH=662
local SIZEW=950
local SIZEH=662
local SIZEV
local GCSIZE=700
local FLSIZE=400
local BIGBUTTON=BIGSIZEW-GCSIZE
local SMALLBUTTON=BIGSIZEW-GCSIZE
local GCF
local GCFMissions
local GCFBusyStatus
local GameTooltip=GameTooltip
-- Want to know what I call!!
local GetItemInfo=GetItemInfo
local type=type
local ITEM_QUALITY_COLORS=ITEM_QUALITY_COLORS
function addon:GetDifficultyColors(perc,usePurple)
local q=self:GetDifficultyColor(perc,usePurple)
return q.r,q.g,q.b
end
function addon:GetQualityColor(n)
local c=ITEM_QUALITY_COLORS[n]
if c then
return c.r,c.g,c.b,1
else
return 1,1,1,1
end
end
function addon:GetDifficultyColor(perc,usePurple)
if(perc >90) then
return QuestDifficultyColors['standard']
elseif (perc >74) then
return QuestDifficultyColors['difficult']
elseif(perc>49) then
return QuestDifficultyColors['verydifficult']
elseif(perc >20) then
return QuestDifficultyColors['impossible']
else
return not usePurple and C.Silver or C.Fuchsia
end
end
----- Local variables
--
-- Forces a table to countain other tables,
local t1={
__index=function(t,k) if k then rawset(t,k,{}) return t[k] end end
}
local t2={
__index=function(t,k) if k then rawset(t,k,setmetatable({},t1)) return t[k] end end
}
local followersCache={}
local followersCacheIndex={}
local dirty=false
local chardb
local db
local n=setmetatable({},{
__index = function(t,k)
local name=addon:GetFollowerData(k,'fullname')
if (name and k) then rawset(t,k,name) return name else return k end
end
})
-- Counter system
local function cleanicon(stringa)
return (stringa:lower():gsub("%.blp$",""))
end
local counters=setmetatable({},t2)
local counterThreatIndex=setmetatable({},t2)
local counterFollowerIndex=setmetatable({},t2)
--generic table scan
local function inTable(table, value)
if (type(table)~='table') then return false end
if (#table > 0) then
for i=1,#table do
if (value==table[i]) then return true end
end
else
for k,v in pairs(table) do
if v == value then
return true
end
end
end
return false
end
local Current_Sorter
local sortKeys={}
local nop=function() end
local sorters={
Garrison_SortMissions_Original=nop,
Garrison_SortMissions_Chance=function(mission)
local p=addon:GetParty(mission.missionID)
if not p.full then return 0 end
return -p.perc or 0
end,
Garrison_SortMissions_Level=function(mission)
return -mission.level * 1000 - (mission.iLevel or 0)
end,
Garrison_SortMissions_Age=function(mission)
return addon:GetMissionData(mission.missionID,'offerEndTime',0)
end,
Garrison_SortMissions_Xp=function(mission)
return -addon:GetMissionData(mission.missionID,'globalXp',0)
end,
Garrison_SortMissions_HourlyXp=function(mission)
return sorters.Garrison_SortMissions_Xp(mission) / addon:GetMissionData(mission.missionID,'improvedDurationSeconds',1)
end,
Garrison_SortMissions_Duration=function(mission)
return addon:GetMissionData(mission.missionID,'improvedDurationSeconds',0)
end,
Garrison_SortMissions_Class=function(mission)
return addon:GetMissionData(mission.missionID,'class','other')
end,
Garrison_SortMissions_Followers=function(mission)
return addon:GetMissionData(mission.missionID,'numFollowers',1)
end,
}
local function sortfuncProgress(a,b)
return a.timeLeftSeconds < b.timeLeftSeconds
end
local function sortfuncAvailable(a,b)
if sortKeys[a.missionID] ~= sortKeys[b.missionID] then
return sortKeys[a.missionID] < sortKeys[b.missionID]
else
return strcmputf8i(a.name, b.name) < 0
end
end
local pcall=pcall
local sort=table.sort
function addon:SortMissions()
--@debug@
addon:Print(C("SortMissions","Orange"),Current_Sorter)
--@end-debug@
if GMFMissions.inProgress then
pcall(sort,GMFMissions.inProgressMissions,sortfuncProgress)
else
if Current_Sorter=="Garrison_SortMissions_Original" then return end
local f=sorters[Current_Sorter]
for _,mission in pairs(GMFMissions.availableMissions) do
local rc,result =pcall(f,mission)
sortKeys[mission.missionID]=rc and result or 0
--@debug@
if not rc then self:Print("Sort error",mission.name,mission.missionID,result) end
--@end-debug@
end
sort(GMFMissions.availableMissions,sortfuncAvailable)
end
end
function addon.Garrison_SortMissions_Chance(missionsList)
addon:RefreshParties()
table.sort(missionsList, sorters.Chance);
end
function addon.Garrison_SortMissions_Age(missionsList)
--addon:RefreshParties()
table.sort(missionsList, sorters.Age);
end
function addon.Garrison_SortMissions_Duration(missionsList)
addon:RefreshParties()
table.sort(missionsList, sorters.Duration);
end
function addon.Garrison_SortMissions_Followers(missionsList)
addon:RefreshParties()
table.sort(missionsList, sorters.Followers);
end
function addon.Garrison_SortMissions_Xp(missionsList)
addon:RefreshParties()
table.sort(missionsList, sorters.Xp);
end
function addon.Garrison_SortMissions_Class(missionsList)
--addon:RefreshParties()
table.sort(missionsList, sorters.Class);
end
function addon:ApplyMSORT(value)
Current_Sorter=value
GMFMissions:UpdateMissions()
end
function addon:GetMain()
return GMF
end
function addon:GetMissions()
return GMFMissions
end
function addon:GetBigScreen()
return ns.bigscreen
end
function addon:GetMissionModule(followertype)
return ns.custom[followertype]
end
function addon:OnInitialized()
--@debug@
print("Initialized")
--@end-debug@
--
ns.custom={
[LE_FOLLOWER_TYPE_GARRISON_6_0]=addon,
[LE_FOLLOWER_TYPE_SHIPYARD_6_2]=self:GetModule("ShipYard"),
}
self:SafeRegisterEvent("GARRISON_MISSION_COMPLETE_RESPONSE")
self:SafeRegisterEvent("GARRISON_MISSION_NPC_CLOSED")
self:SafeRegisterEvent("GARRISON_MISSION_STARTED")
self:SafeRegisterEvent("QUEST_TURNED_IN")
DevTools_Dump(GMF.MissionTab.MissionList.ScrollBox.ScrollTarget)
for _,b in GMF.MissionTab.MissionList.ScrollBox:EnumerateFrames() do
local scale=0.8
local f,h,s=b.Title:GetFont()
b.Title:SetFont(f,h*scale,s)
local f,h,s=b.Summary:GetFont()
b.Summary:SetFont(f,h*scale,s)
b:RegisterForClicks("LeftButtonUp","RightButtonUp")
addon:SafeSecureHookScript(b,"OnEnter","ScriptGarrisonMissionButton_OnEnter")
addon:SafeRawHookScript(b,"OnClick","ScriptGarrisonMissionButton_OnClick")
end
self:CreatePrivateDb()
db=self.db.global
db.seen=nil -- Removed in 2.6.9
db.abilities=nil -- Removed in 2.6.9
db.lifespan=nil -- Removed in 2.6.9
db.traits=nil -- Removed in 2.6.9
db.types=nil -- Removed in 2.6.9
chardb.missions=nil -- Removed
chardb.followers=nil
chardb.running=nil
chardb.runningIndex=nil
if type(dbGAC)== "table " and type(dbGAC.namespaces)=="table" then
dbGAC.namespaces.missionscache=nil -- Removed in 2.6.9
dbGAC.namespaces=nil
end
self:AddLabel(L["Garrison Appearance"])
--self:AddToggle("MOVEPANEL",true,L["Unlock Panel"],L["Makes main mission panel movable"])
self:AddToggle("BIGSCREEN",true,L["Big screen"],L["Disabling this will give you the interface from 1.1.8, given or taken. Need to reload interface"])
self:AddToggle("PIN",true,L["Show Garrison Commander menu"],L["Disable if you dont want the full Garrison Commander Header."])
self:AddLabel(L["Mission Panel"])
self:AddToggle("IGM",true,IGNORE_UNAIVALABLE_FOLLOWERS,IGNORE_UNAIVALABLE_FOLLOWERS_DETAIL)
self:AddToggle("IGP",true,L['Ignore "maxed"'],L["Level 100 epic followers are not used for xp only missions."])
self:AddToggle("NOFILL",false,L["No mission prefill"],L["Disables automatic population of mission page screen. You can also press control while clicking to disable it for a single mission"])
self:AddSelect("MSORT","Garrison_SortMissions_Original",
{
Garrison_SortMissions_Original=L["Original method"],
Garrison_SortMissions_Chance=L["Success Chance"],
Garrison_SortMissions_Followers=L["Number of followers"],
Garrison_SortMissions_Age=L["Expiration Time"],
Garrison_SortMissions_Xp=L["Global approx. xp reward"],
Garrison_SortMissions_HourlyXp=L["Global approx. hourly xp reward"],
Garrison_SortMissions_Duration=L["Duration Time"],
Garrison_SortMissions_Class=L["Reward type"],
},
L["Sort missions by:"],L["Original sort restores original sorting method, whatever it was (If you have another addon sorting mission, it should kick in again)"])
self:AddToggle("USEFUL",true,L["Enhance tooltip"],L["Adds a list of other useful followers to tooltip"])
self:AddToggle("NOTOOLTIP",false,L["No tooltips"],L["Totally removes mission tooltips"])
self:AddToggle("MAXRES",true,L["Maximize result"],L["Allows a lower success percentage for resource missions. Change via Minimum needed chance slider"])
self:AddSlider("MAXRESCHANCE",80,50,100,L["Minimum needed chance"],L["Applied when 'maximize result' is enabled. Default is 80%"],1)
ns.bigscreen=self:GetBoolean("BIGSCREEN")
self:AddLabel(L["Followers Panel"])
self:AddSlider("MAXMISSIONS",5,1,8,L["Mission shown"],L["Mission shown for follower"],1)
self:AddSlider("MINPERC",50,0,100,L["Minimun chance"],L["Minimun chance success under which ignore missions"],5)
self:AddToggle("ILV",true,L["Show itemlevel"],L["When checked, show on each follower button weapon and armor level for maxed followers"])
self:AddToggle("IXP",true,L["Show xp"],L["When checked, show on each follower button missing xp to next level"])
self:AddToggle("UPG",true,L["Show upgrades"],L["Only meaningful upgrades are shown"])
self:AddToggle("NOCONFIRM",true,L["No confirmation"],L["If checked, clicking an upgrade icon will consume the item and upgrade the follower\n|cFFFF0000NO QUESTION ASKED|r"])
self:AddToggle("SWAPBUTTONS",false,L["Swap upgrades positions"],L["IF checked, shows armors on the left and weapons on the right "])
if not ns.bigscreen then
self:AddToggle("FOLLOWERMISSIONLIST",true,L["Missionlist"],L["Affects only little screen mode, hiding the per follower mission list if not checked"])
end
self:AddLabel("Buildings Panel")
self:AddToggle("HF",false,L["Hide followers"],L["Do not show follower icon on plots"])
--@debug@
self:AddLabel("Developers options")
self:AddToggle("DBG",false, "Enable Debug")
self:AddToggle("TRC",false, "Enable Trace")
self:AddOpenCmd("show","showdata","Prints a mission score")
--@end-debug@
self:Trigger("MSORT")
--@debug@
-- assert(self:GetAgeColor(1/0))
-- assert(self:GetAgeColor(0/0))
-- assert(self:GetAgeColor(GetTime()+100))
-- assert(type(1/0)==nil)
-- assert(type(0/0)==nil)
-- assert("stringa"~=nil)
-- assert("stringa"==nil or true)
-- assert(pcall(format,"%03d %03d",tonumber(1/0) or 1,tonumber(0/0) or 2))
--@end-debug@
self:SafeSecureHookScript("GarrisonMissionFrame","OnShow","Setup")
local tabCO=CreateFrame("Button",nil,UIParent,"GarrisonCommanderUpgradeButton,SecureActionbuttonTemplate")
ns.tabCO=tabCO
tabCO.tooltip=L["Complete in progress mission"]
tabCO:SetNormalTexture("Interface\\ICONS\\Ability_Skyreach_Empowered.blp")
tabCO:SetPushedTexture("Interface\\ICONS\\Ability_Skyreach_Empowered.blp")
tabCO:Show()
tabCO.Quantity:Show()
tabCO.Quantity:SetFormattedText("%d",GetItemCount(missionCompleteOrder))
tabCO:SetAttribute("type","item")
tabCO:SetAttribute("item",select(2,GetItemInfo(missionCompleteOrder)))
self:loadHelp()
--return true
end
function addon:showdata(fullargs,action,missionid)
self:Print(fullargs,",",missionid)
missionid=tonumber(missionid)
if missionid then
if action=="score" then
self:Print(self:GetMissionData(missionid,'name'),self:MissionScore(self:GetMissionData(missionid)))
elseif action=="mission" then
self:DumpMission(missionid)
elseif action=="match" then
self:TestMission(missionid)
end
end
end
function addon:CheckMP()
if (IsAddOnLoaded("MasterPlan")) then
MP=true
ns.MP=true
MPSwitch=true
end
end
function addon:CheckGMM()
if (IsAddOnLoaded("GarrisonMissionManager")) then
GMM=true
self:RefreshParties()
self:RefreshMissions()
end
end
function addon:ApplyIGM(value)
if not GMF:IsVisible() then return end
self:RefreshParties()
self:RefreshMissions()
end
function addon:ApplyMAXRES(value)
if not GMF:IsVisible() then return end
self:RefreshParties()
self:RefreshMissions()
end
function addon:ApplyCKMP(value)
if (MasterPlanMissionList) then
if (value) then
MasterPlanMissionList:Hide()
else
MasterPlanMissionList:Show()
end
end
self:RefreshMissions()
end
function addon:ApplyDBG(value)
dbg=value
end
function addon:ApplyPIN(value)
pin=value
end
function addon:ApplyTRC(value)
trc=value
end
function addon:ApplyBIGSCREEN(value)
if (value) then
wipe(chardb.ignored) -- we no longer have an interface to change this settings
end
self:Popup(L["Must reload interface to apply"],0,
function(this)
pp("BIGSCREEN",value,this)
print("BIGSCREEN",value,this)
addon:SetBoolean("BIGSCREEN",value)
ReloadUI()
end,
function(this)
pp("BIGSCREEN",value,this)
print("BIGSCREEN",value,this)
addon:SetBoolean("BIGSCREEN",not value)
widgetsForKey['BIGSCREEN']:SetValue(not value)
end
)
end
function addon:ApplyIGP(value)
if not GMF:IsVisible() then return end
self:RefreshParties()
self:RefreshMissions()
end
function addon:ApplyMAXMISSIONS(value)
MAXMISSIONS=value
BUSY_MESSAGE=format(BUSY_MESSAGE_FORMAT,MAXMISSIONS,MINPERC)
if ns.bigscreen and GMF.FollowerTab:IsVisible() then
end
end
function addon:ApplyMINPERC(value)
MINPERC=value
BUSY_MESSAGE=format(BUSY_MESSAGE_FORMAT,MAXMISSIONS,MINPERC)
end
function addon:ApplyFOLLOWERMISSIONLIST(value)
if GMF.FollowerTab:IsVisible() or (GMF.SummaryTab and GMF.SummaryTab:IsVisible()) then
self:RenderFollowerPageMissionList(nil,GMF.FollowerTab.followerID)
end
end
function addon:ApplyIXP(value)
print(value)
end
function addon:ApplyILV(value)
print(value)
end
function addon:IsIgnored(followerID,missionID)
if (chardb.ignored[missionID][followerID]) then return true end
if (chardb.totallyignored[followerID]) then return true end
end
function addon:GetAllCounters(missionID,threat,table)
wipe(table)
if type(counterThreatIndex[missionID]) == "table" then
local index=counterThreatIndex[missionID][cleanicon(tostring(threat))]
if (type(index)=="table") then
for i=1,#index do
tinsert(table,counters[missionID][index[i]].followerID)
end
end
end
end
function addon:GetCounterBias(missionID,threat)
local bias=-1
local who=""
local index=counterThreatIndex[missionID]
local data=counters[missionID]
if (type(index)=="table" and type(counters)=="table") then
index=index[cleanicon(tostring(threat))]
if (type(index) == "table") then
local members=self:GetParty(missionID,'members',empty)
for i=1,#index do
local follower=data[index[i]]
if ((tonumber(follower.bias) or -1) > bias) then
if (tContains(members,follower.followerID)) then
if (dbg) then
--@debug@
print(" Choosen",self:GetFollowerData(follower.followerID,'fullname'))
--@end-debug@
end
bias=follower.bias
who=follower.name
end
end
end
end
end
return bias,who
end
function addon:AddLine(name,status)
local r2,g2,b2=C.Red()
if (status==AVAILABLE) then
r2,g2,b2=C.Green()
elseif (status==GARRISON_FOLLOWER_WORKING) then
r2,g2,b2=C.Orange()
end
GameTooltip:AddDoubleLine(name, status,nil,nil,nil,r2,g2,b2)
end
function addon:SetThreatColor(obj,threat)
if type(threat)=="string" then
local _,_,bias,follower,name=strsplit(":",threat)
local color=self:GetBiasColor(tonumber(bias) or -1,nil,"Green")
local c=C[color]
obj.Border:SetVertexColor(c())
return (tonumber(bias)or -1)>-1
else
obj.Border:SetVertexColor(C.red())
end
end
function addon:AddIconsToFollower(missionID,useful,followers,members,followerTypeID)
for followerID,icons in pairs(followers) do
if self:GetFollowerType(followerID) == followerTypeID then
if not tContains(members,followerID) then
local bias=self:GetBiasColor(followerID,missionID)
if (not useful[followerID]) then
local rank=self:GetAnyData(followerTypeID,followerID,'rank')
if rank then
useful[followerID]=format("%04d%s %s ",
1000-rank,
C(rank,bias),
self:GetAnyData(followerTypeID,followerID,'coloredname')
)
end
end
for i=1,#icons do
if (useful[followerID]) then
useful[followerID]=format("%s |T%s:0|t",useful[followerID],icons[i].icon)
end
end
end
end
end
end
function addon:AddFollowersToTooltip(missionID,followerTypeID)
--local f=GarrisonMissionListTooltipThreatsFrame
-- Adding All available followers
if not GMF:IsVisible() and not GSF:IsVisible() then return end
local party=self:GetParty(missionID)
local cost=self:GetMissionData(missionID,'cost')
local currency=self:GetMissionData(missionID,'costCurrencyTypesID')
if cost and currency then
local _,available,texture=self:GetCurrencyInfo(currency)
if not texture then
print("Not found texture for",currency,self:GetCurrencyInfo(currency))
end
GameTooltip:AddDoubleLine(TABARDVENDORCOST,format("%d |T%s:0|t",cost,texture),nil,nil,nil,C[cost>available and 'Red' or 'Green']())
end
local members=party.members
if followerTypeID == LE_FOLLOWER_TYPE_SHIPYARD_6_2 then
GameTooltip:AddLine(GARRISON_FOLLOWER_IN_PARTY)
for _,followerID in ipairs(members) do
GameTooltip:AddLine(self:GetShipData(followerID,'fullname'))
end
end
if self:GetBoolean("USEFUL") then
local useful=new()
local traited=G.GetFollowersTraitsForMission(missionID)
local buffed=G.GetBuffedFollowersForMission(missionID,true)
if (type(traited)=='table') then
self:AddIconsToFollower(missionID,useful,traited,members,followerTypeID)
end
if (type(buffed)=='table') then
self:AddIconsToFollower(missionID,useful,buffed,members,followerTypeID)
end
if next(useful) then
table.sort(useful)
GameTooltip:AddDoubleLine(L["Other useful followers"],L["(Ignores low bias ones)"])
local inactive=C(GARRISON_FOLLOWER_INACTIVE,'Red')
for followerID,data in pairs(useful) do
local status=self:GetFollowerStatus(followerID,true,true)
if status ~=inactive then
GameTooltip:AddDoubleLine(data:sub(5),status)
end
end
end
del(useful)
end
local perc=party.perc
local q=self:GetDifficultyColor(perc)
GameTooltip:AddDoubleLine(GARRISON_MISSION_SUCCESS,format(GARRISON_MISSION_PERCENT_CHANCE,perc),nil,nil,nil,q.r,q.g,q.b)
for _,i in pairs (chardb.ignored[missionID]) do
GameTooltip:AddLine(L["You have ignored followers"],C.Orange())
break;
end
if party.goldMultiplier>1 and party.class=='gold' then
GameTooltip:AddDoubleLine(L["Gold incremented!"],party.goldMultiplier..'x',C.Green())
end
if type(party.materialMultiplier)=="table" then
for k,v in pairs(party.materialMultiplier) do
GameTooltip:AddDoubleLine((self:GetCurrencyInfo(k)),v..'x',C.Green())
end
end
if party.xpBonus>0 then
GameTooltip:AddDoubleLine(L["Xp incremented!"],'+'..party.xpBonus,C.Green())
end
if party.isMissionTimeImproved then
GameTooltip:AddLine(L["Mission time reduced!"],C.Green())
end
if (chardb.history[missionID]) then
local tot,success=0,0
for d,r in pairs(chardb.history[missionID]) do
tot,success=tot+1,success + (r.success and 1 or 0)
end
if (tot > 0) then
local ratio=floor(success/tot*100)
GameTooltip:AddDoubleLine(format(L["You performed this mission %d times with a win ratio of"],tot),ratio..'%',0,1,0,self:GetDifficultyColors(ratio))
return
end
end
GameTooltip:AddLine(L["You never performed this mission"],1,0,0)
end
local function switch(flag)
if (GCF[flag]) then
local b=GCF[flag]
if (b:GetChecked()) then
b.text:SetTextColor(C.Green())
else
b.text:SetTextColor(C.Silver())
end
end
end
function addon:RefreshParties()
if true then
addon:OnAllGarrisonMissions(function(missionID) addon:MatchMaker(missionID)end)
else
self:coroutineExecute(0.001,function()
addon:OnAllGarrisonMissions(function(missionID) addon:MatchMaker(missionID) coroutine.yield(true) end)
end
)
end
end
function addon:RefreshMissions(missionID)
self:GetMissions():UpdateMissions()
end
--[[
GARRISON_DURATION_DAYS = "%d |4day:days;"; changed to dual form
GARRISON_DURATION_DAYS_HOURS = "%d |4day:days; %d hr"; changed to dual form
GARRISON_DURATION_HOURS = "%d hr";
GARRISON_DURATION_HOURS_MINUTES = "%d hr %d min";
GARRISON_DURATION_MINUTES = "%d min";
GARRISON_DURATION_SECONDS = "%d sec";
--]]
local function GarrisonTimeStringToSeconds(text)
local s = D.Deformat(text,GARRISON_DURATION_SECONDS)
if (s) then return s end
local m = D.Deformat(text,GARRISON_DURATION_MINUTES)
if m then return m end
local h,m= D.Deformat(text,GARRISON_DURATION_HOURS_MINUTES)
if (h) then return h*3600+m*60 end
local h= D.Deformat(text,GARRISON_DURATION_HOURS)
if (h) then return h*3600 end
local d,h=D:Deformat(GARRISON_DURATION_DAY_HOURS)
if (d) then return d*3600*24 + h*3600 end
local d,h=D:Deformat(GARRISON_DURATION_DAYS_HOURS)
if (d) then return d*3600*24 + h*3600 end
local d=D:Deformat(GARRISON_DURATION_DAYS)
if (d) then return d*3600*24 end
local d=D:Deformat(GARRISON_DURATION_DAY)
if (d) then return d*3600*24 end
return 3600*24
end
function addon:SetDbDefaults(default)
default.global=default.global or {}
default.global["*"]={}
default.profile=default.profile or {}
default.profile.blacklist={}
default.profile.missionControl={
version=1,
allowedRewards = {
['*']=true,
},
rewardChance={
['*']=100,
},
rewardList={},
useOneChance=true,
minimumChance = 100,
minDuration = 0,
maxDuration = 24,
epicExp = false,
skipRare=true,
skipEpic=not addon:HasSalvageYard(),
minLevel=540,
minUpgrade=600
}
default.profile.shipControl={
version=1,
allowedRewards = {
['*']=true,
},
rewardChance={
['*']=100,
},
rewardList={},
useOneChance=true,
minimumChance = 100,
minDuration = 0,
maxDuration = 24,
epicExp = false,
skipRare=true,
skipEpic=true,
minLevel=540,
minUpgrade=600
}
end
function addon:CreatePrivateDb()
self.privatedb=self:RegisterDatabase(
GetAddOnMetadata(me,"X-Database")..'perChar',
{
profile={
ignored={
["*"]={
}
},
totallyignored={
},
history={
['*']={
}
},
missionControl={
blacklist={},
version=3,
allowedRewards = {
['*']=true,
},
rewardChance={
['*']=100,
},
rewardList={},
useOneChance=true,
minimumChance = 100,
minDuration = 0,
maxDuration = 24,
epicExp = false,
skipRare=true,
skipEpic=not addon:HasSalvageYard(),
minLevel=540,
minUpgrade=600
}
}
},
true)
chardb=self.privatedb.profile
end
function addon:SetClean()
dirty=false
end
function addon:HasSalvageYard()
local buildings=G.GetBuildings(LE_GARRISON_TYPE_6_0)
for i =1,#buildings do
local building=buildings[i]
if building.texPrefix=="GarrBuilding_SalvageYard_1_A" then return true end
end
end
function addon:WipeMission(missionID)
counters[missionID]=nil
parties[missionID]=nil
--collectgarbage("step")
end
function addon:EventGARRISON_MISSION_NPC_CLOSED(event,...)
--@debug@
self:Print(event,...)
--@end-debug@
if (GCF) then
self:RemoveMenu()
GCF:Hide()
end
end
---
--@param #string event GARRISON_MISSION_STARTED
--@param #number missionID Numeric mission id
-- After this events fires also GARRISON_MISSION_LIST_UPDATE and GARRISON_FOLLOWER_LIST_UPDATE
function addon:EventGARRISON_MISSION_STARTED(event,missionType,missionID,...)
--@debug@
print(event,missionType,missionID,...)
--@end-debug@
self:RefreshFollowerStatus()
if (not GMF:IsVisible()) then
-- Shipyard
return
end
wipe(chardb.ignored[missionID])
local party=self:GetParty(missionID)
wipe(party.members) -- I remove preset party, so PartyCache will refill it with the ones from the actual mission
if GMF:IsVisible() then
self:RefreshParties()
self:RefreshMissions()
end
end
---
--@param #string event GARRISON_MISSION_FINISHED
--@param #number missionID Numeric mission id
-- Thsi is just a notification, nothing get really changed
-- GetMissionINfo still returns data
-- but GetPartyMissionInfo does no longer return followers.
-- Also timeleft is false
--
---
--@param #number missionID mission identifier
--@param #boolean completed I suppose it always be true...
--@param #boolean success Mission was succesfull
--Mission complete Sequence is:
--GARRISON_MISSION_COMPLETE_RESPONSE
--GARRISON_MISSION_BONUS_ROLL_LOOT missionID true
--GARRISON_FOLLOWER_XP_CHANGED (1 or more times
--GARRISON_MISSION_NPC_OPENED ??
--GARRISON_MISSION_BONUS_ROLL_LOOY missionID nil
--
function addon:EventGARRISON_MISSION_COMPLETE_RESPONSE(event,missionID,completed,rewards,...)
--@debug@
print(event,missionID,completed,rewards,...)
--@end-debug@
chardb.history[missionID][time()]={result=100,success=rewards}
end
-----------------------------------------------------
-- Coroutines data and clock management
-----------------------------------------------------
local coroutines={
Timers={
func=false,
elapsed=60,
interval=60,
paused=false
},
}
function addon:ActivateButton(button,OnClick,Tooltiptext,persistent)
button:SetScript("OnClick",function(...) self[OnClick](self,...) end )
if (Tooltiptext) then
button.tooltip=Tooltiptext
button:SetScript("OnEnter",ShowTT)
if persistent then
button:SetScript("OnLeave",HideTT)