Merge branch 'master' of zorba@192.168.100.11:questhelper
[QuestHelper.git] / main.lua
blobab0825e91796c2a49595a0238107f77e1e9de1bc
1 QuestHelper_File["main.lua"] = "Development Version"
3 QuestHelper = CreateFrame("Frame", "QuestHelper", nil)
5 -- Just to make sure it's always 'seen' (there's nothing that can be seen, but still...), and therefore always updating.
6 QuestHelper:SetFrameStrata("TOOLTIP")
8 QuestHelper_SaveVersion = 10
9 QuestHelper_CharVersion = 1
10 QuestHelper_Locale = GetLocale() -- This variable is used only for the collected data, and has nothing to do with displayed text.
11 QuestHelper_Quests = {}
12 QuestHelper_Objectives = {}
14 QuestHelper_Pref =
17 QuestHelper_DefaultPref =
19 filter_level=true,
20 filter_zone=false,
21 filter_done=false,
22 filter_blocked=false, -- Hides blocked objectives, such as quest turn-ins for incomplete quests
23 filter_watched=false, -- Limits to Watched objectives
24 track=true,
25 track_minimized=false,
26 track_scale=1,
27 track_level=true,
28 track_qcolour=true,
29 track_ocolour=true,
30 track_size=8,
31 tooltip=true,
32 share = true,
33 scale = 1,
34 solo = false,
35 comm = false,
36 show_ants = true,
37 level = 2,
38 hide = false,
39 cart_wp = true,
40 tomtom_wp = true,
41 flight_time = true,
42 locale = GetLocale(), -- This variable is used for display purposes, and has nothing to do with the collected data.
43 perf_scale = 1, -- How much background processing can the current machine handle? Higher means more load, lower means better performance.
44 map_button = true
47 QuestHelper_FlightInstructors = {}
48 QuestHelper_FlightLinks = {}
49 QuestHelper_FlightRoutes = {}
50 QuestHelper_KnownFlightRoutes = {}
51 QuestHelper_SeenRealms = {}
53 QuestHelper.tooltip = CreateFrame("GameTooltip", "QuestHelperTooltip", nil, "GameTooltipTemplate")
54 QuestHelper.objective_objects = {}
55 QuestHelper.user_objectives = {}
56 QuestHelper.quest_objects = {}
57 QuestHelper.player_level = 1
58 QuestHelper.locale = QuestHelper_Locale
60 QuestHelper.faction = (UnitFactionGroup("player") == "Alliance" and 1) or
61 (UnitFactionGroup("player") == "Horde" and 2)
63 assert(QuestHelper.faction)
65 QuestHelper.font = {serif=GameFontNormal:GetFont(), sans=ChatFontNormal:GetFont(), fancy=QuestTitleFont:GetFont()}
67 function QuestHelper:GetFontPath(list_string, font)
68 if list_string then
69 for name in string.gmatch(list_string, "[^;]+") do
70 if font:SetFont(name, 10) then
71 return name
72 elseif font:SetFont("Interface\\AddOns\\QuestHelper\\Fonts\\"..name, 10) then
73 return "Interface\\AddOns\\QuestHelper\\Fonts\\"..name
74 end
75 end
76 end
77 end
79 function QuestHelper:SetLocaleFonts()
80 self.font.sans = nil
81 self.font.serif = nil
82 self.font.fancy = nil
84 local font = self:CreateText(self)
86 if QuestHelper_Locale ~= QuestHelper_Pref.locale then
87 -- Only use alternate fonts if using a language the client wasn't intended for.
88 local replacements = QuestHelper_SubstituteFonts[QuestHelper_Pref.locale]
89 if replacements then
90 self.font.sans = self:GetFontPath(replacements.sans, font)
91 self.font.serif = self:GetFontPath(replacements.serif, font)
92 self.font.fancy = self:GetFontPath(replacements.fancy, font)
93 end
94 end
96 self.font.sans = self.font.sans or self:GetFontPath(QuestHelper_Pref.locale.."_sans.ttf", font)
97 self.font.serif = self.font.serif or self:GetFontPath(QuestHelper_Pref.locale.."_serif.ttf", font) or self.font.sans
98 self.font.fancy = self.font.fancy or self:GetFontPath(QuestHelper_Pref.locale.."_fancy.ttf", font) or self.font.serif
100 self:ReleaseText(font)
102 self.font.sans = self.font.sans or ChatFontNormal:GetFont()
103 self.font.serif = self.font.serif or GameFontNormal:GetFont()
104 self.font.fancy = self.font.fancy or QuestTitleFont:GetFont()
106 -- Need to change the font of the chat frame, for any messages that QuestHelper displays.
107 -- This should do nothing if not using an alternate font.
108 DEFAULT_CHAT_FRAME:SetFont(self.font.sans, select(2, DEFAULT_CHAT_FRAME:GetFont()))
110 if QuestHelperWorldMapButton then
111 QuestHelperWorldMapButton:SetFont(self.font.serif, select(2, QuestHelperWorldMapButton:GetFont()))
115 QuestHelper.route = {}
116 QuestHelper.to_add = {}
117 QuestHelper.to_remove = {}
118 QuestHelper.quest_log = {}
119 QuestHelper.pos = {nil, {}, 0, 0, 1, "You are here.", 0}
120 QuestHelper.sharing = false -- Will be set to true when sharing with at least one user.
122 function QuestHelper.tooltip:GetPrevLines() -- Just a helper to make life easier.
123 local last = self:NumLines()
124 local name = self:GetName()
125 return _G[name.."TextLeft"..last], _G[name.."TextRight"..last]
128 function QuestHelper:SetTargetLocation(i, x, y, toffset)
129 -- Informs QuestHelper that you're going to be at some location in toffset seconds.
130 local c, z = unpack(QuestHelper_ZoneLookup[i])
132 self.target = self:CreateTable()
133 self.target[2] = self:CreateTable()
135 self.target_time = time()+(toffset or 0)
137 x, y = self.Astrolabe:TranslateWorldMapPosition(c, z, x, y, c, 0)
138 self.target[1] = self.zone_nodes[i]
139 self.target[3] = x * self.continent_scales_x[c]
140 self.target[4] = y * self.continent_scales_y[c]
142 self:SetTargetLocationRecalculate()
145 function QuestHelper:SetTargetLocationRecalculate()
146 if self.target then
147 for i, n in ipairs(self.target[1]) do
148 local a, b = n.x-self.target[3], n.y-self.target[4]
149 self.target[2][i] = math.sqrt(a*a+b*b)
154 function QuestHelper:UnsetTargetLocation()
155 -- Unsets the target set above.
156 if self.target then
157 self:ReleaseTable(self.target[2])
158 self:ReleaseTable(self.target)
159 self.target = nil
160 self.target_time = nil
164 local interruptcount = 0 -- counts how many "played gained control" messages we recieve, used for flight paths
165 local init_cartographer_later = false
167 function QuestHelper:Initialize()
168 local file_problem = false
169 local expected_version = GetAddOnMetadata("QuestHelper", "Version")
170 --local expected_version = QuestHelper_File["main.lua"] -- it was a good idea. Damn you, Curse Client.
172 local expected_files =
174 ["upgrade.lua"] = true,
175 ["main.lua"] = true,
176 ["recycle.lua"] = true,
177 ["objective.lua"] = true,
178 ["quest.lua"] = true,
179 ["questlog.lua"] = true,
180 ["utility.lua"] = true,
181 ["dodads.lua"] = true,
182 ["graph.lua"] = true,
183 ["teleport.lua"] = true,
184 ["pathfinding.lua"] = true,
185 ["routing.lua"] = true,
186 ["custom.lua"] = true,
187 ["menu.lua"] = true,
188 ["hidden.lua"] = true,
189 ["nag.lua"] = true,
190 ["comm.lua"] = true,
191 ["mapbutton.lua"] = true,
192 ["help.lua"] = true,
193 ["pattern.lua"] = true,
194 ["flightpath.lua"] = true,
195 ["tracker.lua"] = true,
196 ["objtips.lua"] = true,
197 ["cartographer.lua"] = true,
198 ["tomtom.lua"] = true,
199 ["textviewer.lua"] = true,
200 ["error.lua"] = true,
203 for file, version in pairs(QuestHelper_File) do
204 if not expected_files[file] then
205 DEFAULT_CHAT_FRAME:AddMessage("Unexpected QuestHelper file: "..file)
206 file_problem = true
207 elseif version ~= expected_version then
208 DEFAULT_CHAT_FRAME:AddMessage("Wrong version of QuestHelper file: "..file.." (found '"..version.."', should be '"..expected_version.."')")
209 if version ~= "Development Version" and expected_version ~= "Development Version" then
210 -- Developers are allowed to mix dev versions with release versions
211 file_problem = true
216 for file in pairs(expected_files) do
217 if not QuestHelper_File[file] then
218 DEFAULT_CHAT_FRAME:AddMessage("Missing QuestHelper file: "..file)
219 file_problem = true
223 -- Don't need this table anymore.
224 QuestHelper_File = nil
226 if QuestHelper_StaticData and not QuestHelper_StaticData["enUS"] then
227 file_problem = true
228 DEFAULT_CHAT_FRAME:AddMessage("Static data does not seem to exist")
231 if file_problem then
232 DEFAULT_CHAT_FRAME:AddMessage("QuestHelper hasn't been installed properly.")
233 message("There was an error starting QuestHelper. Please exit World of Warcraft entirely and try again.")
234 QuestHelper = nil -- Just in case anybody else is checking for us, we're not home
235 return
238 QuestHelper_ErrorCatcher_CompletelyStarted()
240 if not QuestHelper_StaticData then
241 -- If there is no static data for some mysterious reason, create an empty table so that
242 -- other parts of the code can carry on as usual, using locally collected data if it exists.
243 QuestHelper_StaticData = {}
246 QHFormatSetLocale(QuestHelper_Pref.locale or GetLocale())
248 if not QuestHelper_UID then
249 QuestHelper_UID = self:CreateUID()
251 QuestHelper_SaveDate = time()
253 self.Astrolabe = DongleStub("Astrolabe-0.4-QuestHelper")
254 QuestHelper_BuildZoneLookup()
256 if QuestHelper_Locale ~= GetLocale() then
257 self:TextOut(QHText("LOCALE_ERROR"))
258 return
261 if not self:ZoneSanity() then
262 self:TextOut(QHText("ZONE_LAYOUT_ERROR"))
263 message("QuestHelper: "..QHText("ZONE_LAYOUT_ERROR"))
264 return
267 QuestHelper_UpgradeDatabase(_G)
268 QuestHelper_UpgradeComplete()
270 if QuestHelper_SaveVersion ~= 10 then
271 self:TextOut(QHText("DOWNGRADE_ERROR"))
272 return
275 if QuestHelper_IsPolluted(_G) then
276 self:TextOut(QHFormat("NAG_POLLUTED"))
277 self:Purge(nil, true, true)
280 local signature = expected_version .. " on " .. GetBuildInfo()
281 QuestHelper_Quests[signature] = QuestHelper_Quests[signature] or {}
282 QuestHelper_Objectives[signature] = QuestHelper_Objectives[signature] or {}
283 QuestHelper_FlightInstructors[signature] = QuestHelper_FlightInstructors[signature] or {}
284 QuestHelper_FlightRoutes[signature] = QuestHelper_FlightRoutes[signature] or {}
286 QuestHelper_Quests_Local = QuestHelper_Quests[signature]
287 QuestHelper_Objectives_Local = QuestHelper_Objectives[signature]
288 QuestHelper_FlightInstructors_Local = QuestHelper_FlightInstructors[signature]
289 QuestHelper_FlightRoutes_Local = QuestHelper_FlightRoutes[signature]
291 QuestHelper_SeenRealms[GetRealmName()] = true -- some attempt at tracking private servers
293 self.player_level = UnitLevel("player")
295 self:UnregisterEvent("VARIABLES_LOADED")
296 self:RegisterEvent("PLAYER_TARGET_CHANGED")
297 self:RegisterEvent("LOOT_OPENED")
298 self:RegisterEvent("QUEST_COMPLETE")
299 self:RegisterEvent("QUEST_LOG_UPDATE")
300 self:RegisterEvent("QUEST_PROGRESS")
301 self:RegisterEvent("MERCHANT_SHOW")
302 self:RegisterEvent("QUEST_DETAIL")
303 self:RegisterEvent("TAXIMAP_OPENED")
304 self:RegisterEvent("PLAYER_CONTROL_GAINED")
305 self:RegisterEvent("PLAYER_LEVEL_UP")
306 self:RegisterEvent("PARTY_MEMBERS_CHANGED")
307 self:RegisterEvent("CHAT_MSG_ADDON")
308 self:RegisterEvent("CHAT_MSG_SYSTEM")
309 self:RegisterEvent("BAG_UPDATE")
310 self:RegisterEvent("GOSSIP_SHOW")
312 for key, def in pairs(QuestHelper_DefaultPref) do
313 if QuestHelper_Pref[key] == nil then
314 QuestHelper_Pref[key] = def
318 self:SetLocaleFonts()
320 if QuestHelper_Pref.share and not QuestHelper_Pref.solo then
321 self:EnableSharing()
324 if QuestHelper_Pref.hide then
325 self.map_overlay:Hide()
328 self:HandlePartyChange()
330 self:Nag("all")
332 for locale in pairs(QuestHelper_StaticData) do
333 if locale ~= self.locale then
334 -- Will delete references to locales you don't use.
335 QuestHelper_StaticData[locale] = nil
336 _G["QuestHelper_StaticData_" .. locale] = nil
340 local static = QuestHelper_StaticData[self.locale]
342 if static then
343 if static.flight_instructors then for faction in pairs(static.flight_instructors) do
344 if faction ~= self.faction then
345 -- Will delete references to flight instructors that don't belong to your faction.
346 static.flight_instructors[faction] = nil
348 end end
350 if static.quest then for faction in pairs(static.quest) do
351 if faction ~= self.faction then
352 -- Will delete references to quests that don't belong to your faction.
353 static.quest[faction] = nil
355 end end
357 if not QuestHelper:IsWrath() then
358 for cat, list in pairs(static.objective) do
359 for name, obj in pairs(list) do
360 if obj.pos then
361 for i, cpos in pairs(obj.pos) do
362 QuestHelper_ConvertCoordsFromWrath(cpos)
370 self:ResetPathing()
372 -- Adding QuestHelper_CharVersion, so I know if I've already converted this characters saved data.
373 if not QuestHelper_CharVersion then
374 -- Changing per-character flight routes, now only storing the flight points they have,
375 -- will attempt to guess the routes from this.
376 local routes = {}
378 for i, l in pairs(QuestHelper_KnownFlightRoutes) do
379 for key in pairs(l) do
380 routes[key] = true
384 QuestHelper_KnownFlightRoutes = routes
386 -- Deleting the player's home again.
387 -- But using the new CharVersion variable I'm adding is cleaner that what I was doing, so I'll go with it.
388 QuestHelper_Home = nil
389 QuestHelper_CharVersion = 1
392 if not QuestHelper_Home then
393 -- Not going to bother complaining about the player's home not being set, uncomment this when the home is used in routing.
394 -- self:TextOut(QHText("HOME_NOT_KNOWN"))
397 self.minimap_dodad = self:CreateMipmapDodad()
399 if QuestHelper_Pref.map_button then
400 QuestHelper:InitMapButton()
403 if QuestHelper_Pref.cart_wp then
404 init_cartographer_later = true
407 if QuestHelper_Pref.tomtom_wp then
408 self:EnableTomTom()
411 self.tracker:SetScale(QuestHelper_Pref.track_scale)
413 if QuestHelper_Pref.track and not QuestHelper_Pref.hide then
414 self:ShowTracker()
417 local version = GetAddOnMetadata("QuestHelper", "Version") or "Unknown"
418 if QuestHelper_Version ~= version then
419 QuestHelper_Version = version
420 self:ChangeLog()
423 self:SetScript("OnUpdate", self.OnUpdate)
425 collectgarbage("collect") -- Free everything we aren't using.
427 if self.debug_objectives then
428 for name, data in pairs(self.debug_objectives) do
429 self:LoadDebugObjective(name, data)
433 self.Routing:Initialize() -- Set up the routing task
435 --[[ -- This is just an example of how the WoW profiler biases its profiles heavily.
436 function C()
439 function A()
440 q = 0
441 for x = 0, 130000000, 1 do
445 function B()
446 q = 0
447 for x = 0, 12000000, 1 do
452 function B2()
453 q = 0
454 for x = 0, 1200000, 1 do
455 --q = q + x
460 debugprofilestart()
462 local ta = debugprofilestop()
464 local tb = debugprofilestop()
466 local tc = debugprofilestop()
468 QuestHelper:TextOut(string.format("%d %d %d", ta, tb - ta, tc - tb))
469 QuestHelper:TextOut(string.format("%d %d", GetFunctionCPUUsage(A), GetFunctionCPUUsage(B)))
471 --/script SetCVar("scriptProfile", value)]]
474 function QuestHelper:OnEvent(event)
475 if event == "VARIABLES_LOADED" then
476 self:Initialize()
479 if event == "GOSSIP_SHOW" then
480 local name, id = UnitName("npc"), self:GetUnitID("npc")
481 if name and id then
482 self:GetObjective("monster", name).o.id = id
483 --self:TextOut("NPC: "..name.." = "..id)
487 if event == "PLAYER_TARGET_CHANGED" then
488 local name, id = UnitName("target"), self:GetUnitID("target")
489 if name and id then
490 self:GetObjective("monster", name).o.id = id
491 --self:TextOut("Target: "..name.." = "..id)
494 if UnitExists("target") and UnitIsVisible("target") and UnitCreatureType("target") ~= "Critter" and not UnitIsPlayer("target") and not UnitPlayerControlled("target") then
495 local index, x, y = self:UnitPosition("target")
497 if index then -- Might not have a position if inside an instance.
498 local w = 0.1
500 -- Modify the weight based on how far they are from us.
501 -- We don't know the exact location (using our own location), so the farther, the less sure we are that it's correct.
502 if CheckInteractDistance("target", 3) then w = 1
503 elseif CheckInteractDistance("target", 2) then w = 0.89
504 elseif CheckInteractDistance("target", 1) or CheckInteractDistance("target", 4) then w = 0.33 end
506 local monster_objective = self:GetObjective("monster", UnitName("target"))
507 self:AppendObjectivePosition(monster_objective, index, x, y, w)
509 monster_objective.o.faction = (UnitFactionGroup("target") == "Alliance" and 1) or
510 (UnitFactionGroup("target") == "Horde" and 2) or nil
512 local level = UnitLevel("target")
513 if level and level >= 1 then
514 local w = monster_objective.o.levelw or 0
515 monster_objective.o.level = ((monster_objective.o.level or 0)*w+level)/(w+1)
516 monster_objective.o.levelw = w+1
522 if event == "LOOT_OPENED" then
523 local target = UnitName("target")
524 if target and UnitIsDead("target") and UnitCreatureType("target") ~= "Critter" and not UnitIsPlayer("target") and not UnitPlayerControlled("target") then
525 local index, x, y = self:UnitPosition("target")
527 local monster_objective = self:GetObjective("monster", target)
528 monster_objective.o.looted = (monster_objective.o.looted or 0) + 1
530 if index then -- Might not have a position if inside an instance.
531 self:AppendObjectivePosition(monster_objective, index, x, y)
534 for i = 1, GetNumLootItems() do
535 local icon, name, number, rarity = GetLootSlotInfo(i)
536 if name then
537 if number and number >= 1 then
538 self:AppendItemObjectiveDrop(self:GetObjective("item", name), name, target, number)
539 else
540 local total = (name:match(COPPER_AMOUNT:gsub("%%d", "%(%%d+%)")) or 0) +
541 (name:match(SILVER_AMOUNT:gsub("%%d", "%(%%d+%)")) or 0) * 100 +
542 (name:match(GOLD_AMOUNT:gsub("%%d", "%(%%d+%)")) or 0) * 10000
544 if total > 0 then
545 self:AppendObjectiveDrop(self:GetObjective("item", "money"), target, total)
550 else
551 local container = nil
553 -- Go through the players inventory and look for a locked item, we're probably looting it.
554 for bag = 0,NUM_BAG_SLOTS do
555 for slot = 1,GetContainerNumSlots(bag) do
556 local link = GetContainerItemLink(bag, slot)
557 if link and select(3, GetContainerItemInfo(bag, slot)) then
558 if container == nil then
559 -- Found a locked item and haven't previously assigned to container, assign its name, or false if we fail to parse it.
560 container = select(3, string.find(link, "|h%[(.+)%]|h|r")) or false
561 else
562 -- Already tried to assign to a container. If there are multiple locked items, we give up.
563 container = false
569 if container then
570 local container_objective = self:GetObjective("item", container)
571 container_objective.o.opened = (container_objective.o.opened or 0) + 1
573 for i = 1, GetNumLootItems() do
574 local icon, name, number, rarity = GetLootSlotInfo(i)
575 if name and number >= 1 then
576 self:AppendItemObjectiveContainer(self:GetObjective("item", name), container, number)
579 else
580 -- No idea where the items came from.
581 local index, x, y = self:PlayerPosition()
583 if index then
584 for i = 1, GetNumLootItems() do
585 local icon, name, number, rarity = GetLootSlotInfo(i)
586 if name and number >= 1 then
587 self:AppendItemObjectivePosition(self:GetObjective("item", name), name, index, x, y)
595 if event == "CHAT_MSG_SYSTEM" then
596 local home_name = self:convertPattern(ERR_DEATHBIND_SUCCESS_S)(arg1)
597 if home_name then
598 if self.i then
599 self:TextOut(QHText("HOME_CHANGED"))
600 self:TextOut(QHText("WILL_RESET_PATH"))
602 local home = QuestHelper_Home
603 if not home then
604 home = {}
605 QuestHelper_Home = home
608 home[1], home[2], home[3], home[4] = self.i, self.x, self.y, home_name
609 self.defered_graph_reset = true
614 if event == "CHAT_MSG_ADDON" then
615 if arg1 == "QHpr" and (arg3 == "PARTY" or arg3 == "WHISPER") and arg4 ~= UnitName("player") then
616 self:HandleRemoteData(arg2, arg4)
620 if event == "PARTY_MEMBERS_CHANGED" then
621 self:HandlePartyChange()
624 if event == "QUEST_LOG_UPDATE" or
625 event == "PLAYER_LEVEL_UP" or
626 event == "PARTY_MEMBERS_CHANGED" then
627 self.defered_quest_scan = true
630 if event == "QUEST_DETAIL" then
631 if not self.quest_giver then self.quest_giver = {} end
632 local npc = UnitName("npc")
633 if npc then
634 -- Some NPCs aren't actually creatures, and so their positions might not be marked by PLAYER_TARGET_CHANGED.
635 local index, x, y = self:UnitPosition("npc")
637 if index then -- Might not have a position if inside an instance.
638 local npc_objective = self:GetObjective("monster", npc)
639 self:AppendObjectivePosition(npc_objective, index, x, y)
640 self.quest_giver[GetTitleText()] = npc
645 if event == "QUEST_COMPLETE" or event == "QUEST_PROGRESS" then
646 local quest = GetTitleText()
647 if quest then
648 local level, hash = self:GetQuestLevel(quest)
649 if not level or level < 1 then
650 --self:TextOut("Don't know quest level for ".. quest.."!")
651 return
653 local q = self:GetQuest(quest, level, hash)
655 if q.need_hash then
656 q.o.hash = hash
659 local unit = UnitName("npc")
660 if unit then
661 q.o.finish = unit
662 q.o.pos = nil
664 -- Some NPCs aren't actually creatures, and so their positions might not be marked by PLAYER_TARGET_CHANGED.
665 local index, x, y = self:UnitPosition("npc")
666 if index then -- Might not have a position if inside an instance.
667 local npc_objective = self:GetObjective("monster", unit)
668 self:AppendObjectivePosition(npc_objective, index, x, y)
670 elseif not q.o.finish then
671 local index, x, y = self:PlayerPosition()
672 if index then -- Might not have a position if inside an instance.
673 self:AppendObjectivePosition(q, index, x, y)
679 if event == "MERCHANT_SHOW" then
680 local npc_name = UnitName("npc")
681 if npc_name then
682 local npc_objective = self:GetObjective("monster", npc_name)
683 local index = 1
684 while true do
685 local item_name = GetMerchantItemInfo(index)
686 if item_name then
687 index = index + 1
688 local item_objective = self:GetObjective("item", item_name)
689 if not item_objective.o.vendor then
690 item_objective.o.vendor = {npc_name}
691 else
692 local known = false
693 for i, vendor in ipairs(item_objective.o.vendor) do
694 if npc_name == vendor then
695 known = true
696 break
699 if not known then
700 table.insert(item_objective.o.vendor, npc_name)
703 else
704 break
710 if event == "TAXIMAP_OPENED" then
711 self:taxiMapOpened()
714 if event == "PLAYER_CONTROL_GAINED" then
715 interruptcount = interruptcount + 1
718 if event == "BAG_UPDATE" then
719 for slot = 1,GetContainerNumSlots(arg1) do
720 local link = GetContainerItemLink(arg1, slot)
721 if link then
722 local id, name = select(3, string.find(link, "|Hitem:(%d+):.-|h%[(.-)%]|h"))
723 if name then
724 self:GetObjective("item", name).o.id = tonumber(id)
731 local map_shown_decay = 0
732 local delayed_action = 100
733 local update_count = 0
734 local ontaxi = false
736 function QuestHelper:OnUpdate()
738 if init_cartographer_later and Cartographer_Waypoints then -- there has to be a better way to do this
739 init_cartographer_later = false
740 if QuestHelper_Pref.cart_wp then
741 self:EnableCartographer()
745 if not ontaxi and UnitOnTaxi("player") then
746 self:flightBegan()
747 interruptcount = 0
748 elseif ontaxi and not UnitOnTaxi("player") then
749 self:flightEnded(interruptcount > 1)
751 ontaxi = UnitOnTaxi("player")
753 update_count = update_count - 1
755 if update_count <= 0 then
757 -- Reset the update count for next time around; this will make sure the body executes every time
758 -- when perf_scale >= 1, and down to 1 in 10 iterations when perf_scale < 1, or when hidden.
759 update_count = update_count + (QuestHelper_Pref.hide and 10 or 1/QuestHelper_Pref.perf_scale)
761 if update_count < 0 then
762 -- Make sure the count doesn't go perpetually negative; don't know what will happen if it underflows.
763 update_count = 0
766 if self.Astrolabe.WorldMapVisible then
767 -- We won't trust that the zone returned by Astrolabe is correct until map_shown_decay is 0.
768 map_shown_decay = 2
769 elseif map_shown_decay > 0 then
770 map_shown_decay = map_shown_decay - 1
771 else
772 SetMapToCurrentZone()
775 delayed_action = delayed_action - 1
776 if delayed_action <= 0 then
777 delayed_action = 100
778 self:HandlePartyChange()
781 local nc, nz, nx, ny = self.Astrolabe:GetCurrentPlayerPosition()
783 if nc and nc == self.c and map_shown_decay > 0 and self.z > 0 and self.z ~= nz then
784 -- There's a chance Astrolable will return the wrong zone if you're messing with the world map, if you can
785 -- be seen in that zone but aren't in it.
786 local nnx, nny = self.Astrolabe:TranslateWorldMapPosition(nc, nz, nx, ny, nc, self.z)
787 if nnx > 0 and nny > 0 and nnx < 1 and nny < 1 then
788 nz, nx, ny = self.z, nnx, nny
792 if nc and nc > 0 and nz == 0 and nc == self.c and self.z > 0 then
793 nx, ny = self.Astrolabe:TranslateWorldMapPosition(nc, nz, nx, ny, nc, self.z)
794 if nx and ny and nx > -0.1 and ny > -0.1 and nx < 1.1 and ny < 1.1 then
795 nz = self.z
796 else
797 nc, nz, nx, ny = nil, nil, nil, nil
801 if nc and nz > 0 then
802 self.c, self.z, self.x, self.y = nc, nz, nx, ny
803 self.i = QuestHelper_IndexLookup[nc][nz]
806 if self.defered_quest_scan and not self.graph_in_limbo then
807 self.defered_quest_scan = false
808 self:ScanQuestLog()
811 if self.c then
812 self:RunCoroutine()
815 local level = UnitLevel("player")
816 if level >= 58 and self.player_level < 58 then
817 self.defered_graph_reset = true
819 self.player_level = level
821 self:PumpCommMessages()
825 QuestHelper:RegisterEvent("VARIABLES_LOADED")
826 QuestHelper:SetScript("OnEvent", QuestHelper.OnEvent)