forked from RestedXP/RXPGuides
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.lua
2679 lines (2391 loc) · 82.4 KB
/
functions.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 faction = UnitFactionGroup("player")
local _,class = UnitClass("player")
RXP_.functions = {}
RXP_.functions.__index = RXP_.functions
RXP_.functions.events = {}
RXP_.stepUpdateList = {}
RXP_.functions.events.collect = {"BAG_UPDATE_DELAYED","QUEST_ACCEPTED","QUEST_TURNED_IN"}
RXP_.functions.events.buy = {"BAG_UPDATE_DELAYED","MERCHANT_SHOW"}
RXP_.functions.events.accept = {"QUEST_ACCEPTED","QUEST_TURNED_IN","QUEST_REMOVED"}
RXP_.functions.events.turnin = {"QUEST_TURNED_IN"}
RXP_.functions.events.complete = {"QUEST_LOG_UPDATE"}
RXP_.functions.events.fp = {"UI_INFO_MESSAGE","TAXIMAP_OPENED"}
RXP_.functions.events.hs = {"UNIT_SPELLCAST_SUCCEEDED"}
RXP_.functions.events.home = {"HEARTHSTONE_BOUND"}
RXP_.functions.events.fly = {"PLAYER_CONTROL_LOST","TAXIMAP_OPENED","ZONE_CHANGED"}
RXP_.functions.events.deathskip = {"CONFIRM_XP_LOSS"}
RXP_.functions.events.xp = {"PLAYER_XP_UPDATE","PLAYER_LEVEL_UP"}
RXP_.functions.events.reputation = {"UPDATE_FACTION"}
RXP_.functions.events.vendor = {"MERCHANT_SHOW","MERCHANT_CLOSED"}
RXP_.functions.events.trainer = {"TRAINER_SHOW","TRAINER_CLOSED"}
RXP_.functions.events.stable = {"PET_STABLE_SHOW","PET_STABLE_CLOSED"}
RXP_.functions.events.tame = {"UNIT_SPELLCAST_SUCCEEDED","UNIT_SPELLCAST_START"}
RXP_.functions.events.money = {"PLAYER_MONEY"}
RXP_.functions.events.train = {"TRAINER_SHOW","CHAT_MSG_SYSTEM","SKILL_LINES_CHANGED","TRAINER_UPDATE"}
RXP_.functions.events.istrained = {"LEARNED_SPELL_IN_TAB","TRAINER_UPDATE"}
RXP_.functions.events.zone = {"ZONE_CHANGED_NEW_AREA"}
RXP_.functions.events.bankdeposit = {"BANKFRAME_OPENED","BAG_UPDATE_DELAYED"}
RXP_.functions.events.skipgossip = {"GOSSIP_SHOW"}
RXP_.functions.events.bankwithdraw = RXP_.functions.events.bankdeposit
RXP_.functions.events.abandon = RXP_.functions.events.complete
RXP_.functions.events.isQuestComplete = RXP_.functions.events.complete
RXP_.functions.events.isOnQuest = RXP_.functions.events.complete
RXP_.functions.events.isQuestTurnedIn = RXP_.functions.events.complete
RXP_.functions.events.cast = RXP_.functions.events.hs
RXP_.functions.events.blastedLands = RXP_.functions.events.collect
RXP_.icons = {
accept = "|TInterface/GossipFrame/AvailableQuestIcon:0|t",
turnin = "|TInterface/GossipFrame/ActiveQuestIcon:0|t",
collect = "|TInterface/GossipFrame/VendorGossipIcon:0|t",
combat = "|TInterface/GossipFrame/BattleMasterGossipIcon:0|t",
complete = "|TInterface/GossipFrame/HealerGossipIcon:0|t",
vendor = "|TInterface/GossipFrame/BankerGossipIcon:0|t",
reputation = "|TInterface/GossipFrame/WorkOrderGossipIcon:0|t",
fly = "|TInterface/GossipFrame/TaxiGossipIcon:0|t",
fp = "|TInterface/AddOns/RXPGuides/Textures/fp:0|t",
hs = "|TInterface/MINIMAP/TRACKING/Innkeeper:0|t",
trainer = "|TInterface/GossipFrame/TrainerGossipIcon:0|t",
train = "|TInterface/GossipFrame/TrainerGossipIcon:0|t",
arrow = "|TInterface/MINIMAP/MinimapArrow:0|t",
marker = "|TInterface/WORLDSTATEFRAME/ColumnIcon-FlagCapture2:0|t",
goto = "|TInterface/MINIMAP/POIICONS:0:0:0:0:128:128:96:112:0:15|t",
deathskip = "|TInterface/MINIMAP/POIICONS:0:0:0:0:128:128:112:127:0:15|t",
home = "|TInterface/MINIMAP/POIICONS:0:0:0:0:128:128:64:79:0:15|t",
xp = "|TInterface/PETBATTLES/BattleBar-AbilityBadge-Strong-Small:0|t",
stable = "|TInterface/MINIMAP/TRACKING/StableMaster:0|t",
tame = "|TInterface/ICONS/Ability_Hunter_BeastTaming:0|t",
abandon = "|TInterface/GossipFrame/IncompleteQuestIcon:0|t",
link = "|TInterface/FriendsFrame/UI-FriendsFrame-Link:0|t",
error = "|TInterface/Buttons/UI-GroupLoot-Pass-Up:0|t",
}
RXP_.icons.buy = RXP_.icons.collect
RXP_.icons.xpto60 = RXP_.icons.xp
function RXP_.error(msg)
print(msg)
return
end
local GetNumQuests = C_QuestLog.GetNumQuestLogEntries or GetNumQuestLogEntries
local IsQuestTurnedIn = C_QuestLog.IsQuestFlaggedCompleted
if not IsQuestTurnedIn then
IsQuestTurnedIn = IsQuestFlaggedCompleted
if not IsQuestTurnedIn then
IsQuestTurnedIn = function(id)
return GetQuestsCompleted()[id]
end
end
end
local function IsQuestComplete(id)
if GetNumQuestLogEntries then
for i = 1,GetNumQuestLogEntries() do
local questLogTitleText, level, questTag, isHeader, isCollapsed, isComplete, frequency, questID = GetQuestLogTitle(i);
if questID == id then
if isComplete then
return true
else
return false
end
end
end
else
return C_QuestLog.IsComplete(id)
end
end
local function IsOnQuest(id)
return C_QuestLog.IsOnQuest(id)
end
RXP_.IsQuestTurnedIn = IsQuestTurnedIn
RXP_.IsQuestComplete = IsQuestComplete
local questConversion = {
[9684] = 63866,
}
local timer = GetTime()
local nrequests = 0
local requests = {}
local questNameCache = {}
local questObjectivesCache = {}
local db
if QuestieLoader then
db = QuestieLoader:ImportModule("QuestieDB")
end
function RXP_.FormatNumber(number,precision)
if not precision then
precision = 0
end
local integer = math.floor(number)
local decimal = math.floor((number-integer)*10^precision+0.5)
if decimal > 0 then
decimal = '.'..tostring(decimal)
else
decimal = ""
end
integer = tostring(integer)
local i = #integer % 3
if i == 0 then
i = 3
end
local suffix = string.sub(integer,i+1)
integer = string.sub(integer,1,i)
for n in string.gmatch(suffix,"%d%d%d") do
integer = integer..","..n
end
return integer..decimal
end
function RXP_.GetQuestName(id)
if not id then return end
id = questConversion[id] or id
if db and type(db.QueryQuest) == "function" and type(db.GetQuest) == "function" then
local quest = db:GetQuest(id)
if quest and quest.name then
return quest.name
end
end
if IsOnQuest(id) then
if GetQuestLogTitle then
for i = 1,GetNumQuests() do
local questLogTitleText, level, questTag, isHeader, isCollapsed, isComplete, frequency, questID = GetQuestLogTitle(i);
if questID == id then
questNameCache[id] = questLogTitleText
return questLogTitleText
end
end
else
return C_QuestLog.GetInfo(id)
end
else
local ctime = GetTime()
if ctime - timer > 1 then
timer = ctime
nrequests = 0
end
if nrequests < 3 or requests[id] == 0 then
if (not requests[id] or ctime-requests[id] > 3) and HaveQuestData(id) then
requests[id] = 0
if C_QuestLog.GetQuestInfo then
return C_QuestLog.GetQuestInfo(id)
else
return C_QuestLog.GetInfo(id)
end
elseif not requests[id] then
requests[id] = GetTime()
elseif ctime-requests[id] <= 3 then
return questNameCache[id]
else
requests[id] = GetTime()
end
nrequests = nrequests + 1
end
return questNameCache[id]
end
end
function RXP_.GetQuestObjectives(id,step)
id = questConversion[id] or id
step = step or 0
if not id then return end
local err = false
if IsOnQuest(id) then
local questInfo = {}
for i = 1,GetNumQuests() do
local questLogTitleText, level, questTag, isHeader, isCollapsed, isComplete, frequency, questID
if GetQuestLogTitle then
questLogTitleText, level, questTag, isHeader, isCollapsed, isComplete, frequency, questID = GetQuestLogTitle(i);
else
qInfo = C_QuestLog.GetInfo(i)
questID = qInfo.questID
isHeader = qInfo.isHeader
if questID then
isComplete = C_QuestLog.IsComplete(questID)
end
end
local nObj = 0
if questID == id then
for j = 1,GetNumQuestLeaderBoards(i) do
local description, objectiveType, isCompleted = GetQuestLogLeaderBoard(j,i)
if description then
nObj = nObj + 1
local required,fulfilled = description:match("(%d+)/(%d+)")
if required then
required = tonumber(required)
fulfilled = tonumber(fulfilled)
else
required = 1
if isCompleted then
fulfilled = 1
else
fulfilled = 0
end
end
questInfo[j] = {text = description, type = objectiveType,numRequired = required, numFulfilled = fulfilled, finished = isCompleted}
else
err = true
break
end
end
if (err or nObj == 0) and GetNumQuestLeaderBoards(i) <= 1 then
local fulfilled = 0
if isComplete then
fulfilled = 1
end
questInfo[1] = { text = "Objective Complete", type = "event",numRequired = 1, numFulfilled = fulfilled, finished = isComplete }
questObjectivesCache[id] = questInfo
return questInfo
else
questObjectivesCache[id] = questInfo
return questInfo
end
end
end
elseif db and type(db.QueryQuest) == "function" and math.abs(RXPCData.currentStep-step) > 4 and type(db.GetQuest) == "function" then
local qInfo = {}
local q = db:GetQuest(id)
--print(type(q))
local objectives
if q and q.ObjectiveData then
objectives = q.ObjectiveData
else
err = true
end
if objectives then
local nObj = 0
for i,quest in pairs(objectives) do
nObj = nObj + 1
local qType = quest.Type
local objId = quest.Id
qInfo[i] = {type = qType, finished = false, questie = true}
if qType == "monster" then
local npc = db:GetNPC(objId)
if npc and npc.name then
qInfo[i].text = npc.name
else
qInfo[i].text = ""
end
elseif qType == "item" then
qInfo[i].text = db:GetItem(objId).name
elseif quest.Text then
qInfo[i].text = quest.Text
else
err = true
break
end
end
end
if not err then
if nObj == 0 then
qInfo[1] = { text = "Objective Complete", type = "event",numRequired = 1, numFulfilled = 0, finished = false }
end
return qInfo
end
end
if not IsOnQuest(id) or err then
local ctime = GetTime()
if ctime - timer > 1 then
timer = ctime
nrequests = 0
end
if nrequests < 3 or requests[id] == 0 then
if (not requests[id] or ctime-requests[id] > 3) and HaveQuestData(id) then
requests[id] = 0
--print(id,GetTime()-base)
local questInfo = C_QuestLog.GetQuestObjectives(id)
if (#questInfo == 1 and (questInfo[1].type == "" or not questInfo[1].type)) or #questInfo == 0 then
questInfo[1] = { text = "Objective Complete", type = "event",numRequired = 1, numFulfilled = 0, finished = false }
end
return questInfo
elseif not requests[id] then
requests[id] = GetTime()
elseif ctime-requests[id] <= 3 then
return questObjectivesCache[id]
else
requests[id] = GetTime()
end
--print(id,GetTime()-base)
nrequests = nrequests + 1
end
return questObjectivesCache[id]
end
end
function RXP_.GetItemName(id)
local name = GetItemInfo(id)
if not name then
RXP_.itemQueryList[id] = true
end
return name
end
function RXP_.SetElementComplete(self,disable)
if not self.element.completed then
self.element.completed = true
self.element.skip = true
RXP_.updateSteps = true
RXP_.updateMap = true
end
if self.button then
--print('----ok',disable)
self.button:SetChecked(true)
if disable then
self.button:Disable()
end
end
end
function RXP_.SetElementIncomplete(self)
if self.element.completed then
self.element.completed = false
RXP_.updateMap = true
end
if self.button then
self.button:Enable()
if not self.element.skip then
self.button:SetChecked(false)
end
end
end
function RXP_.UpdateStepText(self)
RXP_.updateStepText = true
local index
if type(self) == "number" then
index = self
else
index = self.step.index
end
RXP_.stepUpdateList[index] = true
end
function RXP_.AldorScryerCheck(faction)
if RXP_.version == "CLASSIC" then return true end
local name, description, standingID, barMin, barMax, aldorRep = GetFactionInfoByID(932)
local name, description, standingID, barMin, barMax, scryerRep = GetFactionInfoByID(934)
if aldorRep and scryerRep then
if type(faction) == "table" then
if faction.aldor then
faction = "Aldor"
elseif faction.scryer then
faction = "Scryer"
end
end
if faction == "Aldor" then
return (aldorRep > scryerRep)
elseif faction == "Scryer" then
return (aldorRep < scryerRep)
end
end
return true
end
function RXP_.PhaseCheck(phase)
local guide
if type(phase) == "table" then
guide = phase
phase = phase.phase
end
if phase and RXPCData and RXPCData.phase then
local pmin,pmax
pmin,pmax = phase:match("(%d+)%-(%d+)")
if pmax then
pmin = tonumber(pmin)
pmax = tonumber(pmax)
else
pmin = tonumber(phase)
pmax = 0xffff
end
if pmin and RXPCData.phase >= pmin and RXPCData.phase <= pmax then
return true
else
return false
end
end
return true
end
function RXP_.SeasonCheck(step)
if RXPCData.SoM and step.era or step.som and not RXPCData.SoM or RXPCData.SoM and RXPCData.phase > 2 and step["era/som"] then
return false
end
return true
end
function RXP_.HardcoreCheck(step)
local hc = RXPCData.hardcore
if step.softcore and hc or step.hardcore and not hc then
return false
end
return true
end
function RXP_.GetNpcId(unit)
if not unit then
unit = "target"
end
local _, _, _, _, _, npcId = strsplit('-', UnitGUID(unit) or '')
return tonumber(npcId)
end
local HBD = LibStub("HereBeDragons-2.0")
local HBDPins = LibStub("HereBeDragons-Pins-2.0")
RXP_.pickUpList = {}
function RXP_.functions.accept(self,...)
if type(self) == "string" then --on parse
local element = {}
element.tag = "accept"
local text,id = ...
id = tonumber(id)
if not id then return RXP_.error("Error parsing guide "..RXP_.currentGuideName..": Invalid quest ID\n"..self) end
element.title = ""
element.questId = questConversion[id] or id
--element.title = RXP_.GetQuestName(id)
if text and text ~= "" then
element.text = text
else
element.text = "Accept *quest*"
element.requestFromServer = true
end
if element.text:match("%*quest%*") then
element.retrieveText = true
end
element.tooltipText = RXP_.icons.accept..element.text
if not RXP_.pickUpList[id] then
RXP_.pickUpList[id] = ""
end
local step = RXP_.step
local stepType = ""
if step.hardcore then
stepType = "!"
elseif step.softcore then
stepType = "#"
end
if step.som then
stepType = stepType .. "+"
elseif step.era then
stepType = stepType .. "-"
end
if step.phase then
stepType = stepType .. "["..step.phase.."]"
end
RXP_.pickUpList[id] = format("%s\n%s %s",RXP_.pickUpList[id],stepType,RXP_.currentGuideName)
return element
else
local element = self.element
local step = element.step
local event,arg1,questId = ...
local id = element.questId
local isQuestAccepted = IsQuestTurnedIn(id) or IsOnQuest(id) or (event == "QUEST_ACCEPTED" and questId == id)
if element.step.active or element.retrieveText or (element.step.index > 1 and RXP_.currentGuide.steps[element.step.index-1].active) then
RXP_.questAccept[id] = element
local quest = RXP_.GetQuestName(id,element)
if quest then
element.title = quest
RXP_.questAccept[quest] = element
element.text = element.text:gsub("%*quest%*",quest)
if element.requestFromServer then
element.requestFromServer = nil
RXP_.UpdateStepText(self)
end
else
element.title = ""
element.requestFromServer = true
end
end
local icon = RXP_.icons.accept
local skip
if step.active and db and type(db.QueryQuest) == "function" and not isQuestAccepted and not RXP_.skipPreReq[id] then
local quest = db:GetQuest(id)
if quest then
local preQuest = quest:IsPreQuestGroupFulfilled() and quest:IsPreQuestSingleFulfilled()
if quest.preQuestSingle then
for _,qID in pairs(quest.preQuestSingle) do
if RXP_.questTurnIn[qID] and (RXP_.questAccept[qID] or IsOnQuest(qID)) then
preQuest = quest:IsPreQuestGroupFulfilled()
break
end
end
end
if not preQuest then
local requiredQuests
requiredQuests = quest.preQuestGroup or quest.preQuestSingle or {}
local tooltip = RXP_.colors.tooltip.."Missing pre-requisites:|r\n"
for i,qid in ipairs(requiredQuests) do
tooltip = format("%s\n%s%s (%d)",tooltip,RXP_.icons.turnin,db:GetQuest(qid).name,qid)
end
element.tooltip = tooltip
element.icon = RXP_.icons.error
skip = RXPData.skipMissingPreReqs
else
element.icon = icon
element.tooltip = nil
end
end
else
element.icon = icon
element.tooltip = nil
end
element.tooltipText = RXP_.icons.accept..element.text
local completed = element.completed
if isQuestAccepted then
RXP_.SetElementComplete(self,true)
elseif skip then
RXP_.SetElementComplete(self)
elseif event == "QUEST_REMOVED" and arg1 == id and not element.skip then
RXP_.SetElementIncomplete(self)
end
local function ProcessItems(value)
local qItem = RXP_.questAcceptItems[questId]
if not qItem then return end
if not step.activeItems then step.activeItems = {} end
if type(qItem) == "table" then
for _,item in pairs(qItem) do
step.activeItems[item] = value
end
else
step.activeItems[qItem] = value
end
end
if step.active then
if event then
local itemFrame = self.GetParent and self:GetParent().activeItemFrame
if completed ~= element.completed and itemFrame then
ProcessItems(not element.completed)
RXP_.UpdateItemFrame(itemFrame)
end
else
ProcessItems(true)
end
end
end
end
RXP_.turnInList = {}
function RXP_.functions.turnin(self,...)
if type(self) == "string" then --on parse
local element = {}
element.tag = "turnin"
local text,id,reward = ...
id = tonumber(id)
if not id then return RXP_.error("Error parsing guide "..RXP_.currentGuideName..": Invalid quest ID\n"..self) end
element.questId = questConversion[id] or id
element.reward = tonumber(reward) or 0
element.title = ""
--element.title = RXP_.GetQuestName(id)
if text and text ~= "" then
element.text = text
else
element.text = "Turn in *quest*"
element.requestFromServer = true
end
if element.text:match("%*quest%*") then
element.retrieveText = true
end
element.tooltipText = RXP_.icons.turnin..element.text
if not RXP_.turnInList[id] then
RXP_.turnInList[id] = ""
end
local step = RXP_.step
local stepType = ""
if step.hardcore then
stepType = "!"
elseif step.softcore then
stepType = "#"
end
if step.som then
stepType = stepType .. "+"
elseif step.era then
stepType = stepType .. "-"
end
if step.phase then
stepType = stepType .. "["..step.phase.."]"
end
RXP_.turnInList[id] = format("%s\n%s %s",RXP_.turnInList[id],stepType,RXP_.currentGuideName)
return element
else
local element = self.element
local step = element.step
local event,questId = ...
local id = element.questId
if step.active or element.retrieveText then
RXP_.questTurnIn[id] = element
RXP_.questAccept[id] = RXP_.questAccept[id] or element
local quest = RXP_.GetQuestName(id,true)
if quest then
element.title = quest
RXP_.questTurnIn[quest] = element
RXP_.questAccept[quest] = RXP_.questAccept[quest] or element
element.text = element.text:gsub("%*quest%*",quest)
if element.requestFromServer then
element.requestFromServer = nil
RXP_.UpdateStepText(self)
end
else
element.title = ""
element.requestFromServer = true
end
end
local icon = RXP_.icons.turnin
local skip
if step.active and db and type(db.QueryQuest) == "function" and not RXP_.questAccept[id] and not RXP_.skipPreReq[id] then
local quest = db:GetQuest(id)
if not IsOnQuest(id) and quest and not quest.IsRepeatable then
local requiredQuests = {}
local preQuest = quest:IsPreQuestGroupFulfilled() and quest:IsPreQuestSingleFulfilled()
local questList
if not preQuest then
questList = quest.preQuestGroup or quest.preQuestSingle
end
if questList then
for _,qID in ipairs(questList) do
table.insert(requiredQuests,qID)
end
end
table.insert(requiredQuests,id)
local tooltip = RXP_.colors.tooltip.."Missing pre-requisites:|r\n"
for i,qid in ipairs(requiredQuests) do
if i < #requiredQuests then
tooltip = format("%s\n%s%s (%d)",tooltip,RXP_.icons.turnin,db:GetQuest(qid).name,qid)
else
tooltip = format("%s\n%s%s (%d)",tooltip,RXP_.icons.accept,db:GetQuest(qid).name,qid)
end
end
element.tooltip = tooltip
element.icon = RXP_.icons.error
skip = RXPData.skipMissingPreReqs
else
element.icon = icon
element.tooltip = nil
end
else
element.icon = icon
element.tooltip = nil
end
element.tooltipText = element.icon..element.text
RXP_.UpdateStepText(self)
local completed = element.completed
local isComplete = IsQuestTurnedIn(id)
if isComplete then
RXP_.SetElementComplete(self,true)
elseif questId == id or skip then --repeatable quests
RXP_.SetElementComplete(self)
end
local function ProcessItems(value)
local qItem = RXP_.questTurnInItems[questId]
if not qItem then return end
if not step.activeItems then step.activeItems = {} end
if type(qItem) == "table" then
for _,item in pairs(qItem) do
step.activeItems[item] = value
end
else
step.activeItems[qItem] = value
end
end
if step.active then
if event then
local itemFrame = self.GetParent and self:GetParent().activeItemFrame
if completed ~= element.completed and itemFrame then
ProcessItems(not element.completed)
RXP_.UpdateItemFrame(itemFrame)
end
else
ProcessItems(true)
end
end
end
end
local questMonster = string.gsub(QUEST_MONSTERS_KILLED,"%d+%$","")
questMonster = questMonster:gsub("%%s","%.%*"):gsub("%%d","%%d%+")
local questItem = string.gsub(QUEST_ITEMS_NEEDED,"%%s","%(%.%*%)"):gsub("%%d","%%d%+")
function RXP_.UpdateQuestCompletionData(self)
local element = self.element
if not element then return end
local step = element.step
local icon = RXP_.icons.complete
local id = element.questId
if type(id) ~= "number" then
print('Error: Invalid quest ID at step '..element.step.index)
return
end
local skip
local objectives = RXP_.GetQuestObjectives(id,element.step.index)
local isQuestComplete = IsQuestTurnedIn(id) or IsQuestComplete(id)
local objtext
local completed
if objectives and #objectives > 0 then
if element.obj and element.obj <= #objectives then
local obj = objectives[element.obj]
local t = obj.text
if obj.type == "item" then
icon = RXP_.icons.collect
elseif obj.type == "monster" and (t:match(questMonster) or obj.questie) then
icon = RXP_.icons.combat
end
if not obj.questie then
if obj.type == "event" then
if isQuestComplete then
t = string.format(t..": %d/%d",obj.numRequired,obj.numRequired)
else
t = string.format(t..": %d/%d",obj.numFulfilled,obj.numRequired)
end
elseif isQuestComplete then
t = t:gsub(": %d+/(%d+)",": %1/%1")
end
end
completed = obj.finished
objtext = t
else
completed = true
for i,obj in pairs(objectives) do
local t = obj.text
completed = completed and obj.finished
if not obj.questie then
if obj.type == "event" then
if isQuestComplete then
t = string.format(t..": %d/%d",obj.numRequired,obj.numRequired)
else
t = string.format(t..": %d/%d",obj.numFulfilled,obj.numRequired)
end
elseif isQuestComplete then
t = t:gsub(": %d+/(%d+)",": %1/%1")
end
end
if objtext then
objtext = objtext.."\n"..t
else
objtext = t
end
end
end
else
element.text = "Retrieving quest data..."
element.tooltipText = nil
RXP_.UpdateStepText(self)
return
end
if step.active and db and type(db.QueryQuest) == "function" and element.obj and not isQuestComplete and not RXP_.skipPreReq[id] then
local quest = db:GetQuest(id)
if quest and quest.ObjectiveData and quest.ObjectiveData[element.obj] then
local itemId = quest.ObjectiveData[element.obj].Id
local questType = quest.ObjectiveData[element.obj].Type
local validQuest = true
if questType == "item" then
validQuest = select(12,GetItemInfo(itemId)) == 12 and select(11,GetItemInfo(itemId)) == 0
end
if not IsOnQuest(id) and validQuest then
local requiredQuests = {}
local preQuest = quest:IsPreQuestGroupFulfilled() and quest:IsPreQuestSingleFulfilled()
local questList
if not preQuest then
questList = quest.preQuestGroup or quest.preQuestSingle
end
if questList then
for _,qID in ipairs(questList) do
table.insert(requiredQuests,qID)
end
end
table.insert(requiredQuests,id)
local tooltip = RXP_.colors.tooltip.."Missing pre-requisites:|r\n"
for i,qid in ipairs(requiredQuests) do
if i < #requiredQuests then
tooltip = format("%s\n%s%s (%d)",tooltip,RXP_.icons.turnin,db:GetQuest(qid).name,qid)
else
tooltip = format("%s\n%s%s (%d)",tooltip,RXP_.icons.accept,db:GetQuest(qid).name,qid)
end
end
element.tooltip = tooltip
element.icon = RXP_.icons.error
skip = RXPData.skipMissingPreReqs
else
element.icon = icon
element.tooltip = nil
end
end
else
element.icon = icon
element.tooltip = nil
end
local quest
if objectives then
quest = RXP_.GetQuestName(id,element)
end
if quest then
element.title = quest
else
element.title = ""
end
local prefix = objtext:sub(1,1)
if not quest or prefix == " " or prefix == ":" then
element.requestFromServer = true
elseif quest then
element.requestFromServer = nil
end
if element.rawtext then
element.rawtext = element.text:gsub("%*quest%*",element.title)
end
local text = element.rawtext
completed = completed or isQuestComplete
if text then
text = text.."\n\n"..objtext
element.tooltipText = icon..text:gsub("\n","\n ")
else
element.tooltipText = icon..objtext:gsub("\n","\n "..icon)
text = objtext
end
element.text = text
RXP_.UpdateStepText(self)
if completed then
RXP_.SetElementComplete(self,true)
elseif skip then
RXP_.SetElementComplete(self)
else
RXP_.SetElementIncomplete(self)
end
end
function RXP_.QueueUpdate(ref,func,lowPrio)
local update
if lowPrio then
update = RXP_.updateInactiveQuest
else
update = RXP_.updateActiveQuest
end
update[ref] = func
end
function RXP_.functions.complete(self,...)
if type(self) == "string" then --on parse
local element = {}
local text,id,obj = ...
id = tonumber(id)
if not (id and obj) then
RXP_.error("Error parsing guide "..RXP_.currentGuideName..": Invalid objective or quest ID\n"..self)
end
element.obj = tonumber(obj)
element.dynamicText = true
--element.title = RXP_.GetQuestName(id)
--local objectives = RXP_.GetQuestObjectives(id)--queries the server for items/creature names associated with the quest
element.questId = questConversion[id] or id
if text and text ~= "" then
element.rawtext = text
element.text = element.rawtext
element.tooltipText = RXP_.icons.complete..element.text
else
element.text = ""
element.requestFromServer = true
end
return element
end
local event = ...
local step = self.element.step
local id = self.element.questId
if event then
if step.active then
RXP_.updateActiveQuest[self] = RXP_.UpdateQuestCompletionData
else
RXP_.updateInactiveQuest[self] = RXP_.UpdateQuestCompletionData
end
else
if step.active and RXP_.questCompleteItems[id] then
local qItem = RXP_.questCompleteItems[id]
if not step.activeItems then step.activeItems = {} end
if type(qItem) == "table" then
for _,item in pairs(qItem) do
step.activeItems[item] = true
end
else
step.activeItems[qItem] = true
end
end
RXP_.UpdateQuestCompletionData(self)
end
end
local lastZone
function RXP_.functions.goto(self,...)
if type(self) == "string" then --on parse
local element = {}
element.tag = "goto"
local text,zone,x,y,radius,optional = ...
if zone then
lastZone = zone
else
zone = lastZone
end
local mapID = RXP_.mapId[zone] or tonumber(zone)
element.x = tonumber(x)
element.y = tonumber(y)
if not (element.x and element.y and zone and mapID) then