Added rightclick to map button, desaturated it when QuestHelper is hidden, and change...
[QuestHelper.git] / teleport.lua
bloba07550aa61674e6d5962f2fa41d8d80bab4b1eb4
1 function QuestHelper:CreateTeleportInfo()
2 local info = self:CreateTable()
3 info.node = self:CreateTable()
4 info.reag = self:CreateTable()
5 return info
6 end
8 function QuestHelper:ReleaseTeleportInfo(info)
9 for _, data in pairs(info.node) do
10 self:ReleaseTable(data)
11 end
13 self:ReleaseTable(info.node)
14 self:ReleaseTable(info.reag)
15 self:ReleaseTable(info)
16 end
18 function QuestHelper:TeleportInfoClear(info)
19 for node, data in pairs(info.node) do
20 self:ReleaseTable(data)
21 info.node[node] = nil
22 end
24 for id in pairs(info.reag) do
25 info.reag[id] = nil
26 end
27 end
29 function QuestHelper:SetTeleportInfoTarget(info,
30 node, -- The world graph node this will take us to.
31 start, -- The last time this spell was used.
32 duration, -- How long the spell cooldown is.
33 cast, -- How long does the spell take to cast.
34 reagent_id) -- What reagent is consumed by using the spell (can be nil)
35 local data = info.node[node]
36 if not data then data = self:CreateTable() info.node[node] = data end
38 data[1], data[2], data[3], data[4] = start, duration, cast, reagent_id
39 end
41 function QuestHelper:SetTeleportInfoReagent(info, reagent_id, count)
42 if count > 0 then
43 info.reag[reagent_id] = count
44 else
45 info.reag[reagent_id] = nil
46 end
47 end
49 function QuestHelper:TeleportInfoUseNode(info, node, time_delta)
50 local data = info.node[node]
51 if data then
52 self:TextOut("Used "..(node.name or "unnamed node").." in path.")
54 data[1] = GetTime()+time_delta
55 if data[3] then
56 local count = info.reag[data[3]] or 0
57 count = count - 1
58 if count > 1 then
59 info.reag[data[4]] = count
60 else
61 info.reag[data[4]] = nil
62 end
63 end
64 end
65 end
67 function QuestHelper:TeleportInfoTransfer(original, dest)
68 for key in pairs(dest.node) do
69 if not original.node[key] then
70 self:ReleaseTable(dest.node[key])
71 dest.node[key] = nil
72 end
73 end
75 for key, data in pairs(original.node) do
76 local data2 = dest.node[key]
77 if not data2 then
78 data2 = self:CreateTable()
79 dest.node[key] = data2
80 end
81 data2[1], data2[2], data2[3], data2[4] = data[1], data[2], data[3], data[4]
82 end
84 for key in pairs(dest.reag) do
85 if not original.reag[key] then
86 dest.reag[key] = nil
87 end
88 end
90 for key, value in pairs(original.reag) do
91 dest.reag[key] = value
92 end
93 end
95 function QuestHelper:TeleportInfoAddGraphPoints(info, graph, end_list, time_delta)
96 for node, data in pairs(info.node) do
97 if data[1]+data[2] >= time_delta+GetTime() and (not data[4] or (data[4] and info.reag[data[4]])) then
98 self:TextOut("Considering "..(node.name or "unnamed node").." for use in pathing.")
99 graph:AddStartNode(node, data[3], end_list)
104 QuestHelper.teleport_info = QuestHelper:CreateTeleportInfo()