update changes
[QuestHelper.git] / collect_warp.lua
blobd433c2634ef92e8c1012dd9835549d46dc322ff8
1 QuestHelper_File["collect_warp.lua"] = "Development Version"
2 QuestHelper_Loadtime["collect_warp.lua"] = GetTime()
4 local debug_output = false
5 if QuestHelper_File["collect_warp.lua"] == "Development Version" then debug_output = true end
7 local QHCW
9 local GetLoc
10 local Merger
11 local RawLocation
13 local lastloc_bolus
14 local lastloc_table
16 local function OnUpdate()
17 local bolus, tab = GetLoc(), {RawLocation()}
18 if lastloc_table and lastloc_table[2] and tab[2] and lastloc_table[3] and tab[3] and not lastloc_table[1] and not tab[1] then
19 local leapy = false
20 if lastloc_table[2] ~= tab[2] or lastloc_table[3] ~= tab[3] then
21 leapy = true
22 else
23 local dx, dy = lastloc_table[4] - tab[4], lastloc_table[5] - tab[5]
24 dx, dy = dx * dx, dy * dy
25 if dx + dy > 25 * 25 then -- Blink is 20, so we need to do more than that.
26 leapy = true
27 end
28 end
30 if leapy then
31 Merger.Add(QHCW, lastloc_bolus .. bolus)
32 if debug_output then QuestHelper:TextOut("Warpy!") end
33 end
34 end
36 lastloc_bolus = bolus
37 lastloc_table = tab
38 end
40 function QH_Collect_Warp_Init(QHCData, API)
41 if not QHCData.warp then QHCData.warp = {} end
42 QHCW = QHCData.warp
44 API.Registrar_OnUpdateHook(OnUpdate)
46 GetLoc = API.Callback_LocationBolusCurrent
47 QuestHelper: Assert(GetLoc)
49 RawLocation = API.Callback_Location_Raw
50 QuestHelper: Assert(RawLocation)
52 Merger = API.Utility_Merger
53 QuestHelper: Assert(Merger)
54 end