-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDMFQuest.lua
2264 lines (2039 loc) · 86.6 KB
/
DMFQuest.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
--[[----------------------------------------------------------------------------
DMFQuest
Reminder tool for Darkmoon Faire crafting quest materials
Version 1.0:
- 2013 - 2014
- 5.1.0 - 6.0.3
Version 2.0:
- 2015 - 2024
- 6.0.3 - 10.2.5
Version 3.0:
- 2024 -
- 10.2.5 -
----------------------------------------------------------------------------]]--
local ADDON_NAME, ns = ...
local L = ns.L -- Localization table
local db
local isFramePinned = false
local isRetail = (WOW_PROJECT_ID == WOW_PROJECT_MAINLINE)
local isCataClassic = (WOW_PROJECT_ID == WOW_PROJECT_CATACLYSM_CLASSIC)
local maxProfCount = isRetail and 5 or 6 -- First Aid removed in Patch 8.0.1 (2018-07-17)
local maxItemButtonCount = isRetail and 10 or 9 -- Moonfang's Pelt added in Patch 5.4.0 (2013-09-10)
local ptrDebugDay = isRetail and 7 or 14
local maxPrimarySkillGainFromQuest = isRetail and 2 or 5
local maxSecondarySkillGainFromQuest = isRetail and 3 or 5
-- GLOBALS: DMFQConfig, DEBUG_CHAT_FRAME
-- GLOBALS: AcceptQuest, ACTION_SPELL_AURA_APPLIED_BUFF, BINDING_HEADER_DEBUG, BuyMerchantItem, C_AddOns, C_Calendar
-- GLOBALS: C_Container, C_CurrencyInfo, C_DateAndTime, C_Item, C_Map, C_MapExplorationInfo, C_MerchantFrame
-- GLOBALS: C_QuestLog, C_Spell, C_Timer, C_TradeSkillUI, C_UnitAuras, CalendarFrame, ChatFrame3, ChatFrame4
-- GLOBALS: CONFIRM_RESET_SETTINGS, Constants, CreateFontStringPool, CreateFrame, DEFAULT_CHAT_FRAME, Enum, format
-- GLOBALS: GameTooltip, GARRISON_MISSION_REWARD_HEADER, GetBuildInfo, GetMerchantItemID, GetMerchantItemInfo
-- GLOBALS: GetMerchantItemLink, GetMerchantItemMaxStack, GetMerchantNumItems, GetMinimapZoneText, GetMoney
-- GLOBALS: GetProfessionInfo, GetProfessions, GetQuestID, GetQuestLogIndexByID, GetScreenHeight, GetScreenWidth
-- GLOBALS: GetTime, GREEN_FONT_COLOR, HUD_EDIT_MODE_SETTING_AURA_FRAME_ICON_DIRECTION_DOWN
-- GLOBALS: HUD_EDIT_MODE_SETTING_AURA_FRAME_ICON_DIRECTION_UP, InCombatLockdown
-- GLOBALS: InterfaceOptionsFrame_OpenToCategory, ipairs, Item, math, MISCELLANEOUS, next, ORANGE_FONT_COLOR, pairs
-- GLOBALS: PlaySound, PROFESSION_RANKS, PROFESSIONS_ARCHAEOLOGY, PROFESSIONS_COOKING, PROFESSIONS_FIRST_AID
-- GLOBALS: PROFESSIONS_FIRST_PROFESSION, PROFESSIONS_FISHING, PROFESSIONS_SECOND_PROFESSION, RED_FONT_COLOR
-- GLOBALS: RESET_ALL_BUTTON_TEXT, RESET_TO_DEFAULT, Settings, SHOW_PET_BATTLES_ON_MAP_TEXT, SlashCmdList, SOUNDKIT
-- GLOBALS: string, strjoin, strsplit, strtrim, time, TIMEMANAGER_TOOLTIP_REALMTIME, tonumber, tostring, tostringall
-- GLOBALS: type, UIParent, UnitPosition, unpack, wipe, WOW_PROJECT_CATACLYSM_CLASSIC, WOW_PROJECT_ID
-- GLOBALS: WOW_PROJECT_ID, WOW_PROJECT_MAINLINE
--[[----------------------------------------------------------------------------
Hard coded "data"
----------------------------------------------------------------------------]]--
--[[------------------------------------------------------------------------
https://www.wowhead.com/news=318875/darkmoon-faire-november-2020-skill-requirement-removed-from-profession-quests
------------------------------------------------------------------------
In the Shadowlands pre-patch, the 75 skill requirement has been removed
from Darkmoon Faire profession quests. You now only need to know a
minimum of level 1, and completing the quest still adds points to the
highest expansion's profession level known.
------------------------------------------------------------------------]]--
local minimumSkillRequired = isRetail and 1 or 75 -- This used to be 75
-- In Retail (TWW) this info is loaded on demand instead of being there always
-- https://www.townlong-yak.com/framexml/11.0.2/Blizzard_ProfessionsBook/Blizzard_ProfessionsBook.lua#12
local currentSkillCap = isRetail and 950 or PROFESSION_RANKS[#PROFESSION_RANKS][1] or 75
local dbDefaults = {
-- Frame
XPos = 275,
YPos = 275,
FrameLock = false,
GrowDirection = 1, -- 0 = Down, 1 = Up
FrameVertexColor = { 1, 1, 1 }, -- UI shade
-- Features
AutoBuy = true,
HideLow = false,
HideMax = false,
ShowInCapitals = false,
-- Quests
PetBattle = true,
DeathMetalKnight = true,
TestYourStrength = true,
FadedTreasureMap = true,
XPRepBuff = false,
ShowItemRewards = true,
-- Time Offset
UseTimeOffset = false,
TimeOffsetValue = 0,
-- Development and Debug
dbVersion = 1, -- In case we need to change things in the future
debug = false, -- Debug output
isPTR = false, -- Change some values on PTR only
}
-- Item Buttons
local itemButtonOrder = { -- [order] = questItemId
-- Dungeon
71635, -- Imbued Crystal
71636, -- Monstrous Egg
71637, -- Mysterious Grimoire
71638, -- Ornate Weapon
-- Heroic Dungeon
71715, -- A Treatise on Strategy
-- Raid
71716, -- Soothsayer's Runes
-- PvP
71951, -- Banner of the Fallen
71952, -- Captured Insignia
71953, -- Fallen Adventurer's Journal
-- Killing Moonfang
105891 -- Moonfang's Pelt
}
local buttonVertices = { -- SetVertexColor, rowIndex selected with button.itemStatus, 1-3 normal (onLeave), 4-6 highlight (onEnter)
-- Quest Completed (1)
{ 0, 1, 0, -- OnLeave
.75, 1, .75 }, -- OnEnter
-- On Quest (2)
{ 0, 1, 1, -- OnLeave
.75, 1, 1 }, -- OnEnter
-- Item, but no Quest (3)
{ 1, 1, 1, -- OnLeave
.75, .75, .75 }, -- OnEnter
-- No Item (4)
{ .3, .3, .3, -- OnLeave
.75, .75, .75 } -- OnEnter
}
-- Item Quests
local turnInItems = { -- [questItemId] = questId
-- Dungeon
[71635] = 29443, -- Imbued Crystal
[71636] = 29444, -- Monstrous Egg
[71637] = 29445, -- Mysterious Grimoire
[71638] = 29446, -- Ornate Weapon
-- Heroic Dungeon
[71715] = 29451, -- A Treatise on Strategy
-- Raid
[71716] = 29464, -- Soothsayer's Runes
-- PvP
[71951] = 29456, -- Banner of the Fallen
[71952] = 29457, -- Captured Insignia
[71953] = 29458, -- Fallen Adventurer's Journal
-- Killing Moonfang
[105891] = 33354 -- Moonfang's Pelt
}
local rewardsTable = { -- [questItemId] = # of [Darkmoon Prize Ticket] from completing the quest
-- Dungeon
[71635] = 10, -- Imbued Crystal
[71636] = 10, -- Monstrous Egg
[71637] = 10, -- Mysterious Grimoire
[71638] = 10, -- Ornate Weapon
-- Heroic Dungeon
[71715] = 15, -- A Treatise on Strategy
-- Raid
[71716] = 10, -- Soothsayer's Runes
-- PvP
[71951] = 5, -- Banner of the Fallen
[71952] = 5, -- Captured Insignia
[71953] = 5, -- Fallen Adventurer's Journal
-- Killing Moonfang
[105891] = 10 -- Moonfang's Pelt
}
-- Portal Areas
-- For some reason areaIDs change between Retail and CataClassic while subZoneAreaIDs stay the same?
local capitalCityAreaIDs = {
-- https://wago.tools/db2/UiMap // https://wow.tools/dbc/?dbc=uimap
-- Alliance
[isRetail and 84 or 1453] = true, -- Stormwind City
[isRetail and 87 or 1455] = true, -- Ironforge
[isRetail and 89 or 1457] = true, -- Darnassus
[isRetail and 103 or 1947] = true, -- The Exodar (BC)
-- Horde
[isRetail and 85 or 1454] = true, -- Orgrimmar
[isRetail and 88 or 1456] = true, -- Thunder Bluff
[isRetail and 90 or 1458] = true, -- Undercity
[isRetail and 110 or 1954] = true, -- Silvermoon City (BC)
-- Neutral (thanks to b-morgan for testing these!)
[isRetail and 111 or 1955] = true, -- Shattrath City (BC)
[125] = true, -- Dalaran (WotLK)
[126] = true -- Dalaran (The Underbelly) (WotLK)
}
local subZoneAreaIDs = { -- uiMapIDs and their matching subZone areaIDs
--[[
-- https://wago.tools/db2/UiMap // https://wow.tools/dbc/?dbc=uimap
-- https://wago.tools/db2/AreaTable // https://wow.tools/dbc/?dbc=areatable
[uiMapID] = {
areaID,
areaID,
areaID
}
]]--
-- Alliance
[isRetail and 37 or 1429] = { -- Elwynn Forrest
87, -- Goldshire (Town)
5637 -- Lion's Pride Inn (Inn)
},
-- Horde
[isRetail and 7 or 1412] = { -- Mulgore
-- These both return Mulgore for GetMinimapZoneText() and empty string for GetSubZoneText()
-- Also the changing of GetMinimapZoneText() is kind of hit or miss depending on the direction you arrive to the Portal from
404, -- Bael'dun Digsite (SW from Portal)
1638 -- Thunder Bluff (Next to the city, but not quite in it yet)
},
[isRetail and 88 or 1456] = { -- Thunder Bluff
1638, -- Thunder Bluff (Central Rise)
1639, -- Elder Rise (Eastern Rise)
1640, -- Spirit Rise (Northern Rise)
1641, -- Hunter Rise (Southern Rise)
8614 -- The Cat and the Shaman (Inn)
}
}
-- Professions
local ProfData = {} -- Save information about our Professions here
local ProfessionQuestData = {
-- Primary Professions
[171] = { -- Alchemy
questId = 29506,
questItems = {
[1645] = 5, -- Moonberry Juice
[19299] = 5 -- Fizzy Faire Drink
}
},
[164] = { -- Blacksmithing
questId = 29508
},
[333] = { -- Enchanting
questId = 29510
},
[202] = { -- Engineering
questId = 29511
},
[182] = { -- Herbalism
questId = 29514
},
[773] = { -- Inscription
questId = 29515,
questItems = {
[39354] = 5 -- Light Parchment
}
},
[755] = { -- Jewelcrafting
questId = 29516
},
[165] = { -- Leatherworking
questId = 29517,
questItems = {
[6529] = 10, -- Shiny Bauble
[2320] = 5, -- Coarse Thread
[6260] = 5 -- Blue Dye
}
},
[186] = { -- Mining
questId = 29518
},
[393] = { -- Skinning
questId = 29519
},
[197] = { -- Tailoring
questId = 29520,
questItems = {
[2320] = 1, -- Coarse Thread
[6260] = 1, -- Blue Dye
[2604] = 1 -- Red Dye
}
},
-- Secondary Professions
[794] = { -- Archaeology
questId = 29507,
questCurrency = {
[393] = 15 -- Fossil Archaeology Fragment
}
},
[129] = { -- FirstAid
questId = 29512
},
[356] = { -- Fishing
questId = 29513
},
[185] = { -- Cooking
questId = 29509,
questItems = {
[30817] = 5 -- Simple Flour
}
}
}
local ProfessionTradeSkillLines = {
-- https://warcraft.wiki.gg/wiki/TradeSkillLineID // https://wowpedia.fandom.com/wiki/TradeSkillLineID
-- https://wago.tools/db2/SkillLine // https://wow.tools/dbc/?dbc=skillline
-- [ProfId] = { Classic, TBC, Wrath, Cata, MoP, WoD, Legion, BfA, SL, DF, TWW }
-- Primary Professions
[171] = { -- Alchemy
2485, 2484, 2483, 2482, 2481, 2480, 2479, 2478, 2750, 2823, 2871
},
[164] = { -- Blacksmithing
2477, 2476, 2475, 2474, 2473, 2472, 2454, 2437, 2751, 2822, 2872
},
[333] = { -- Enchanting
2494, 2493, 2492, 2491, 2489, 2488, 2487, 2486, 2753, 2825, 2874
},
[202] = { -- Engineering
2506, 2505, 2504, 2503, 2502, 2501, 2500, 2499, 2755, 2827, 2875
},
[182] = { -- Herbalism
2556, 2555, 2554, 2553, 2552, 2551, 2550, 2549, 2760, 2832, 2877
},
[773] = { -- Inscription
2514, 2513, 2512, 2511, 2510, 2509, 2508, 2507, 2756, 2828, 2878
},
[755] = { -- Jewelcrafting
2524, 2523, 2522, 2521, 2520, 2519, 2518, 2517, 2757, 2829, 2879
},
[165] = { -- Leatherworking
2532, 2531, 2530, 2529, 2528, 2527, 2526, 2525, 2758, 2830, 2880
},
[186] = { -- Mining
2572, 2571, 2570, 2569, 2568, 2567, 2566, 2565, 2761, 2833, 2881
},
[393] = { -- Skinning
2564, 2563, 2562, 2561, 2560, 2559, 2558, 2557, 2762, 2834, 2882
},
[197] = { -- Tailoring
2540, 2539, 2538, 2537, 2536, 2535, 2534, 2533, 2759, 2831, 2883
},
-- Secondary Professions
--[794] = { -- Archeology
--}
[185] = { -- Cooking
2548, 2547, 2546, 2545, 2544, 2543, 2542, 2541, 2752, 2824, 2873
},
--[129] = { -- First Aid
--},
[356] = { -- Fishing
2592, 2591, 2590, 2589, 2588, 2587, 2586, 2585, 2754, 2826, 2876
}
}
local MissingProfessionsTable = { -- prof1, prof2, archaeology, fishing, cooking, firstAid
-- Primary Professions
PROFESSIONS_FIRST_PROFESSION, -- "First Profession"
PROFESSIONS_SECOND_PROFESSION, -- "Second Profession"
-- Archeology
PROFESSIONS_ARCHAEOLOGY, -- "Archaeology"
-- Fishing
PROFESSIONS_FISHING, -- "Fishing"
-- Cooking
PROFESSIONS_COOKING, -- "Cooking"
-- First Aid
PROFESSIONS_FIRST_AID -- "First Aid"
}
-- Additional Quests and Activities
local additionalQuests = {
PetBattle = {
Icon = 631719, -- 319458
QuestIdTable = {
32175, -- Jeremy Feasel - Darkmoon Pet Battle!
36471 -- Christoph VonFeasel - A New Darkmoon Challenger!
},
QuestAvailableCount = isRetail and 2 or 0 -- Patch 5.0.4 (2012-08-28) / Patch 6.0.2 (2014-10-14)
},
DeathMetalKnight = {
Icon = 236362,
QuestId = 47767, -- Death Metal Knight
QuestAvailable = (isRetail) -- Patch 7.2.5 (2017-06-13)
},
TestYourStrength = {
Icon = 136101,
QuestId = 29433, -- Test Your Strenght
QuestAvailable = true -- Patch 4.3.0 (2011-11-29)
},
FadedTreasureMap = { -- One time Quest starting from Vendor bought item
Icon = 237388,
QuestId = 38934, -- Silas' Secret Stash
StartItemId = 126930, -- Faded Treasure Map
QuestAvailable = (isRetail) -- Patch 6.2.0 (2015-06-23)
},
XPRepBuff = {
Icon = 237554,
SpellId = 46668, -- WHEE!
StartItemId = 81055, -- Darkmoon Ride Ticket
StartItemIcon = 134481,
ActivityAvailable = (isRetail) -- WHEE! - Patch 4.3.0 (2011-11-29) / Darkmoon Ride Ticket - Patch 5.1.0 (2012-11-27)
}
}
-- Gossips on Darkmoon Island
--[[
npcName gossipOptionID QuestId Quest
------------------------------------------------------------------------
Maxima Blastenheimer 28702 29436 The Humanoid Cannonball
Ziggie Sparks 43061 36481 Firebird's Challenge
Jessica Rogers 40225 29455 Target: Turtle
Mola 40564 29463 It's Hammer Time
Rinling 31203 29438 He Shoots, He Scores!
Finlay Coolshot 39246 29434 Tonk Commander
Simon Sezdans 52652 64783 Dance Dance Darkmoon
------------------------------------------------------------------------
local function OnEvent(self, event)
local info = C_GossipInfo.GetOptions()
for i, v in pairs(info) do
print(i, v.icon, v.name, v.gossipOptionID)
if v.icon == 132060 then -- interface/gossipframe/vendorgossipicon.blp
print("Selecting vendor gossip option.")
C_GossipInfo.SelectOption(v.gossipOptionID)
end
end
end
local f = CreateFrame("Frame")
f:RegisterEvent("GOSSIP_SHOW")
f:SetScript("OnEvent", OnEvent)
------------------------------------------------------------------------
]]--
--[[----------------------------------------------------------------------------
Helper functions
----------------------------------------------------------------------------]]--
local function Debug(text, ...)
if (not db) or (not db.debug) then return end
if text then
if text:match("%%[dfqsx%d%.]") then
(DEBUG_CHAT_FRAME or (ChatFrame3:IsShown() and ChatFrame3 or ChatFrame4)):AddMessage("|cffff9999"..ADDON_NAME..":|r " .. format(text, ...))
else
(DEBUG_CHAT_FRAME or (ChatFrame3:IsShown() and ChatFrame3 or ChatFrame4)):AddMessage("|cffff9999"..ADDON_NAME..":|r " .. strjoin(" ", text, tostringall(...)))
end
end
end
local function Print(text, ...)
if text then
if text:match("%%[dfqs%d%.]") then
DEFAULT_CHAT_FRAME:AddMessage("|cffffcc00".. ADDON_NAME ..":|r " .. format(text, ...))
else
DEFAULT_CHAT_FRAME:AddMessage("|cffffcc00".. ADDON_NAME ..":|r " .. strjoin(" ", text, tostringall(...)))
end
end
end
local function initDB(db, defaults) -- This function copies values from one table into another:
if type(db) ~= "table" then db = {} end
if type(defaults) ~= "table" then return db end
for k, v in pairs(defaults) do
if type(v) == "table" then
db[k] = initDB(db[k], v)
elseif type(v) ~= type(db[k]) then
db[k] = v
end
end
return db
end
-- COLOUR MIXING THROUGH ADDITION IN CMYK SPACE
-- Modified from https://stackoverflow.com/a/30079700
local blendColors
do
local RGB_scale = 255
local CMYK_scale = 100
local function RGB_to_CMYK(r, g, b)
if (r == 0) and (g == 0) and (b == 0) then -- black
return 0, 0, 0, CMYK_scale
end
-- RGB [0,255] -> CMY [0,1]
local c = 1 - r / RGB_scale
local m = 1 - g / RGB_scale
local y = 1 - b / RGB_scale
-- extract out K [0,1]
local min_CMY = math.min(c, m, y)
c = (c - min_CMY)
m = (m - min_CMY)
y = (y - min_CMY)
local k = min_CMY
-- rescale to the range [0,CMYK_scale]
return c * CMYK_scale, m * CMYK_scale, y * CMYK_scale, k * CMYK_scale
end
local function CMYK_to_RGB(c, m, y, k)
-- CMYK [0,100] -> RGB [0,255]
local r = RGB_scale * (1 - (c + k) / CMYK_scale)
local g = RGB_scale * (1 - (m + k) / CMYK_scale)
local b = RGB_scale * (1 - (y + k) / CMYK_scale)
Debug("<- NewColor: %.2f, %.2f, %.2f", r, g, b)
return r, g, b
end
function blendColors(list_of_colours)
local C, M, Y, K = 0, 0, 0, 0
for i = 1, #list_of_colours do
local r, g, b, o = unpack(list_of_colours[i])
local c, m, y, k = RGB_to_CMYK(r, g, b)
C = C + o * c
M = M + o * m
Y = Y + o * y
K = K + o * k
Debug("-> OldColor #%d: %.2f, %.2f, %.2f", i, r, g, b)
end
return CMYK_to_RGB(C, M, Y, K)
end
end
--[[----------------------------------------------------------------------------
EventHandler
----------------------------------------------------------------------------]]--
local f = CreateFrame("Frame", "DMFQuest", UIParent, "ResizeLayoutFrame") -- ResizeLayoutFrame
f:SetScript("OnEvent", function(self, event, ...)
Debug("===", event, tostringall(...))
return self[event] and self[event](self, event, ...)
end)
f:RegisterEvent("ADDON_LOADED")
-- Init
function f:ADDON_LOADED(event, addOnName, containsBindings)
if addOnName ~= ADDON_NAME then return end
DMFQConfig = initDB(DMFQConfig, dbDefaults)
db = DMFQConfig
self.initDone = false
self.startTime = 0
self.endTime = 0
self.addonTitle = strtrim(string.format("%s %s", ADDON_NAME, C_AddOns.GetAddOnMetadata(ADDON_NAME, "Version")))
self:RegisterEvent("PLAYER_LOGIN")
self:UnregisterEvent(event)
self.ADDON_LOADED = nil
end
function f:PLAYER_LOGIN(event)
self:CreateUI()
self:ClearAllPoints()
self:SetPoint((db.GrowDirection == 1) and "BOTTOMLEFT" or "TOPLEFT", UIParent, "BOTTOMLEFT", db.XPos, db.YPos) -- 0 = Down, 1 = Up
self:RegisterEvent("PLAYER_ENTERING_WORLD")
--self:RegisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_SHOW")
self:RegisterEvent("QUEST_LOG_UPDATE")
self:RegisterEvent("SKILL_LINES_CHANGED")
self:RegisterEvent("TRADE_SKILL_LIST_UPDATE")
self:RegisterEvent("ZONE_CHANGED")
self:RegisterEvent("ZONE_CHANGED_INDOORS")
self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
self:UnregisterEvent(event)
self.PLAYER_LOGIN = nil
end
local eventsAlreadyRegistered = false
function f:PLAYER_ENTERING_WORLD(event, isInitialLogin, isReloadingUi) -- Fires when the player logs in, /reloads the UI or zones between map instances. Basically whenever the loading screen appears.
if self:CheckForPortalZone() and self:CheckForDMF() then
if (not eventsAlreadyRegistered) then
eventsAlreadyRegistered = true
self:RegisterEvent("BAG_UPDATE_DELAYED")
--self:RegisterEvent("MERCHANT_FILTER_ITEM_UPDATE")
self:RegisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_SHOW")
--self:RegisterEvent("MERCHANT_UPDATE")
self:RegisterEvent("QUEST_ACCEPTED")
self:RegisterEvent("QUEST_DETAIL")
self:RegisterEvent("QUEST_REMOVED")
if isRetail then
self:RegisterEvent("QUEST_DATA_LOAD_RESULT")
end
end
if self.initDone then -- Limit calls to these during Login/ReloadUI
self:UpdateItemButtons()
self:UpdateTextLines()
end
if (not self:IsShown()) then
Debug("!!! Showing !!!", self:CheckForPortalZone(), self:CheckForDMF())
self:Show()
end
return
elseif (eventsAlreadyRegistered) then
eventsAlreadyRegistered = false
self:UnregisterEvent("BAG_UPDATE_DELAYED")
self:UnregisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_SHOW")
self:UnregisterEvent("QUEST_ACCEPTED")
self:UnregisterEvent("QUEST_DETAIL")
self:UnregisterEvent("QUEST_REMOVED")
if isRetail then
self:UnregisterEvent("QUEST_DATA_LOAD_RESULT")
end
end
if (self:IsShown()) and (not isFramePinned) then
Debug("!!! Hiding !!!", self:CheckForPortalZone(), self:CheckForDMF())
self:Hide()
end
end
function f:QUEST_LOG_UPDATE(event) -- Fires when the quest log updates. Fires also when the player logs in or /reloads the UI
if (not self.initDone) then
self:RegisterEvent("CALENDAR_UPDATE_EVENT_LIST") -- Triggers when your query has finished processing on the server and new calendar information is available.
C_Calendar.OpenCalendar() -- Requests calendar information from the server. Does not open the calendar frame.
self:UpdateItemButtons()
self:UpdateProfessions()
self:UpdateTextLines()
self.initDone = true -- Don't do this more than once
-- We don't actually need this, since QUEST_ACCEPTED and QUEST_REMOVED covers same things with less firing overall
self:UnregisterEvent(event)
self.QUEST_LOG_UPDATE = nil
end
end
function f:CALENDAR_UPDATE_EVENT_LIST(event) -- Fired when Calendar data is available
self:UnregisterEvent(event)
if self:CheckForDMF() then
--C_Timer.After(1, function()
Print(GREEN_FONT_COLOR:WrapTextInColorCode(L.ChatMessage_Login_DMFWarning))
--end)
end
self.CALENDAR_UPDATE_EVENT_LIST = nil
end
-- Professions
function f:SKILL_LINES_CHANGED(event) -- Only fires for major changes to the list, such as learning or unlearning a skill or raising one's level from Journeyman to Master. It doesn't fire for skill rank increases.
if self.initDone then
self:UpdateProfessions()
self:UpdateTextLines()
end
end
f.TRADE_SKILL_LIST_UPDATE = f.SKILL_LINES_CHANGED
-- Zones
-- Call PLAYER_ENTERING_WORLD, because it does the exact thing we want to do when ZONE_CHANGED* events fire
f.ZONE_CHANGED = f.PLAYER_ENTERING_WORLD -- Fires when the player enters an outdoors subzone.
f.ZONE_CHANGED_INDOORS = f.PLAYER_ENTERING_WORLD -- Fires when the player enters an indoors subzone.
f.ZONE_CHANGED_NEW_AREA = f.PLAYER_ENTERING_WORLD -- Fires when the player enters a new zone.
-- Merchant
local lockAutoBuy = false
do -- AutoBuy trigger and throttling
local function DelayedAutoBuy(...)
f:AutoBuyItems()
end
function f:PLAYER_INTERACTION_MANAGER_FRAME_SHOW(event, interactionType) -- Show and Hide events have been streamlined into PLAYER_INTERACTION_MANAGER_FRAME_SHOW/HIDE in 10.0
if interactionType == Enum.PlayerInteractionType.Merchant then
--f.MERCHANT_UPDATE()
if (not lockAutoBuy) then
local questLogIndex
if isRetail then -- 29506 = A Fizzy Fusion
questLogIndex = C_QuestLog.GetLogIndexForQuestID(29506)
else
questLogIndex = GetQuestLogIndexByID(29506)
end
if f:CheckForDMF() and (f:IsShown() or (questLogIndex and questLogIndex > 0)) then
lockAutoBuy = true
Debug("++ Lock AutoBuy")
C_Timer.After(0, DelayedAutoBuy) -- Fire on next frame
else
Debug(" !!! Something weird happened !!!", tostring(f:CheckForDMF()), tostring(f:IsShown()), tostring(questLogIndex))
end
else
Debug(" !!! Block AutoBuy !!!")
end
end
end
end
-- Bags
do -- UpdateItemButtons and UpdateTextLines throttling
local function DelayedUpdateItemButtons(...)
f:UpdateItemButtons()
f:UpdateTextLines()
if lockAutoBuy then
lockAutoBuy = false
Debug("-- Unlock AutoBuy")
end
end
function f:BAG_UPDATE_DELAYED(event) -- Fired after all applicable BAG_UPDATE events for a specific action have been fired.
-- This fires only once or twice for all the items, BAG_UPDATE fires twice per item
C_Timer.After(0, DelayedUpdateItemButtons) -- Fire on next frame in hopes we don't fire this for more than once
end
f.BAG_UPDATE_COOLDOWN = f.BAG_UPDATE_DELAYED -- WHEE! -buff
end
-- Quests
function f:QUEST_ACCEPTED(event, questId)
self:UpdateItemButtons()
end
function f:QUEST_DETAIL(event, questStartItemID) -- Fired when the player is given a more detailed view of his quest.
if questStartItemID and turnInItems[questStartItemID] then -- Don't auto-accept any other quests than turn-in items
Debug(" <= Found Quest")
AcceptQuest()
elseif questStartItemID and questStartItemID == 0 then -- At least on PTR for some reason questStartItemID is 0?
Debug("- Falling back, arey you on PTR?")
local questId = GetQuestID()
for _, qId in pairs(turnInItems) do
if qId == questId then
Debug(" <== Found Quest")
AcceptQuest()
break
end
end
end
end
function f:QUEST_REMOVED(event, questID, wasReplayQuest)
self:UpdateItemButtons()
end
local questDataRequests = {}
-- Check if out previously requested QuestData from f:UpdateTextLines() has arrived
function f:QUEST_DATA_LOAD_RESULT(questID, success) -- Retail only ATM
if questDataRequests[questID] then --and success then -- At least on PTR success always seems to return false
questDataRequests[questID] = nil
self:UpdateTextLines()
end
end
--[[----------------------------------------------------------------------------
Functions
----------------------------------------------------------------------------]]--
-- Create UI
local function _onEnterShowTooltip(self, motion) -- Show Tooltip
self.buttonIcon:SetVertexColor(buttonVertices[self.itemStatus][4], buttonVertices[self.itemStatus][5], buttonVertices[self.itemStatus][6])
GameTooltip:ClearLines()
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine(self.tooltipText)
if db.ShowItemRewards and (self.itemStatus ~= 1) then -- Don't show rewards for already completed quests
local info = C_CurrencyInfo.GetCurrencyInfo(515)
local count = rewardsTable[self.itemId] or "?"
GameTooltip:AddLine(GARRISON_MISSION_REWARD_HEADER .. " |T".. info.iconFileID ..":16:16:0:0:32:32:2:30:2:30|t " .. count .. " " .. info.name) -- 134481, Darkmoon Prize Ticket
end
GameTooltip:Show() -- Region:Show() resizes the tooltip and reapplies any anchor defined with SetOwner().
end
local function _onLeaveHideTooltip(self, motion) -- Hide Tooltip
self.buttonIcon:SetVertexColor(buttonVertices[self.itemStatus][1], buttonVertices[self.itemStatus][2], buttonVertices[self.itemStatus][3])
GameTooltip:Hide()
end
function f:CreateUI()
Debug("CreateUI")
local scalerForClassic = isRetail and 1 or 324/410 -- ~.79% in Classic
self.fixedWidth = 324 * scalerForClassic
self.minimumHeight = 150
self.heightPadding = 72 -- (TopBorder 2px, Title 20px, TopSeparator 2px) + (TopPadding 6px, Text [Dynamic], BottomPadding 6px) + (BottomSeparator 2px, Buttons 32px, BottomBorder 2px)
--[[
Texture Slicing (New in 10.2)
-----------------------------
This system is recommended to be used in new code going forward as a replacement for both the deprecated Backdrop system
and the script-based NineSlice panel layout utility. One of the advantages of this new system is that it only requires a
single texture object to render the grid, whereas both the old systems required nine separate objects. This system is
fully compatible with custom texture assets and does not require the use of atlases.
]]
-- Background
local backgroundTex = self:CreateTexture()
backgroundTex:SetTexture("Interface\\AddOns\\DMFQuest\\BackgroundTexture8x64.png")
backgroundTex:SetTextureSliceMargins(2, 24, 2, 36) -- left, top, right, bottom
backgroundTex:SetTextureSliceMode(Enum.UITextureSliceMode.Tiled)
backgroundTex:SetAllPoints(self)
backgroundTex:SetVertexColor(db.FrameVertexColor[1], db.FrameVertexColor[2], db.FrameVertexColor[3])
self.Background = backgroundTex
-- TitleText
local titleText = self:CreateFontString(nil, "OVERLAY", "GameFontNormal") -- FontSize 12
titleText:SetPoint("CENTER", self, "TOP", 0, -12 * scalerForClassic)
titleText:SetText(self.addonTitle)
self.TitleText = titleText
-- Drag
self:SetMovable(true)
self:SetClampedToScreen(true)
self:EnableMouse(true)
self:RegisterForDrag("LeftButton")
self:SetScript("OnDragStart", function(self, button) -- self, button
if db.FrameLock then return end
self.StartMoving(self, button)
end)
self:SetScript("OnDragStop", function(self) -- self
self:StopMovingOrSizing()
db.XPos = self:GetLeft()
db.YPos = (db.GrowDirection == 1) and self:GetBottom() or self:GetTop() -- 0 = Down, 1 = Up
self:ClearAllPoints()
self:SetPoint((db.GrowDirection == 1) and "BOTTOMLEFT" or "TOPLEFT", UIParent, "BOTTOMLEFT", db.XPos, db.YPos) -- 0 = Down, 1 = Up
end)
self:SetScript("OnHide", f.StopMovingOrSizing)
-- CloseButton
local closeButton = CreateFrame("Button", nil, self, "UIPanelCloseButton")
closeButton:SetSize(28, 28)
if isRetail then
Debug("closeButton:SetPoint -> isRetail")
closeButton:SetPoint("TOPRIGHT", 2, 1)
else -- Positioning is off in CataClassic?
Debug("closeButton:SetPoint -> !isRetail")
closeButton:SetPoint("TOPRIGHT", 5, 5)
end
closeButton:GetNormalTexture():SetVertexColor(
blendColors(
{
{ db.FrameVertexColor[1], db.FrameVertexColor[2], db.FrameVertexColor[3], .5 },
{ 1, 1, 1, .5 }
}
)
)
self.CloseButton = closeButton
-- CloseButton doesn't make sound when clicked
closeButton:SetScript("OnClick", function(self, button, down)
Debug("CloseButton OnClick", self:GetParent():GetName(), button, down)
--PlaySound(SOUNDKIT.IG_CHARACTER_INFO_CLOSE)
PlaySound(SOUNDKIT.U_CHAT_SCROLL_BUTTON)
--self:GetParent():Hide()
f:Hide()
isFramePinned = false
f.TitleText:SetText(f.addonTitle)
end)
-- ItemButtons
for i = 1, maxItemButtonCount do
local b = CreateFrame("Button", nil, self)
b:SetSize(32, 32)
if isCataClassic then -- Buttons are too big in CataClassic, ~40px instead of 32px?
b:SetScale(scalerForClassic)
end
b.tooltipText = ""
b.itemStatus = 4
b:SetScript("OnEnter", _onEnterShowTooltip)
b:SetScript("OnLeave", _onLeaveHideTooltip)
local tex = b:CreateTexture()
tex:SetAllPoints()
b.buttonIcon = tex
b:SetPoint("BOTTOMLEFT", (i - 1) * 32 + 2, 2)
local item = Item:CreateFromItemID(itemButtonOrder[i])
item:ContinueOnItemLoad(function()
b.itemId = itemButtonOrder[i]
b.itemName = item:GetItemName()
b.itemLink = item:GetItemLink()
local tex = item:GetItemIcon()
b.buttonIcon:SetTexture(tex)
Debug(" - Button", i, b.itemName)
end)
self["itemButton" .. i] = b
self:MarkIgnoreInLayout(b) -- Ignore these objects when calculating the size for the Frame
end
-- Profession Container
local prefessionContainer = CreateFrame("Frame", nil, self, "ResizeLayoutFrame") -- ResizeLayoutFrame
prefessionContainer.fixedWidth = 320 * scalerForClassic
prefessionContainer.minimumHeight = 50
prefessionContainer:SetPoint("TOP", 0, -24)
self.Container = prefessionContainer
-- TextLine
local containerText = self:CreateFontString(nil, "OVERLAY", "Game15Font_o1") -- "GameFontHighlight")
containerText:SetPoint("CENTER", 0, 6) -- Y-offset is the size difference between the Title+Button Bars (with edges) and the Frame minimum size divided by two ((72-60)/2) and maybe adjusted by one (+1) to make the text look more natural
containerText:SetText("\n" .. ADDON_NAME .. " Loaded!\n\n")
--containerText:SetText(ADDON_NAME .. " Loaded!\n\n§1234567890+´+\n½!\"#¤%&/()=?`\n\nqwertyuiopå¨\nQWERTYUIOPÅ^\n\nasdfghjklöä'\nASDFGHJKLÖÄ*\n\n<zxcvbnm,.-\n>ZXCVBNM;:_") -- Debug
self.ContainerText = containerText
self:MarkIgnoreInLayout(backgroundTex, titleText, closeButton, containerText) -- Ignore these objects when calculating the size for the Frame
--self:Show()
self:Layout() -- Resize UI
self.CreateUI = nil
end
-- CheckForDMF
local function _shiftTimeTables(timeData) -- Shift timeData if needed
if (not db.UseTimeOffset) then
return timeData
end
timeData.hour = timeData.hour + db.TimeOffsetValue
if timeData.hour < 0 then
timeData.monthDay = timeData.monthDay - 1
timeData.hour = timeData.monthDay + 24
elseif timeData.hour > 23 then
timeData.monthDay = timeData.monthDay + 1
timeData.hour = timeData.hour - 24
end
local monthInfo = C_Calendar.GetMonthInfo(0)
local previousMonthInfo = C_Calendar.GetMonthInfo(-1)
if timeData.monthDay <= 0 then
timeData.month = timeData.month - 1
timeData.monthDay = previousMonthInfo.numDays
elseif timeData.monthDay > monthInfo.numDays then
timeData.month = timeData.month + 1
timeData.monthDay = 1
end
if timeData.month <= 0 then
timeData.year = timeData.year - 1
timeData.month = 12
elseif timeData.month > 12 then
timeData.year = timeData.year + 1
timeData.month = 1
end
return timeData
end
local function _epochToHumanReadable(epoch) -- Turn epoch into Human readable
local mins, hours, days, returnString = 0, 0, 0, ""
while epoch >= 86400 do
days = days + 1
epoch = epoch - 86400
end
if days > 0 then
returnString = returnString .. string.format("%d %s, ", days, days > 1 and "days" or "day")
end
while epoch >= 3600 do
hours = hours + 1
epoch = epoch - 3600
end
if hours > 0 then
returnString = returnString .. string.format("%d %s, ", hours, hours > 1 and "hours" or "hour")
end
while epoch >= 60 do
mins = mins + 1
epoch = epoch - 60
end
if mins > 0 then
returnString = returnString .. string.format("%d %s, ", mins, mins > 1 and "mins" or "min")
end
if epoch > 0 then
returnString = returnString .. string.format("%d %s", epoch, epoch > 1 and "secs" or "sec")
end
return strtrim(returnString, " ,")
end
function f:CheckForDMF() -- Check Calendar for if DMF is on
Debug("CheckForDMF")
local currentCalendarTime = C_DateAndTime.GetCurrentCalendarTime()
--[[
CalendarTime
Field Type Description
year number The current year (e.g. 2019)
month number The current month [1-12]
monthDay number The current day of the month [1-31]
weekday number The current day of the week (1=Sunday, 2=Monday, ..., 7=Saturday)
hour number The current time in hours [0-23]
minute number The current time in minutes [0-59]
]]--
if self.startTime > 0 and self.endTime > 0 then
if (db.debug and db.isPTR) then currentCalendarTime.monthDay = ptrDebugDay end -- PTR Debug
currentCalendarTime.day = currentCalendarTime.monthDay
local currentEpoch = time(currentCalendarTime)
if currentEpoch >= self.startTime and currentEpoch <= self.endTime then
Debug(" <= Exit via shortcut:", _epochToHumanReadable(currentEpoch - self.startTime), "<-", currentEpoch, "->", _epochToHumanReadable(self.endTime - currentEpoch))
return true
end
Debug("- Reset startTime and endTime:", _epochToHumanReadable(currentEpoch - self.startTime), "<-", currentEpoch, "->", _epochToHumanReadable(self.endTime - currentEpoch))
self.startTime = 0
self.endTime = 0
end
local searchResult, openMonth, openYear
if CalendarFrame and CalendarFrame:IsShown() then -- Get current open month in calendar view
Debug("- Save Open")