1 QuestHelper_File
["collect_flight.lua"] = "Development Version"
3 local debug_output
= false
4 if QuestHelper_File
["collect_flight.lua"] == "Development Version" then debug_output
= true end
9 local function GetRoute(currentname
, endnode
)
10 local path
= currentname
.. "@@" .. TaxiNodeName(endnode
)
13 for j
= 1, GetNumRoutes(endnode
) - 1 do
14 if #route
> 0 then route
= route
.. "@@" end
15 route
= route
.. string.format("%f:%f", TaxiGetDestX(endnode
, j
), TaxiGetDestY(endnode
, j
))
21 local function GetCurrentname()
22 for i
= 1, NumTaxiNodes() do if TaxiNodeGetType(i
) == "CURRENT" then return TaxiNodeName(i
) end end
30 local real_TakeTaxiNode = TakeTaxiNode
31 TakeTaxiNode = function(id)
32 path, route = GetRoute(GetCurrentname(), id)
36 start_time = GetTime()
42 local function TaximapOpened()
43 -- Figure out who we have targeted and what our location name is
44 local currentname
= GetCurrentname()
45 if not currentname
then return end -- must not actually have opened the map
47 for i
= 1, NumTaxiNodes() do
48 local name
, type = TaxiNodeName(i
), TaxiNodeGetType(i
)
49 if not QHCFM
[name
] then QHCFM
[name
] = {} end
50 QHCFM
[name
].x
, QHCFM
[name
].y
= TaxiNodePosition(i
)
51 if type == "CURRENT" then
52 local guid
= UnitGUID("target")
53 QuestHelper
: Assert(#guid
== 18, "guid len " .. guid
) -- 64 bits, plus the 0x prefix
54 QuestHelper
: Assert(guid
:sub(1, 2) == "0x", "guid 0x-prefix " .. guid
)
55 QuestHelper
: Assert(guid
:sub(5, 5) == "3" or guid
:sub(5, 5) == "5", "guid 3-prefix " .. guid
) -- It *shouldn't* be a player or a pet by the time we've gotten here. If so, something's gone wrong.
56 local creatureid
= guid
:sub(9, 18) -- here's our actual identifier
58 QHCFM
[name
].master
= creatureid
61 if type ~= "CURRENT" then
62 local path
, route
= GetRoute(currentname
, i
)
63 if not QHCFT
[path
] then QHCFT
[path
] = {} end
64 if not QHCFT
[path
][route
] then QHCFT
[path
][route
] = true end
69 local function OnUpdate()
70 if UnitOnTaxi("player") then
71 if phase
== "PENDING" then
72 start_time
= GetTime()
76 if phase
== "PENDING" then
77 if GetTime() > start_time
+ 5 then -- something has gone wrong, abort
79 path
, route
, start_time
= nil, nil, nil
81 elseif phase
== "FLYING" then
83 QHCFT
[path
][route
] = (type(QHCFT
[path
][route
]) == "number" and QHCFT
[path
][route
] or 0) + (GetTime() - start_time
)
84 QHCFT
[path
][route
.. "##count"] = (QHCFT
[path
][route
.. "##count"] or 0) + 1
86 path
, route
, start_time
= nil, nil, nil
91 function QH_Collect_Flight_Init(QHCData
, API
)
93 if not QHCData.flight_master then QHCData.flight_master = {} end
94 if not QHCData.flight_times then QHCData.flight_times = {} end
95 QHCFM, QHCFT = QHCData.flight_master, QHCData.flight_times
97 API.Registrar_EventHook("TAXIMAP_OPENED", TaximapOpened)
99 API.Registrar_OnUpdateHook(OnUpdate)