1 QuestHelper_File
["main.lua"] = "Development Version"
2 QuestHelper_Loadtime
["main.lua"] = GetTime()
4 QuestHelper
= CreateFrame("Frame", "QuestHelper", nil)
6 -- Just to make sure it's always 'seen' (there's nothing that can be seen, but still...), and therefore always updating.
7 QuestHelper
:SetFrameStrata("TOOLTIP")
9 QuestHelper_SaveVersion
= 10
10 QuestHelper_CharVersion
= 1
11 QuestHelper_Locale
= GetLocale() -- This variable is used only for the collected data, and has nothing to do with displayed text.
12 QuestHelper_Quests
= {}
13 QuestHelper_Objectives
= {}
18 QuestHelper_DefaultPref
=
23 filter_blocked
=false, -- Hides blocked objectives, such as quest turn-ins for incomplete quests
24 filter_watched
=false, -- Limits to Watched objectives
26 track_minimized
=false,
43 locale
= GetLocale(), -- This variable is used for display purposes, and has nothing to do with the collected data.
44 perf_scale
= 1, -- How much background processing can the current machine handle? Higher means more load, lower means better performance.
45 perfload_scale
= 1, -- Performance scale to use on startup
49 QuestHelper_FlightInstructors
= {}
50 QuestHelper_FlightLinks
= {}
51 QuestHelper_FlightRoutes
= {}
52 QuestHelper_KnownFlightRoutes
= {}
53 QuestHelper_SeenRealms
= {}
55 QuestHelper
.tooltip
= CreateFrame("GameTooltip", "QuestHelperTooltip", nil, "GameTooltipTemplate")
56 QuestHelper
.objective_objects
= {}
57 QuestHelper
.user_objectives
= {}
58 QuestHelper
.quest_objects
= {}
59 QuestHelper
.player_level
= 1
60 QuestHelper
.locale
= QuestHelper_Locale
62 QuestHelper
.faction
= (UnitFactionGroup("player") == "Alliance" and 1) or
63 (UnitFactionGroup("player") == "Horde" and 2)
65 assert(QuestHelper
.faction
)
67 QuestHelper
.font
= {serif
=GameFontNormal
:GetFont(), sans
=ChatFontNormal
:GetFont(), fancy
=QuestTitleFont
:GetFont()}
69 function QuestHelper
:GetFontPath(list_string
, font
)
71 for name
in string.gmatch(list_string
, "[^;]+") do
72 if font
:SetFont(name
, 10) then
74 elseif font
:SetFont("Interface\\AddOns\\QuestHelper\\Fonts\\"..name
, 10) then
75 return "Interface\\AddOns\\QuestHelper\\Fonts\\"..name
81 function QuestHelper
:SetLocaleFonts()
86 local font
= self
:CreateText(self
)
88 if QuestHelper_Locale
~= QuestHelper_Pref
.locale
then
89 -- Only use alternate fonts if using a language the client wasn't intended for.
90 local replacements
= QuestHelper_SubstituteFonts
[QuestHelper_Pref
.locale
]
92 self
.font
.sans
= self
:GetFontPath(replacements
.sans
, font
)
93 self
.font
.serif
= self
:GetFontPath(replacements
.serif
, font
)
94 self
.font
.fancy
= self
:GetFontPath(replacements
.fancy
, font
)
98 self
.font
.sans
= self
.font
.sans
or self
:GetFontPath(QuestHelper_Pref
.locale
.."_sans.ttf", font
)
99 self
.font
.serif
= self
.font
.serif
or self
:GetFontPath(QuestHelper_Pref
.locale
.."_serif.ttf", font
) or self
.font
.sans
100 self
.font
.fancy
= self
.font
.fancy
or self
:GetFontPath(QuestHelper_Pref
.locale
.."_fancy.ttf", font
) or self
.font
.serif
102 self
:ReleaseText(font
)
104 self
.font
.sans
= self
.font
.sans
or ChatFontNormal
:GetFont()
105 self
.font
.serif
= self
.font
.serif
or GameFontNormal
:GetFont()
106 self
.font
.fancy
= self
.font
.fancy
or QuestTitleFont
:GetFont()
108 -- Need to change the font of the chat frame, for any messages that QuestHelper displays.
109 -- This should do nothing if not using an alternate font.
110 DEFAULT_CHAT_FRAME
:SetFont(self
.font
.sans
, select(2, DEFAULT_CHAT_FRAME
:GetFont()))
113 QuestHelper
.route
= {}
114 QuestHelper
.to_add
= {}
115 QuestHelper
.to_remove
= {}
116 QuestHelper
.quest_log
= {}
117 QuestHelper
.pos
= {nil, {}, 0, 0, 1, "You are here.", 0}
118 QuestHelper
.sharing
= false -- Will be set to true when sharing with at least one user.
120 function QuestHelper
.tooltip
:GetPrevLines() -- Just a helper to make life easier.
121 local last
= self
:NumLines()
122 local name
= self
:GetName()
123 return _G
[name
.."TextLeft"..last
], _G
[name
.."TextRight"..last
]
126 function QuestHelper
:SetTargetLocation(i
, x
, y
, toffset
)
127 -- Informs QuestHelper that you're going to be at some location in toffset seconds.
128 local c
, z
= unpack(QuestHelper_ZoneLookup
[i
])
130 self
.target
= self
:CreateTable()
131 self
.target
[2] = self
:CreateTable()
133 self
.target_time
= time()+(toffset
or 0)
135 x
, y
= self
.Astrolabe
:TranslateWorldMapPosition(c
, z
, x
, y
, c
, 0)
136 self
.target
[1] = self
.zone_nodes
[i
]
137 self
.target
[3] = x
* self
.continent_scales_x
[c
]
138 self
.target
[4] = y
* self
.continent_scales_y
[c
]
140 self
:SetTargetLocationRecalculate()
143 function QuestHelper
:SetTargetLocationRecalculate()
145 for i
, n
in ipairs(self
.target
[1]) do
146 local a
, b
= n
.x
-self
.target
[3], n
.y
-self
.target
[4]
147 self
.target
[2][i
] = math
.sqrt(a
*a
+b
*b
)
152 function QuestHelper
:UnsetTargetLocation()
153 -- Unsets the target set above.
155 self
:ReleaseTable(self
.target
[2])
156 self
:ReleaseTable(self
.target
)
158 self
.target_time
= nil
162 local interruptcount
= 0 -- counts how many "played gained control" messages we recieve, used for flight paths
163 local init_cartographer_later
= false
165 function QuestHelper
:Initialize()
166 QuestHelper_Loadtime
["init_start"] = GetTime()
168 local file_problem
= false
169 local expected_version
= GetAddOnMetadata("QuestHelper", "Version")
171 local expected_files
=
173 ["bst_pre.lua"] = true,
174 ["bst_post.lua"] = true,
175 ["bst_astrolabe.lua"] = true,
176 ["bst_ctl.lua"] = true,
177 ["bst_libaboutpanel.lua"] = true,
179 ["upgrade.lua"] = true,
181 ["recycle.lua"] = true,
182 ["objective.lua"] = true,
183 ["quest.lua"] = true,
184 ["questlog.lua"] = true,
185 ["utility.lua"] = true,
186 ["dodads.lua"] = true,
187 ["graph.lua"] = true,
188 ["teleport.lua"] = true,
189 ["pathfinding.lua"] = true,
190 ["routing.lua"] = true,
191 ["custom.lua"] = true,
193 ["hidden.lua"] = true,
196 ["mapbutton.lua"] = true,
198 ["pattern.lua"] = true,
199 ["flightpath.lua"] = true,
200 ["tracker.lua"] = true,
201 ["objtips.lua"] = true,
202 ["cartographer.lua"] = true,
203 ["tomtom.lua"] = true,
204 ["textviewer.lua"] = true,
205 ["error.lua"] = true,
206 ["timeslice.lua"] = true,
209 ["static.lua"] = true,
210 ["static_deDE.lua"] = true,
211 ["static_enUS.lua"] = true,
212 ["static_esES.lua"] = true,
213 ["static_esMX.lua"] = true,
214 ["static_frFR.lua"] = true,
215 ["static_koKR.lua"] = true,
216 ["static_ruRU.lua"] = true,
217 ["static_zhCN.lua"] = true,
218 ["static_zhTW.lua"] = true,
220 ["collect.lua"] = true,
221 ["collect_achievement.lua"] = true,
222 ["collect_lzw.lua"] = true,
223 ["collect_traveled.lua"] = true,
224 ["collect_zone.lua"] = true,
225 ["collect_location.lua"] = true,
226 ["collect_merger.lua"] = true,
227 ["collect_monster.lua"] = true,
228 ["collect_item.lua"] = true,
229 ["collect_object.lua"] = true,
230 ["collect_loot.lua"] = true,
231 ["collect_patterns.lua"] = true,
232 ["collect_flight.lua"] = true,
233 ["collect_util.lua"] = true,
234 ["collect_quest.lua"] = true,
235 ["collect_equip.lua"] = true,
236 ["collect_notifier.lua"] = true,
237 ["collect_bitstream.lua"] = true,
238 ["collect_spec.lua"] = true,
239 ["collect_upgrade.lua"] = true,
240 ["collect_merchant.lua"] = true,
243 local uninstallederr
= ""
245 for file
, version
in pairs(QuestHelper_File
) do
246 if not expected_files
[file
] then
247 local errmsg
= "Unexpected QuestHelper file: "..file
248 DEFAULT_CHAT_FRAME
:AddMessage(errmsg
)
249 uninstallederr
= uninstallederr
.. " " .. errmsg
.. "\n"
251 elseif version
~= expected_version
then
252 local errmsg
= "Wrong version of QuestHelper file: "..file
.." (found '"..version
.."', should be '"..expected_version
.."')"
253 DEFAULT_CHAT_FRAME
:AddMessage(errmsg
)
254 uninstallederr
= uninstallederr
.. " " .. errmsg
.. "\n"
255 if version
~= "Development Version" and expected_version
~= "Development Version" then
256 -- Developers are allowed to mix dev versions with release versions
262 for file
in pairs(expected_files
) do
263 if not QuestHelper_File
[file
] then
264 local errmsg
= "Missing QuestHelper file: "..file
265 DEFAULT_CHAT_FRAME
:AddMessage(errmsg
)
266 uninstallederr
= uninstallederr
.. " " .. errmsg
.. "\n"
271 -- Don't need this table anymore.
272 QuestHelper_File
= nil
274 if QuestHelper_StaticData
and not QuestHelper_StaticData
[GetLocale()] then
275 local errmsg
= "Static data does not seem to exist"
276 DEFAULT_CHAT_FRAME
:AddMessage(errmsg
)
278 -- TODO: Are you sure this should be an error? Shouldn't we let people we don't have data for collect their own?
279 uninstallederr
= uninstallederr
.. " " .. errmsg
.. "\n"
284 message(QHText("PLEASE_RESTART"))
285 QuestHelper_ErrorCatcher_ExplicitError("not-installed-properly" .. "\n" .. uninstallederr
)
286 QuestHelper
= nil -- Just in case anybody else is checking for us, we're not home
290 if not GetCategoryList
then
291 message(QHText("PRIVATE_SERVER"))
292 QuestHelper_ErrorCatcher_ExplicitError("error id cakbep ten T")
297 if not DongleStub
then
298 message(QHText("NOT_UNZIPPED_CORRECTLY"))
299 QuestHelper_ErrorCatcher_ExplicitError("not-unzipped-properly")
300 QuestHelper
= nil -- Just in case anybody else is checking for us, we're not home
304 QuestHelper_ErrorCatcher_CompletelyStarted()
306 if not QuestHelper_StaticData
then
307 -- If there is no static data for some mysterious reason, create an empty table so that
308 -- other parts of the code can carry on as usual, using locally collected data if it exists.
309 QuestHelper_StaticData
= {}
312 QHFormatSetLocale(QuestHelper_Pref
.locale
or GetLocale())
314 if not QuestHelper_UID
then
315 QuestHelper_UID
= self
:CreateUID()
317 QuestHelper_SaveDate
= time()
319 self
.Astrolabe
= DongleStub("Astrolabe-0.4-QuestHelper")
320 QuestHelper_BuildZoneLookup()
322 if QuestHelper_Locale
~= GetLocale() then
323 self
:TextOut(QHText("LOCALE_ERROR"))
327 if not self
:ZoneSanity() then
328 self
:TextOut(QHText("ZONE_LAYOUT_ERROR"))
329 message("QuestHelper: "..QHText("ZONE_LAYOUT_ERROR"))
333 QuestHelper_UpgradeDatabase(_G
)
334 QuestHelper_UpgradeComplete()
336 if QuestHelper_SaveVersion
~= 10 then
337 self
:TextOut(QHText("DOWNGRADE_ERROR"))
341 if QuestHelper_IsPolluted(_G
) then
342 self
:TextOut(QHFormat("NAG_POLLUTED"))
343 self
:Purge(nil, true, true)
346 local signature
= expected_version
.. " on " .. GetBuildInfo()
347 QuestHelper_Quests
[signature
] = QuestHelper_Quests
[signature
] or {}
348 QuestHelper_Objectives
[signature
] = QuestHelper_Objectives
[signature
] or {}
349 QuestHelper_FlightInstructors
[signature
] = QuestHelper_FlightInstructors
[signature
] or {}
350 QuestHelper_FlightRoutes
[signature
] = QuestHelper_FlightRoutes
[signature
] or {}
352 QuestHelper_Quests_Local
= QuestHelper_Quests
[signature
]
353 QuestHelper_Objectives_Local
= QuestHelper_Objectives
[signature
]
354 QuestHelper_FlightInstructors_Local
= QuestHelper_FlightInstructors
[signature
]
355 QuestHelper_FlightRoutes_Local
= QuestHelper_FlightRoutes
[signature
]
357 QuestHelper_SeenRealms
[GetRealmName()] = true -- some attempt at tracking private servers
361 self
.player_level
= UnitLevel("player")
363 self
:UnregisterEvent("VARIABLES_LOADED")
364 self
:RegisterEvent("PLAYER_TARGET_CHANGED")
365 self
:RegisterEvent("LOOT_OPENED")
366 self
:RegisterEvent("QUEST_COMPLETE")
367 self
:RegisterEvent("QUEST_LOG_UPDATE")
368 self
:RegisterEvent("QUEST_PROGRESS")
369 self
:RegisterEvent("MERCHANT_SHOW")
370 self
:RegisterEvent("QUEST_DETAIL")
371 self
:RegisterEvent("TAXIMAP_OPENED")
372 self
:RegisterEvent("PLAYER_CONTROL_GAINED")
373 self
:RegisterEvent("PLAYER_LEVEL_UP")
374 self
:RegisterEvent("PARTY_MEMBERS_CHANGED")
375 self
:RegisterEvent("CHAT_MSG_ADDON")
376 self
:RegisterEvent("CHAT_MSG_SYSTEM")
377 self
:RegisterEvent("BAG_UPDATE")
378 self
:RegisterEvent("GOSSIP_SHOW")
379 self
:RegisterEvent("CHAT_MSG_CHANNEL_NOTICE")
381 -- Use DefaultPref as fallback for unset preference keys.
382 setmetatable(QuestHelper_Pref
, {__index
=QuestHelper_DefaultPref
})
384 self
:SetLocaleFonts()
386 if QuestHelper_Pref
.share
and not QuestHelper_Pref
.solo
then
390 if QuestHelper_Pref
.hide
then
391 self
.map_overlay
:Hide()
394 self
:HandlePartyChange()
398 for locale
in pairs(QuestHelper_StaticData
) do
399 if locale
~= self
.locale
then
400 -- Will delete references to locales you don't use.
401 QuestHelper_StaticData
[locale
] = nil
402 _G
["QuestHelper_StaticData_" .. locale
] = nil
406 local static
= QuestHelper_StaticData
[self
.locale
]
409 if static
.flight_instructors
then for faction
in pairs(static
.flight_instructors
) do
410 if faction
~= self
.faction
then
411 -- Will delete references to flight instructors that don't belong to your faction.
412 static
.flight_instructors
[faction
] = nil
416 if static
.quest
then for faction
in pairs(static
.quest
) do
417 if faction
~= self
.faction
then
418 -- Will delete references to quests that don't belong to your faction.
419 static
.quest
[faction
] = nil
424 -- Adding QuestHelper_CharVersion, so I know if I've already converted this characters saved data.
425 if not QuestHelper_CharVersion
then
426 -- Changing per-character flight routes, now only storing the flight points they have,
427 -- will attempt to guess the routes from this.
430 for i
, l
in pairs(QuestHelper_KnownFlightRoutes
) do
431 for key
in pairs(l
) do
436 QuestHelper_KnownFlightRoutes
= routes
438 -- Deleting the player's home again.
439 -- But using the new CharVersion variable I'm adding is cleaner that what I was doing, so I'll go with it.
440 QuestHelper_Home
= nil
441 QuestHelper_CharVersion
= 1
444 if not QuestHelper_Home
then
445 -- Not going to bother complaining about the player's home not being set, uncomment this when the home is used in routing.
446 -- self:TextOut(QHText("HOME_NOT_KNOWN"))
449 self
.minimap_dodad
= self
:CreateMipmapDodad()
451 if QuestHelper_Pref
.map_button
then
452 QuestHelper
:InitMapButton()
455 if QuestHelper_Pref
.cart_wp
then
456 init_cartographer_later
= true
459 if QuestHelper_Pref
.tomtom_wp
then
463 self
.tracker
:SetScale(QuestHelper_Pref
.track_scale
)
465 if QuestHelper_Pref
.track
and not QuestHelper_Pref
.hide
then
469 local version
= GetAddOnMetadata("QuestHelper", "Version") or "Unknown"
471 local major
, minor
= (QuestHelper_Version
or ""):match("^(%d+)%.(%d+)")
472 major
, minor
= tonumber(major
), tonumber(minor
)
474 -- For versions before 0.82, we're changing the default level offset to 3.
475 if major
== 0 and minor
and minor
< 82 and QuestHelper_Pref
.level
== 2 then
476 QuestHelper_Pref
.level
= nil
479 -- For versions before 0.84...
480 if major
== 0 and minor
and minor
< 84 then
481 -- remove all keys that match their default setting.
482 for key
, val
in pairs(QuestHelper_DefaultPref
) do
483 if QuestHelper_Pref
[key
] == val
then
484 QuestHelper_Pref
[key
] = nil
489 if QuestHelper_Version
~= version
then
490 QuestHelper_Version
= version
494 self
:SetScript("OnUpdate", self
.OnUpdate
)
496 -- Seems to do its own garbage collection pass before fully loading, so I'll just rely on that
497 --collectgarbage("collect") -- Free everything we aren't using.
499 if self
.debug_objectives
then
500 for name
, data
in pairs(self
.debug_objectives
) do
501 self
:LoadDebugObjective(name
, data
)
505 QH_Timeslice_Add(function ()
507 self
.Routing
:Initialize() -- Set up the routing task
510 --[[ -- This is just an example of how the WoW profiler biases its profiles heavily.
516 for x = 0, 130000000, 1 do
522 for x = 0, 12000000, 1 do
529 for x = 0, 1200000, 1 do
537 local ta = debugprofilestop()
539 local tb = debugprofilestop()
541 local tc = debugprofilestop()
543 QuestHelper:TextOut(string.format("%d %d %d", ta, tb - ta, tc - tb))
544 QuestHelper:TextOut(string.format("%d %d", GetFunctionCPUUsage(A), GetFunctionCPUUsage(B)))
546 --/script SetCVar("scriptProfile", value)]]
548 LibStub("LibAboutPanelQH").new(nil, "QuestHelper")
550 QuestHelper_Loadtime
["init_end"] = GetTime()
554 local please_donate_enabled
= true
555 local please_donate_initted
= false
557 function QuestHelper
:OnEvent(event
)
558 if event
== "VARIABLES_LOADED" then
559 local tstart
= GetTime()
561 QH_Timeslice_Increment(GetTime() - tstart
, "init")
564 local tstart
= GetTime()
566 if event
== "GOSSIP_SHOW" then
567 local name
, id
= UnitName("npc"), self
:GetUnitID("npc")
569 self
:GetObjective("monster", name
).o
.id
= id
570 --self:TextOut("NPC: "..name.." = "..id)
574 if event
== "PLAYER_TARGET_CHANGED" then
575 local name
, id
= UnitName("target"), self
:GetUnitID("target")
577 self
:GetObjective("monster", name
).o
.id
= id
578 --self:TextOut("Target: "..name.." = "..id)
581 if UnitExists("target") and UnitIsVisible("target") and UnitCreatureType("target") ~= "Critter" and not UnitIsPlayer("target") and not UnitPlayerControlled("target") then
582 local index
, x
, y
= self
:UnitPosition("target")
584 if index
then -- Might not have a position if inside an instance.
587 -- Modify the weight based on how far they are from us.
588 -- We don't know the exact location (using our own location), so the farther, the less sure we are that it's correct.
589 if CheckInteractDistance("target", 3) then w
= 1
590 elseif CheckInteractDistance("target", 2) then w
= 0.89
591 elseif CheckInteractDistance("target", 1) or CheckInteractDistance("target", 4) then w
= 0.33 end
593 local monster_objective
= self
:GetObjective("monster", UnitName("target"))
594 self
:AppendObjectivePosition(monster_objective
, index
, x
, y
, w
)
596 monster_objective
.o
.faction
= (UnitFactionGroup("target") == "Alliance" and 1) or
597 (UnitFactionGroup("target") == "Horde" and 2) or nil
599 local level
= UnitLevel("target")
600 if level
and level
>= 1 then
601 local w
= monster_objective
.o
.levelw
or 0
602 monster_objective
.o
.level
= ((monster_objective
.o
.level
or 0)*w
+level
)/(w
+1)
603 monster_objective
.o
.levelw
= w
+1
609 if event
== "LOOT_OPENED" then
610 local target
= UnitName("target")
611 if target
and UnitIsDead("target") and UnitCreatureType("target") ~= "Critter" and not UnitIsPlayer("target") and not UnitPlayerControlled("target") then
612 local index
, x
, y
= self
:UnitPosition("target")
614 local monster_objective
= self
:GetObjective("monster", target
)
615 monster_objective
.o
.looted
= (monster_objective
.o
.looted
or 0) + 1
617 if index
then -- Might not have a position if inside an instance.
618 self
:AppendObjectivePosition(monster_objective
, index
, x
, y
)
621 for i
= 1, GetNumLootItems() do
622 local icon
, name
, number, rarity
= GetLootSlotInfo(i
)
624 if number and number >= 1 then
625 self
:AppendItemObjectiveDrop(self
:GetObjective("item", name
), name
, target
, number)
627 local total
= (name
:match(COPPER_AMOUNT
:gsub("%%d", "%(%%d+%)")) or 0) +
628 (name
:match(SILVER_AMOUNT
:gsub("%%d", "%(%%d+%)")) or 0) * 100 +
629 (name
:match(GOLD_AMOUNT
:gsub("%%d", "%(%%d+%)")) or 0) * 10000
632 self
:AppendObjectiveDrop(self
:GetObjective("item", "money"), target
, total
)
638 local container
= nil
640 -- Go through the players inventory and look for a locked item, we're probably looting it.
641 for bag
= 0,NUM_BAG_SLOTS
do
642 for slot
= 1,GetContainerNumSlots(bag
) do
643 local link
= GetContainerItemLink(bag
, slot
)
644 if link
and select(3, GetContainerItemInfo(bag
, slot
)) then
645 if container
== nil then
646 -- Found a locked item and haven't previously assigned to container, assign its name, or false if we fail to parse it.
647 container
= select(3, string.find(link
, "|h%[(.+)%]|h|r")) or false
649 -- Already tried to assign to a container. If there are multiple locked items, we give up.
657 local container_objective
= self
:GetObjective("item", container
)
658 container_objective
.o
.opened
= (container_objective
.o
.opened
or 0) + 1
660 for i
= 1, GetNumLootItems() do
661 local icon
, name
, number, rarity
= GetLootSlotInfo(i
)
662 if name
and number >= 1 then
663 self
:AppendItemObjectiveContainer(self
:GetObjective("item", name
), container
, number)
667 -- No idea where the items came from.
668 local index
, x
, y
= self
:PlayerPosition()
671 for i
= 1, GetNumLootItems() do
672 local icon
, name
, number, rarity
= GetLootSlotInfo(i
)
673 if name
and number >= 1 then
674 self
:AppendItemObjectivePosition(self
:GetObjective("item", name
), name
, index
, x
, y
)
682 if event
== "CHAT_MSG_SYSTEM" then
683 local home_name
= self
:convertPattern(ERR_DEATHBIND_SUCCESS_S
)(arg1
)
686 self
:TextOut(QHText("HOME_CHANGED"))
687 self
:TextOut(QHText("WILL_RESET_PATH"))
689 local home
= QuestHelper_Home
692 QuestHelper_Home
= home
695 home
[1], home
[2], home
[3], home
[4] = self
.i
, self
.x
, self
.y
, home_name
696 self
.defered_graph_reset
= true
701 if event
== "CHAT_MSG_ADDON" then
702 if arg1
== "QHpr" and (arg3
== "PARTY" or arg3
== "WHISPER") and arg4
~= UnitName("player") then
703 self
:HandleRemoteData(arg2
, arg4
)
707 if event
== "PARTY_MEMBERS_CHANGED" then
708 self
:HandlePartyChange()
711 if event
== "QUEST_LOG_UPDATE" or
712 event
== "PLAYER_LEVEL_UP" or
713 event
== "PARTY_MEMBERS_CHANGED" then
714 self
.defered_quest_scan
= true
717 if event
== "QUEST_DETAIL" then
718 if not self
.quest_giver
then self
.quest_giver
= {} end
719 local npc
= UnitName("npc")
721 -- Some NPCs aren't actually creatures, and so their positions might not be marked by PLAYER_TARGET_CHANGED.
722 local index
, x
, y
= self
:UnitPosition("npc")
724 if index
then -- Might not have a position if inside an instance.
725 local npc_objective
= self
:GetObjective("monster", npc
)
726 self
:AppendObjectivePosition(npc_objective
, index
, x
, y
)
727 self
.quest_giver
[GetTitleText()] = npc
732 if event
== "QUEST_COMPLETE" or event
== "QUEST_PROGRESS" then
733 local quest
= GetTitleText()
735 local level
, hash
= self
:GetQuestLevel(quest
)
736 if not level
or level
< 1 then
737 --self:TextOut("Don't know quest level for ".. quest.."!")
740 local q
= self
:GetQuest(quest
, level
, hash
)
746 local unit
= UnitName("npc")
751 -- Some NPCs aren't actually creatures, and so their positions might not be marked by PLAYER_TARGET_CHANGED.
752 local index
, x
, y
= self
:UnitPosition("npc")
753 if index
then -- Might not have a position if inside an instance.
754 local npc_objective
= self
:GetObjective("monster", unit
)
755 self
:AppendObjectivePosition(npc_objective
, index
, x
, y
)
757 elseif not q
.o
.finish
then
758 local index
, x
, y
= self
:PlayerPosition()
759 if index
then -- Might not have a position if inside an instance.
760 self
:AppendObjectivePosition(q
, index
, x
, y
)
766 if event
== "MERCHANT_SHOW" then
767 local npc_name
= UnitName("npc")
769 local npc_objective
= self
:GetObjective("monster", npc_name
)
772 local item_name
= GetMerchantItemInfo(index
)
775 local item_objective
= self
:GetObjective("item", item_name
)
776 if not item_objective
.o
.vendor
then
777 item_objective
.o
.vendor
= {npc_name
}
780 for i
, vendor
in ipairs(item_objective
.o
.vendor
) do
781 if npc_name
== vendor
then
787 table.insert(item_objective
.o
.vendor
, npc_name
)
797 if event
== "TAXIMAP_OPENED" then
801 if event
== "PLAYER_CONTROL_GAINED" then
802 interruptcount
= interruptcount
+ 1
805 if event
== "BAG_UPDATE" then
806 for slot
= 1,GetContainerNumSlots(arg1
) do
807 local link
= GetContainerItemLink(arg1
, slot
)
809 local id
, name
= select(3, string.find(link
, "|Hitem:(%d+):.-|h%[(.-)%]|h"))
811 self
:GetObjective("item", name
).o
.id
= tonumber(id
)
817 if event
== "CHAT_MSG_CHANNEL_NOTICE" and please_donate_enabled
and not please_donate_initted
then
818 please_donate_enabled
= QHNagInit()
819 startup_time
= GetTime()
820 please_donate_initted
= true
825 QH_Timeslice_Increment(GetTime() - tstart
, "event")
828 local map_shown_decay
= 0
829 local delayed_action
= 100
830 --local update_count = 0
833 function QuestHelper
:OnUpdate()
834 local tstart
= GetTime()
836 if not QuestHelper_Loadtime
["onupdate"] then QuestHelper_Loadtime
["onupdate"] = GetTime() end
838 if please_donate_enabled
and startup_time
and startup_time
+ 1 < GetTime() then
839 QuestHelper
:TextOut(QHText("PLEASE_DONATE"))
841 please_donate_enabled
= false
843 QHUpdateNagTick() -- These probably shouldn't be in OnUpdate. Eventually I'll move them somewhere cleaner.
845 if init_cartographer_later
and Cartographer_Waypoints
then -- there has to be a better way to do this
846 init_cartographer_later
= false
847 if QuestHelper_Pref
.cart_wp
then
848 self
:EnableCartographer()
852 if not ontaxi
and UnitOnTaxi("player") then
855 elseif ontaxi
and not UnitOnTaxi("player") then
856 self
:flightEnded(interruptcount
> 1)
858 ontaxi
= UnitOnTaxi("player")
860 -- For now I'm ripping out the update_count code
861 --update_count = update_count - 1
862 --if update_count <= 0 then
864 -- Reset the update count for next time around; this will make sure the body executes every time
865 -- when perf_scale >= 1, and down to 1 in 10 iterations when perf_scale < 1, or when hidden.
866 --update_count = update_count + (QuestHelper_Pref.hide and 10 or 1/QuestHelper_Pref.perf_scale)
868 --if update_count < 0 then
869 -- Make sure the count doesn't go perpetually negative; don't know what will happen if it underflows.
873 if self
.Astrolabe
.WorldMapVisible
then
874 -- We won't trust that the zone returned by Astrolabe is correct until map_shown_decay is 0.
876 elseif map_shown_decay
> 0 then
877 map_shown_decay
= map_shown_decay
- 1
879 --SetMapToCurrentZone() -- not sure why this existed
882 delayed_action
= delayed_action
- 1
883 if delayed_action
<= 0 then
885 self
:HandlePartyChange()
888 local nc
, nz
, nx
, ny
= self
.Astrolabe
:GetCurrentPlayerPosition()
891 if nc
and nc
~= -1 then -- We just want the raw data here, before we've done anything clever.
892 tc
, tx
, ty
= self
.Astrolabe
:GetAbsoluteContinentPosition(nc
, nz
, nx
, ny
)
893 QuestHelper
: Assert(tc
and tx
and ty
) -- is it true? nobody knows! :D
896 if nc
and nc
== self
.c
and map_shown_decay
> 0 and self
.z
> 0 and self
.z
~= nz
then
897 -- There's a chance Astrolable will return the wrong zone if you're messing with the world map, if you can
898 -- be seen in that zone but aren't in it.
899 local nnx
, nny
= self
.Astrolabe
:TranslateWorldMapPosition(nc
, nz
, nx
, ny
, nc
, self
.z
)
900 if nnx
> 0 and nny
> 0 and nnx
< 1 and nny
< 1 then
901 nz
, nx
, ny
= self
.z
, nnx
, nny
905 if nc
and nc
> 0 and nz
== 0 and nc
== self
.c
and self
.z
> 0 then
906 nx
, ny
= self
.Astrolabe
:TranslateWorldMapPosition(nc
, nz
, nx
, ny
, nc
, self
.z
)
907 if nx
and ny
--[[and nx > -0.1 and ny > -0.1 and nx < 1.1 and ny < 1.1]] then -- removing the conditional because I think I can use the data even when it's a little wonky
910 nc
, nz
, nx
, ny
= nil, nil, nil, nil
914 if nc
and nz
> 0 then
915 self
.c
, self
.z
, self
.x
, self
.y
= nc
, nz
, nx
, ny
916 self
.i
= QuestHelper_IndexLookup
[nc
][nz
]
919 self
.collect_c
, self
.collect_x
, self
.collect_y
, self
.collect_rc
, self
.collect_rz
= tc
, tx
, ty
, nc
, nz
921 local level
= UnitLevel("player")
922 if level
>= 58 and self
.player_level
< 58 then
923 self
.defered_graph_reset
= true
925 if level
~= self
.player_level
then
926 self
.defered_quest_scan
= true
928 self
.player_level
= level
930 if self
.defered_quest_scan
and not self
.graph_in_limbo
then
931 self
.defered_quest_scan
= false
935 QH_Timeslice_Toggle("routing", not not self
.c
)
937 self
:PumpCommMessages()
940 QH_Collector_OnUpdate()
942 QH_Timeslice_Increment(GetTime() - tstart
, "onupdate")
947 -- Some or all of these may be nil. c,x,y should be enough for a location - c is the pure continent (currently either 0 or 3 for Azeroth or Outland) and x,y are the coordinates within that continent.
948 -- rc and rz are the continent and zone that Questhelper thinks it's within. For various reasons, this isn't perfect. TODO: Base it off the map zone name identifiers instead of the map itself?
949 function QuestHelper
:RetrieveRawLocation()
950 return self
.collect_c
, self
.collect_x
, self
.collect_y
, self
.collect_rc
, self
.collect_rz
953 QuestHelper
:RegisterEvent("VARIABLES_LOADED")
954 QuestHelper
:SetScript("OnEvent", QuestHelper
.OnEvent
)