forked from cralor/TourGuideClassic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBroker.lua
167 lines (137 loc) · 6.58 KB
/
Broker.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
local TourGuide = TourGuide
local dataobj = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject("TourGuide", {type = "data source", text = "Bah!", icon = TourGuide.icons.KILL})
local lastmapped, lastmappedaction
function TourGuide:UpdateStatusFrame()
self:Debug(1, "UpdateStatusFrame", self.current)
if self.updatedelay then
local _, logi = self:GetObjectiveStatus(self.updatedelay)
self:Debug(1, "Delayed update", self.updatedelay, logi)
if logi then return end
end
local nextstep
self.updatedelay = nil
for i in ipairs(self.actions) do
local turnedin, logi, complete = self:GetObjectiveStatus(i)
if not turnedin and not nextstep then
local action, name, quest = self:GetObjectiveInfo(i)
local note, useitem, optional, prereq, lootitem, lootqty = self:GetObjectiveTag("N", i), self:GetObjectiveTag("U", i), self:GetObjectiveTag("O", i), self:GetObjectiveTag("PRE", i), self:GetObjectiveTag("L", i)
self:Debug(11, "UpdateStatusFrame", i, action, name, note, logi, complete, turnedin, quest, useitem, optional, lootitem, lootqty, lootitem and GetItemCount(lootitem) or 0)
local hasuseitem = useitem and self:FindBagSlot(useitem)
local haslootitem = lootitem and GetItemCount(lootitem) >= lootqty
local prereqturnedin = prereq and self.turnedin[prereq]
-- Test for completed objectives and mark them done
if action == "SETHEARTH" and self.db.char.hearth == name then return self:SetTurnedIn(i, true) end
local zonetext, subzonetext, subzonetag = GetZoneText(), string.trim(GetSubZoneText()), self:GetObjectiveTag("SZ")
if (action == "RUN" or action == "FLY" or action == "HEARTH" or action == "BOAT") and (subzonetext == name or subzonetext == subzonetag or zonetext == name or zonetext == subzonetag) then return self:SetTurnedIn(i, true) end
if action == "KILL" or action == "NOTE" then
if not optional and haslootitem then return self:SetTurnedIn(i, true) end
local quest, questtext = self:GetObjectiveTag("Q", i), self:GetObjectiveTag("QO", i)
if quest and questtext then
local qi = self:GetQuestLogIndexByName(quest)
for lbi=1,GetNumQuestLeaderBoards(qi) do
self:Debug(1, quest, questtext, qi, GetQuestLogLeaderBoard(lbi, qi))
if GetQuestLogLeaderBoard(lbi, qi) == questtext then return self:SetTurnedIn(i, true) end
end
end
end
local incomplete
if action == "ACCEPT" then incomplete = (not optional or hasuseitem or haslootitem or prereqturnedin) and not logi
elseif action == "TURNIN" then incomplete = not optional or logi
elseif action == "COMPLETE" then incomplete = not complete and (not optional or logi)
elseif action == "NOTE" or action == "KILL" then incomplete = not optional or haslootitem
else incomplete = not logi end
if incomplete then nextstep = i end
local thisaction = action
if nextstep and self.db.char.trackquests then
for j=1,GetNumQuestWatches() do
local logj = GetQuestIndexForWatch(j)
RemoveQuestWatch(logj)
end
if (action == "COMPLETE" or action == "TURNIN") and logi then
local j = i
repeat
action = self:GetObjectiveInfo(j)
turnedin, logi, complete = self:GetObjectiveStatus(j)
if action == thisaction and logi then AddQuestWatch(logi) end -- Watch quests when we can
j = j + 1
until action ~= thisaction
end
end
end
end
QuestLog_Update()
QuestWatch_Update()
if not nextstep and self:LoadNextGuide() then return self:UpdateStatusFrame() end
if not nextstep then return end
self.current = nextstep
local action, quest, fullquest = self:GetObjectiveInfo(nextstep)
local turnedin, logi, complete = self:GetObjectiveStatus(nextstep)
local note, useitem, optional = self:GetObjectiveTag("N", nextstep), self:GetObjectiveTag("U", nextstep), self:GetObjectiveTag("O", nextstep)
dataobj.text, dataobj.icon = (quest or"???")..(note and " [?]" or ""), self.icons[action]
TourGuide:CommCurrentObjective()
self:DebugF(1, "Progressing to objective \"%s %s\"", action, quest)
-- Mapping
if (TomTom or Cartographer_Waypoints) and (lastmapped ~= quest or lastmappedaction ~= action) then
lastmappedaction, lastmapped = action, quest
self:ParseAndMapCoords(action, quest, self:GetObjectiveTag("Z", nextstep) or self.zonename, note, self:GetObjectiveTag("QID", nextstep), logi)
end
if self.db.char.showuseitem and action == "COMPLETE" and self.db.char.showuseitemcomplete then
local useitem2 = nil --GetQuestLogSpecialItemInfo(logi or 0)
if useitem2 then useitem2 = tonumber(useitem2:match("item:(%d+):")) end
self:SetUseItem(useitem2 or useitem)
elseif self.db.char.showuseitem and action ~= "COMPLETE" then
self:SetUseItem(useitem)
else
self:SetUseItem()
end
self:UpdateOHPanel()
self:UpdateGuidesPanel()
end
function TourGuide:CommCurrentObjective()
local action, quest, fullquest = self:GetObjectiveInfo()
local qid = self:GetObjectiveTag("QID")
C_ChatInfo.SendAddonMessage("TGuide", action.." "..(quest or "???"), "PARTY")
if qid then C_ChatInfo.SendAddonMessage("TGuideQID", qid, "PARTY") end
end
local function GetQuadrant(frame)
local x,y = frame:GetCenter()
if not x or not y then return "BOTTOMLEFT", "BOTTOM", "LEFT" end
local hhalf = (x > UIParent:GetWidth()/2) and "RIGHT" or "LEFT"
local vhalf = (y > UIParent:GetHeight()/2) and "TOP" or "BOTTOM"
return vhalf..hhalf, vhalf, hhalf
end
function dataobj.OnClick(self, btn)
if TourGuide.db.char.currentguide == "No Guide" then InterfaceOptionsFrame_OpenToCategory(TourGuide.configpanel)
InterfaceOptionsFrame_OpenToCategory(TourGuide.configpanel)
else
if btn == "RightButton" then
if TourGuide.objectiveframe:IsVisible() then
HideUIPanel(TourGuide.objectiveframe)
else
local quad, vhalf, hhalf = GetQuadrant(self)
local anchpoint = (vhalf == "TOP" and "BOTTOM" or "TOP")..hhalf
TourGuide.objectiveframe:ClearAllPoints()
TourGuide.objectiveframe:SetPoint(quad, self, anchpoint)
ShowUIPanel(TourGuide.objectiveframe)
end
else
if IsShiftKeyDown() then TourGuide:SetTurnedIn()
else
local i = GetQuestLogIndexByID(TourGuide:GetObjectiveTag("QID", TourGuide.current))
if i then SelectQuestLogEntry(i) end
ShowUIPanel(QuestLogFrame)
end
end
end
end
function dataobj.OnLeave() GameTooltip:Hide() end
function dataobj.OnEnter(self)
local tip = TourGuide:GetObjectiveTag("N")
if not tip then return end
GameTooltip:SetOwner(self, "ANCHOR_NONE")
local quad, vhalf, hhalf = GetQuadrant(self)
local anchpoint = (vhalf == "TOP" and "BOTTOM" or "TOP")..hhalf
TourGuide:Debug(11, "Setting tooltip anchor", anchpoint, quad, hhalf, vhalf)
GameTooltip:SetPoint(quad, self, anchpoint)
GameTooltip:SetText(tip, nil, nil, nil, nil, true)
end