-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGoal.lua
More file actions
751 lines (682 loc) · 25.8 KB
/
Copy pathGoal.lua
File metadata and controls
751 lines (682 loc) · 25.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
local Goal = { }
local ZGV = ZygorGuidesViewer
if not ZGV then return end
local L = ZGV.L
local table,string,tonumber,ipairs,pairs,setmetatable = table,string,tonumber,ipairs,pairs,setmetatable
ZGV.GoalProto = Goal
ZGV.GoalProto_mt = { __index=Goal }
Goal.indent=0
function Goal:GetStatus()
if not self:IsVisible() then return "hidden" end
if not self:IsCompleteable() then return "passive" end
local complete,possible,progress = self:IsComplete()
if complete then return "complete" end
if (ZGV.db.profile.showobsolete or ZGV.db.profile.skipobsolete) and not self.parentStep.parentGuide.noobsolete and self:IsObsolete() then return "obsolete" end
if not possible then return "impossible" end
-- only possible and progressing is left.
return "incomplete",progress
end
function Goal:UpdateStatus()
self.status = self:GetStatus()
end
function Goal:IsVisible()
if not self:IsFitting() then return false end
if self.condition_visible then return self.condition_visible() end
return true
end
function Goal:IsCompleteable()
--if type(goal)=="number" then goal=self.CurrentStep.goals[goal] end
if self.force_nocomplete then return false end
if self.questid --[[and self.objnum--]] then return true end
if self.action=="from"
or self.action==""
then return false end
if self.action=="goal"
or self.action=="kill"
or self.action=="get"
or self.action=="accept"
or self.action=="turnin"
or self.action=="collect"
or self.action=="buy"
or self.action=="fpath"
or self.action=="home"
or self.action=="ding"
or self.action=="havebuff"
or self.action=="nobuff"
or self.action=="invehicle"
or self.action=="outvehicle"
or self.action=="equipped"
or self.action=="rep"
or self.action=="condition"
or self.action=="achieve"
or self.action=="skill"
or self.action=="skillmax"
or self.action=="learn"
or self.action=="fishing"
then return true end
if self.action=="goto" then
-- this one is tricky.
-- by default - completeable only if only 'goto' goals are present.
local all_gotos=true
for i,goal in ipairs(self.parentStep.goals) do
if goal.action~="goto" then
all_gotos=false
break
end
end
return (self.force_complete or all_gotos)
end
return false
end
local goalstring_slain=QUEST_MONSTERS_KILLED:gsub(": .*","")
-- returns: true = complete, false = incomplete
-- second return: true = completable, false = incompletable
function Goal:IsComplete()
if (self.force_sticky and ZGV.recentlyCompletedGoals[self]) or ZGV.recentlyStickiedGoals[self] then
return true,true,true
end
if self.force_nocomplete then return end
if self.action=="accept" then
local possible=true
if self.questid and not ZGV:IsQuestPossible(self.questid) then possible=false end
local complete = ZGV.completedQuests[self.questid]
or ZGV.questsbyid[self.questid]
or (ZGV.instantQuests[self.questid] and ZGV.completedQuestTitles[self.quest])
or (not ZGV.CurrentGuide.daily and ZGV.db.char.permaCompletedDailies[self.questid])
return complete, complete or possible
elseif self.action=="turnin" then
local inlog = ZGV.questsbyid[self.questid]
local turned = (
ZGV.completedQuests[self.questid]
or (not ZGV.CurrentGuide.daily and ZGV.db.char.permaCompletedDailies[self.questid])
) and not inlog
return turned, turned or (inlog and (inlog.complete or #inlog.goals==0))
end
if self.achieveid then
local completed
if self.achievesub then
local description, ctype
description, ctype, completed = GetAchievementCriteriaInfo(self.achieveid, self.achievesub)
else
local id, name, points
id, name, points, completed = GetAchievementInfo(self.achieveid)
end
if completed then
return true,true
end
-- else fall-through
end
-- Quest-related? Handle appropriately.
if self.questid then
-- if the quest was done, the goal is done and over with.
if ZGV.completedQuests[self.questid]
or (ZGV.instantQuests[self.questid] and self.quest and ZGV.completedQuestTitles[self.quest]) then return true,true end
local questInLog = ZGV.questsbyid[self.questid]
if questInLog then
-- Now if it is goalbound, complete it as the goal would.
if self.objnum then
local questGoalData = questInLog.goals[self.objnum]
if questGoalData then
if questGoalData.complete then
return true, true
else
local count = self.count or questGoalData.needed or 1
if questGoalData.num>=count then
return true, true
else
return false, true, questGoalData.num/count
end
end
else
ZGV:Print("WARNING: quest has no such goal! Step "..self.parentStep.num..", line "..(self.num)..", quest "..(self.questid or self.quest)..", goal "..(self.objnum or -1))
return false, true
end
else
if not self.action or self.action=="" then
-- okay, this is a simple "complete the quest" check
return questInLog.complete,true
end
end
else
-- if quest is not in log, then it usually means screw its links as well.
-- Unless we're a future-proof goal, which drops through.
if not self.future then
return false,false
end
end
end
if self.action=="ding" then
local percent
local level = UnitLevel("player")
if ZGV.db.char.fakelevel and ZGV.db.char.fakelevel>0 then level=ZGV.db.char.fakelevel end
percent = (level<self.level-1) and 0 or (level>=self.level) and 1.0 or UnitXP("player")/UnitXPMax("player")
return UnitLevel("player")>=tonumber(self.level), UnitLevel("player")>=tonumber(self.level)-1, percent
elseif self.action=="goto" then
local zone = GetRealZoneText()
if self.map and zone~=self.map then return false,true end
if ZGV.recentlyVisitedCoords[self] then
return true, true
end
if self.x then
local px,py = GetPlayerMapPosition("player")
local gx,gy,dist = self.x/100,self.y/100,self.dist/100
local realdist2 = (px-gx)*(px-gx) + (py-gy)*(py-gy)
if realdist2<=dist*dist then
ZGV.recentlyVisitedCoords[self] = true
return true, true
else
local prog = 1-((realdist2-dist*dist)*500)
if prog<0 then prog=0 end
if prog>1 then prog=1 end
return false, true, prog
end
else
return true,true
end
elseif self.action=="hearth" then
return GetZoneText()==self.param or GetMinimapZoneText()==self.param or GetSubZoneText()==self.param, true
elseif self.action=="home" then
return ZGV.recentlyHomeChanged, true
elseif self.action=="fpath" then
return (ZGV.db.char.taxis[ZGV.LibTaxi.TaxiNames_English[self.param]]), true
elseif self.action=="collect" or self.action=="buy" then
local got = GetItemCount(self.target)
local progress = got/self.count
if self.exact then
return got==self.count, true, got<=self.count and progress or 0
else
return got>=self.count, true, progress>1 and 1 or progress
end
elseif self.action=="havebuff" then
for i=1,30 do
local name,_,tex = UnitBuff("player",i)
if name and (tex:find(self.buff) or name:find(self.buff)) then return true,true end
local name,_,tex = UnitDebuff("player",i)
if name and (tex:find(self.buff) or name:find(self.buff)) then return true,true end
end
return false,true
elseif self.action=="nobuff" then
for i=1,30 do
local name,_,tex = UnitBuff("player",i)
if name and (tex:find(self.buff) or name:find(self.buff)) then return false,true end
local name,_,tex = UnitDebuff("player",i)
if name and (tex:find(self.buff) or name:find(self.buff)) then return false,true end
end
return true,true
elseif self.action=="invehicle" then
return UnitInVehicle("player"),true
elseif self.action=="outvehicle" then
return not UnitInVehicle("player"),true
elseif self.action=="equipped" then
local link = GetInventoryItemLink("player",self.slot)
local name
if link then name = link:match("|Hitem:.-%[(.-)%]") end
return name and name==self.item , GetItemCount(self.item)>0
elseif self.action=="rep" then
local rep = ZGV:GetReputation(self.faction)
if rep then
return rep.standing>=self.rep, true, 1-(rep:CalcTo(self.rep)/(rep.max-rep.min)) or 0
else
return nil,nil,nil
end
elseif self.action=="condition" then
return self:condition_complete()
elseif self.action=="achieve" then
if self.achieveid then
if self.achievesub then
-- partial achievement
local desc,ctype,completed,quantity,required = GetAchievementCriteriaInfo(self.achieveid,self.achievesub)
if not required or required==0 then required=1 end
if not quantity then quantity = 0 end
if quantity>required then quantity=required end
return not not completed, true, quantity/required
else
-- full achievement
local id, name, points, completed = GetAchievementInfo(self.achieveid)
local numcrit = GetAchievementNumCriteria(self.achieveid)
local completenum = 0
for i=1,numcrit do
local desc,ctype,completed,quantity,required = GetAchievementCriteriaInfo(self.achieveid,i)
if not required or required==0 then required=1 end
if not quantity then quantity = 0 end
if quantity>required then quantity=required end
completenum=completenum+quantity/required
end
return not not completed, true, numcrit>0 and completenum/numcrit or 0
end
else
return nil,nil,nil
end
elseif self.action=="skill" then
local skill = ZGV:GetSkill(self.skill)
return skill.level>=self.skilllevel,skill.max>=self.skilllevel
elseif self.action=="skillmax" then
return ZGV:GetSkill(self.skill).max>=self.skilllevel,true
elseif self.action=="learn" then
-- Recipe checking - ID ONLY version
-- Check if recipe ID exists in known recipes database
if self.recipeid and ZGV.db.char.RecipesKnown then
return ZGV.db.char.RecipesKnown[self.recipeid], true
end
-- If no recipeid or not found, return false
return false, true
elseif self.action=="fishing" then
-- Check fishing skill level
local currentFishing = ZGV:GetSkillLevel("Fishing") or 0
local targetLevel = self.skillLevel or 0
local progress = currentFishing / targetLevel
if progress > 1 then progress = 1 end
ZGV:Debug("Fishing goal check: current=" .. currentFishing .. ", target=" .. targetLevel .. ", progress=" .. progress)
return currentFishing >= targetLevel, true, progress
elseif self.action=="kill" and self.usekillcount then --killcount version
local count = ZGV.recentKills[self.target]
return count and count>=self.count, true
end
return false,false
end
function FindPetActionInfo(action)
if type(action)==number then return action,GetPetActionInfo(action) end
for i=1,12 do
local name,x,tex = GetPetActionInfo(i)
if name and (name:find(action) or tex:find(action)) then return i,name,x,tex end
end
end
function Goal:IsActionable()
return ((self.useitemid or self.useitem) and GetItemCount(self.useitemid or self.useitem)>0)
or (self.castspell and IsUsableSpell(self.castspell))
or (self.petaction and FindPetActionInfo(self.petaction))
or (self.script)
end
local function plural(s,i)
if not i or i==1 then return s else return ZygorGuidesViewer_L("Specials")["plural"](s) end
end
function Goal:IsFitting()
if self.wrong then return nil end
if not self.requirement then return true end
self.wrong = not ZygorGuidesViewer:RaceClassMatch(self.requirement)
return not self.wrong
end
function Goal:NeedsTranslation()
return not self.L
end
local retry=10
function Goal:AutoTranslate()
local oldL=self.L
local waiting=false
if type(self.L)=="number" and self.L>0 then self.L=self.L-1 return end
if self.L==true then return false end
if not self:IsFitting() then
-- ignore wrong goals
self.L=true
end
--ZGV:Debug(("Translating step %d goal %d, try %d..."):format(self.parentStep.num,self.num,self.countL or 0))
if self.action=="fpath" and ZGV.LibTaxi then
if ZGV.LibTaxi.TaxiNames_Local then
self.param = ZGV.LibTaxi.TaxiNames_Local[self.param] or self.param
end
self.L = true
end
if self.questid then
local qt,qobjs = ZGV:GetQuestData(self.questid)
if qt and qt~="" then
self.quest=qt
if (self.action=='get' or self.action=='kill' or self.action=='goal')
and not self.targetid then
if qobjs then
local obj=qobjs[self.objnum or 1]
if obj and #obj>2 then
self.target=obj
self.L=true
else
self.L=retry --RETRY
end
else
self.L=true --sorry...
end
elseif self.action=='accept' or self.action=='turnin' then
ZGV:Debug("Translated: accept/turnin "..self.quest)
self.L = true -- quest title is enough
else
ZGV:Debug("Translated: '"..tostring(self.action).."' "..tostring(self.quest))
self.L = true
end
-- translated a quest - if it's an instant-daily, put it in a special bag
if ZGV.instantQuests[self.questid] and ZGV.dailyQuests[self.questid] then
ZGV.db.global.instantDailies[self.questid] = qt
end
else
self.L = retry --RETRY
end
end
if self.targetid then
if self.action=="kill" then
if ZygorGuidesNPCs then
local target,tooltip=ZGV:GetTranslatedNPC(self.targetid)
if target then
self.target,self.tooltip=target,tooltip
end
end
self.L=true
elseif self.action=="collect" or self.action=="get" or self.action=="buy" or self.action=="use" then
local item = ZGV:GetItemData(self.targetid)
if item then
self.target=item
self.L=true
else
self.L=retry --RETRY
end
end
end
if self.useitemid then
local item = ZGV:GetItemData(self.useitemid)
if item then
self.useitem = item
self.L = true
else
self.L = retry
end
end
if self.npcid then
if ZygorGuidesNPCs then
local npc,tooltip=ZGV:GetTranslatedNPC(self.npcid)
if npc then
self.npc,self.tooltip=npc,tooltip
end
end
self.L=true
end
if self.L==nil then
-- not waiting for a translation? oh well.
self.L=true
end
if self.L==true and self.countL and self.countL>0 then
ZGV:Debug(("Translated step %d goal %d at try %d"):format(self.parentStep.num,self.num,self.countL))
end
-- if many translation attempts fail, just leave it.
if not self.L then
self.countL=(self.countL or 0)+1
if self.countL>=100 then
ZGV:Debug(("Failed to translate step %d goal %d, tried %d times"):format(self.parentStep.num,self.num,self.countL))
self.countL=nil
self.L=true
end
end
if self.L then
ZGV.frameNeedsUpdating=true
self.countL=nil
end
return oldL~=self.L
end
local function COLOR_LOC(s) return "|cffffee77"..s.."|r" end
local function COLOR_COUNT(s) return "|cffffffcc"..s.."|r" end
local function COLOR_ITEM(s) return "|cffaaeeff"..s.."|r" end
local function COLOR_QUEST(s) return "|cffbb99ff"..s.."|r" end
local function COLOR_NPC(s) return "|cffaaffaa"..s.."|r" end
local function COLOR_MONSTER(s) return "|cffffaaaa"..s.."|r" end
local function COLOR_GOAL(s) return "|cffffcccc"..s.."|r" end
local function COLOR_SKILL(s) return "|cff77ff77"..s.."|r" end
function Goal:GetText(showcompleteness)
local text="?"
if self.text then text = self.text
elseif self.action=='accept' then text = L["stepgoal_accept"]:format(COLOR_QUEST((self.questpart and L['questtitle_part'] or L['questtitle']):format(self.quest,self.questpart)))
elseif self.action=='turnin' then text = L["stepgoal_turn in"]:format(COLOR_QUEST((self.questpart and L['questtitle_part'] or L['questtitle']):format(self.quest,self.questpart)))
elseif self.action=='talk' then text = L["stepgoal_talk to"]:format(COLOR_NPC(self.npc))
elseif self.action=='get' and self.count and self.count>1 then text = L["stepgoal_get #"]:format(self.count>0 and self.count or "?",COLOR_ITEM(plural(self.target,self.count)))
elseif self.action=='get' then text = L["stepgoal_get"]:format(COLOR_ITEM(plural(self.target,self.plural and 2 or 1)))
elseif self.action=='kill' and self.count and self.count>1 then text = L["stepgoal_kill #"]:format(self.count>0 and self.count or "?",COLOR_MONSTER(plural(self.target,self.count)))
elseif self.action=='kill' then text = L["stepgoal_kill"]:format(COLOR_MONSTER(plural(self.target,self.plural and 2 or 1)))
elseif self.action=='collect' and self.count and self.count>1 then text = L["stepgoal_collect #"]:format(self.count,COLOR_ITEM(plural(self.target,self.count)))
elseif self.action=='collect' then text = L["stepgoal_collect"]:format(COLOR_ITEM(plural(self.target,self.plural and 2 or 1)))
elseif self.action=='buy' then text = L["stepgoal_buy"]:format(self.count,COLOR_ITEM(plural(self.target,self.count)))
elseif self.action=='goal' and self.count and self.count>1 then text = L["stepgoal_goal #"]:format(self.count>0 and self.count or "?",COLOR_GOAL(plural(self.target,self.count)))
elseif self.action=='goal' then text = L["stepgoal_goal"]:format(COLOR_GOAL(self.target))
elseif self.action=='from' then
text=nil
for i,mob in ipairs(self.mobs) do
local mobname
if mob.id then mobname=ZGV:GetTranslatedNPC(mob.id) end
if not self.knownmissing then
ZGV:Debug("Missing from NPC database: "..mob.name.." #"..(mob.id or "?"))
end
self.knownmissing=true
if mobname then mob.name=mobname end
end
if #self.mobs>1 then
-- contraction
ZGV.db.profile.contractmobs = true
if ZGV.db.profile.contractmobs and ZygorGuidesViewer_L("Specials")['contract_mobs'] then
local contr = ZygorGuidesViewer_L("Specials")['contract_mobs'](self.mobs)
if contr then
text = COLOR_MONSTER(contr)
end
end
if not text then
-- regular listing
text = ""
for i,mob in ipairs(self.mobs) do
if #text>0 then text = text .. ", " end
text = text .. COLOR_MONSTER(plural(mob.name,nil,mob.pl and 2 or 1))
end
end
else
text = COLOR_MONSTER(plural(self.mobs[1].name,self.mobs[1].pl and 2 or 1))
end
text=L['stepgoal_kill']:format(text)
elseif self.action=='ding' then text = L["stepgoal_ding"]:format(COLOR_NPC(self.level))
elseif self.action=='fpath' then text = L["stepgoal_fpath"]:format(COLOR_LOC(self.param))
elseif self.action=='home' then text = L["stepgoal_home"]:format(COLOR_LOC(self.param))
elseif self.action=='use' then text = L["stepgoal_use"]:format(COLOR_ITEM(self.useitem or "#"..self.useitemid))
elseif self.action=='cast' then text = L["stepgoal_cast"]:format(COLOR_ITEM(self.castspell or "#"..self.castspellid))
elseif self.action=='petaction' then text = L["stepgoal_petaction"]:format(self.petaction)
elseif self.action=='havebuff' then text = L["stepgoal_havebuff"]:format(COLOR_ITEM(self.buff))
elseif self.action=='nobuff' then text = L["stepgoal_nobuff"]:format(COLOR_ITEM(self.buff))
elseif self.action=='invehicle' then text = L["stepgoal_invehicle"]
elseif self.action=='outvehicle' then text = L["stepgoal_outvehicle"]
elseif self.action=='equipped' then text = L["stepgoal_equipped"]:format(self.item,self.slot)
elseif self.action=='hearth' then text = L["stepgoal_hearth to"]:format(COLOR_LOC(self.param))
elseif self.action=='rep' then text = L["stepgoal_rep"]:format(ZGV.StandingNames[self.rep],self.faction)
elseif self.action=='goto' then
if self.map and GetRealZoneText() ~= self.map then
-- different map
if self.x then
-- and coords
text = L["stepgoal_go to"]:format( COLOR_LOC(L['map_coords']:format(self.map,self.x,self.y)) )
else
-- just the map
text = L["stepgoal_go to"]:format( COLOR_LOC(("%s"):format(self.map)) )
end
else
-- same map
text = L["stepgoal_go to"]:format( COLOR_LOC(L['coords']:format(self.x or 0,self.y or 0)) )
end
elseif self.action=="achieve" then
local id, name, points, completed = GetAchievementInfo(self.achieveid)
if self.achievesub then
local desc,ctype,completed,quantity,required = GetAchievementCriteriaInfo(self.achieveid,self.achievesub)
text = L["stepgoal_achievesub"]:format(COLOR_QUEST(desc),COLOR_ITEM(name))
else
text = L["stepgoal_achieve"]:format(COLOR_ITEM(name))
end
elseif self.action=="skill" then
text = L["stepgoal_skill"]:format(COLOR_SKILL(self.skill),self.skilllevel)
elseif self.action=="skillmax" then
text = L["stepgoal_skillmax"]:format(COLOR_SKILL(self.skill),self.skilllevel)
elseif self.action=="learn" then
text = L["stepgoal_learn"]:format(COLOR_ITEM(self.displaytext or "Recipe"))
elseif self.action=="fishing" then
-- Fishing goal text with fallback for missing localization
local fishingText = L["stepgoal_fishing"]
if not fishingText then
fishingText = "Fish until your skill reaches %s"
end
text = fishingText:format(COLOR_SKILL(self.skillLevel or 0))
end
-- trickiness.
if self.x -- if there's a coordinate
and not (self.action=="goto" and not self.text) -- but it's not a plain goto
and not (self.text and self.text:find("[0-9%.]-,[0-9%.]-")) -- and it's not a coord-in-text
and not self.force_noway then
text = text .. L['stepgoal_at_suff']:format(COLOR_LOC(L['coords']:format(self.x,self.y)))
end
if self.force_nocomplete and self.action~="collect" and self.action~="buy" then showcompleteness=false end
if showcompleteness then
local desc = ""
-- quest-goal completion display; lame 0/5
if self.questid then
local questdata = ZGV.questsbyid[self.questid]
if questdata then
-- quest in log? yay.
if self.objnum then
-- goal-bound
local questgoal = questdata.goals[self.objnum]
if questgoal then
local count = self.count or questgoal.needed
desc = L["completion_goal"]:format(questgoal.num,count)
end
end
end
end
if self.action=="ding" then
local percent
local level = UnitLevel("player")
percent = (level<self.level-1) and 0 or (level>=self.level) and 100 or floor(UnitXP("player")/UnitXPMax("player") * 100)
desc = L["completion_ding"]:format(percent)
elseif self.action=="collect" or self.action=="buy" then
desc = L["completion_collect"]:format(GetItemCount(self.target),self.count)
elseif self.action=="rep" then
desc = L["completion_rep"]:format(ZGV:GetReputation(self.faction):Going())
elseif self.action=="achieve" then
if self.achievesub then
local desc,ctype,completed,quantity,required = GetAchievementCriteriaInfo(self.achieveid,self.achievesub)
desc = L["completion_goal"]:format(quantity,required)
else
local id, name, points, completed = GetAchievementInfo(self.achieveid)
local numcrit = GetAchievementNumCriteria(self.achieveid)
local completenum = 0
for i=1,numcrit do
local desc,ctype,completed,quantity,required = GetAchievementCriteriaInfo(self.achieveid,i)
if completed then completenum=completenum+1 end
end
desc = L["completion_goal"]:format(completenum,numcrit)
end
elseif self.action=="fishing" then
-- Show fishing skill progress
local currentFishing = ZGV:GetSkillLevel("Fishing") or 0
local targetLevel = self.skillLevel or 0
local progressText = L["completion_fishing"]
if not progressText then
progressText = "(%d/%d)"
end
desc = progressText:format(currentFishing, targetLevel)
elseif self.action=="skill" then
local skill = ZGV:GetSkill(self.skill)
desc = L["completion_skill"]:format(skill.level,self.skilllevel)
elseif self.action=="skillmax" then
local skill = ZGV:GetSkill(self.skill)
desc = L["completion_skillmax"]:format(skill.max,self.skilllevel)
elseif self.action=="kill" and self.usekillcount then --kill, killcount version
local count = ZGV.recentKills[self.target]
desc = L["completion_goal"]:format(count,self.count)
end
local complete,ext = self:IsComplete()
if complete and ZGV.db.profile.goalcolorize then
text = "|cffbbffbb" .. text:gsub("|c........",""):gsub("|r","") .. "|r"
end
if desc and desc~="" then
if complete then
text = text .. " " .. desc
elseif ext then
text = text .. " |cffffbbbb" .. desc .. "|r"
else
text = text .. " |cffaaaaaa" .. desc .. "|r"
end
end
end
return text
end
function Goal:GetString()
if self.action=="get" then
return self.target
elseif self.action=="goal" then
return self.target
elseif self.action=="kill" then
return self.target
end
end
function Goal:Prepare()
if self.castspell or self.castspellid and (not self.castspell or not self.castspellid) then
local link = GetSpellLink(self.castspellid or self.castspell)
if link then
self.castspellid,self.castspell = link:match("spell:([0-9]+).-%[(.-)%]")
self.castspellid = tonumber(self.castspellid)
end
end
if self.action=="goal" or self.action=="kill" or self.action=="get" then
if self.questid then
local questData = ZGV.questsbyid[self.questid]
if questData and questData.index>0 then
local questGoal = self:GetString()
local questGoalData = questData.goalsNamed[questGoal]
if questGoalData and questGoalData.needed and not self.exact and (not self.count or self.count==0 or self.count>questGoalData.needed) then
self.count=questGoalData.needed
end
end
if not self.count then self.count=1 end
end
end
if not InCombatLockdown() then
if self.script then
local macroname = "ZygorGuidesMacro" .. self.num
local macro = GetMacroIndexByName(macroname)
if macro==0 then
macro = CreateMacro(macroname,1,"/run "..self.script,1)
end
self.macro = macro
end
end
if self.autoscript then
local func=loadstring(self.autoscript)
func()
end
end
--- Is this goal obsolete?
function Goal:IsObsolete()
if not self.questid then return end
if self.noobsolete then return end
if self.parentStep.parentGuide.daily or not self.parentStep.level or self.parentStep.level==0 then return nil end
local maxlevel = ZGV.maxQuestLevels[self.questid] or 99
local level = UnitLevel("player")
if ZGV.db.char.fakelevel and ZGV.db.char.fakelevel>0 then level=ZGV.db.char.fakelevel end
if maxlevel<level-ZGV.db.profile.levelsahead and not ZGV.questsbyid[self.questid] then
return true
end
end
function Goal:IsAuxiliary()
if (self.questid
or self.action=="accept"
or self.action=="turnin"
or self.action=="kill"
or self.action=="get"
or self.action=="goal"
or self.action=="ding"
or self.action=="fishing") and not self.force_nocomplete
then
return false
elseif self.action=="fpath" then
local isc = self:IsComplete()
if isc~=nil then return isc end
local step=self.parentStep
for i=1,5 do
step=step:GetNextStep()
if not step then return false end
while (step.requirement) do
step=step:GetNextStep()
if not step then return false end
end
if step:IsComplete() then return true end
end
return false
else
return true
end
end