disable the flight stuff for now, we'll fix it after thanksgiving
[QuestHelper.git] / collect_flight.lua
blobe41ae60b7a433ed10cd5bd8ecf47cb3fe1f439ff
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
6 local QHCFM
7 local QHCFT
9 local function GetRoute(currentname, endnode)
10 local path = currentname .. "@@" .. TaxiNodeName(endnode)
12 local route = ""
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))
16 end
18 return path, route
19 end
21 local function GetCurrentname()
22 for i = 1, NumTaxiNodes() do if TaxiNodeGetType(i) == "CURRENT" then return TaxiNodeName(i) end end
23 end
25 local path, route
26 local start_time
27 local phase = "IDLE"
29 --[[
30 local real_TakeTaxiNode = TakeTaxiNode
31 TakeTaxiNode = function(id)
32 path, route = GetRoute(GetCurrentname(), id)
34 phase = "PENDING"
36 start_time = GetTime()
38 real_TakeTaxiNode(id)
39 end
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
59 end
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
65 end
66 end
67 end
69 local function OnUpdate()
70 if UnitOnTaxi("player") then
71 if phase == "PENDING" then
72 start_time = GetTime()
73 phase = "FLYING"
74 end
75 else
76 if phase == "PENDING" then
77 if GetTime() > start_time + 5 then -- something has gone wrong, abort
78 phase = "IDLE"
79 path, route, start_time = nil, nil, nil
80 end
81 elseif phase == "FLYING" then
82 -- yaay
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
85 phase = "IDLE"
86 path, route, start_time = nil, nil, nil
87 end
88 end
89 end
91 function QH_Collect_Flight_Init(QHCData, API)
92 --[[
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)