Automated update from: http://smariot.hopto.org/translate
[QuestHelper.git] / teleport.lua
blob0c550e3478747b4f89d405110189c4bb57cbf117
1 QuestHelper_File["teleport.lua"] = "Development Version"
2 QuestHelper_Loadtime["teleport.lua"] = GetTime()
4 function QuestHelper:CreateTeleportInfo()
5 local info = self:CreateTable()
6 info.node = self:CreateTable()
7 info.reag = self:CreateTable()
8 return info
9 end
11 function QuestHelper:ReleaseTeleportInfo(info)
12 for _, data in pairs(info.node) do
13 self:ReleaseTable(data)
14 end
16 self:ReleaseTable(info.node)
17 self:ReleaseTable(info.reag)
18 self:ReleaseTable(info)
19 end
21 function QuestHelper:TeleportInfoClear(info)
22 for node, data in pairs(info.node) do
23 self:ReleaseTable(data)
24 info.node[node] = nil
25 end
27 for id in pairs(info.reag) do
28 info.reag[id] = nil
29 end
30 end
32 function QuestHelper:SetTeleportInfoTarget(info,
33 node, -- The world graph node this will take us to.
34 start, -- The last time this spell was used.
35 duration, -- How long the spell cooldown is.
36 cast, -- How long does the spell take to cast.
37 reagent_id) -- What reagent is consumed by using the spell (can be nil)
38 local data = info.node[node]
39 if not data then data = self:CreateTable() info.node[node] = data end
41 data[1], data[2], data[3], data[4] = start, duration, cast, reagent_id
42 end
44 function QuestHelper:SetTeleportInfoReagent(info, reagent_id, count)
45 if count > 0 then
46 info.reag[reagent_id] = count
47 else
48 info.reag[reagent_id] = nil
49 end
50 end
52 function QuestHelper:TeleportInfoUseNode(info, node, time_delta)
53 local data = info.node[node]
54 if data then
55 self:TextOut("Used "..(node.name or "unnamed node").." in path.")
57 data[1] = GetTime()+time_delta
58 if data[3] then
59 local count = info.reag[data[3]] or 0
60 count = count - 1
61 if count > 1 then
62 info.reag[data[4]] = count
63 else
64 info.reag[data[4]] = nil
65 end
66 end
67 end
68 end
70 function QuestHelper:TeleportInfoTransfer(original, dest)
71 for key in pairs(dest.node) do
72 if not original.node[key] then
73 self:ReleaseTable(dest.node[key])
74 dest.node[key] = nil
75 end
76 end
78 for key, data in pairs(original.node) do
79 local data2 = dest.node[key]
80 if not data2 then
81 data2 = self:CreateTable()
82 dest.node[key] = data2
83 end
84 data2[1], data2[2], data2[3], data2[4] = data[1], data[2], data[3], data[4]
85 end
87 for key in pairs(dest.reag) do
88 if not original.reag[key] then
89 dest.reag[key] = nil
90 end
91 end
93 for key, value in pairs(original.reag) do
94 dest.reag[key] = value
95 end
96 end
98 function QuestHelper:TeleportInfoAddGraphPoints(info, graph, end_list, time_delta)
99 for node, data in pairs(info.node) do
100 if data[1]+data[2] >= time_delta+GetTime() and (not data[4] or (data[4] and info.reag[data[4]])) then
101 self:TextOut("Considering "..(node.name or "unnamed node").." for use in pathing.")
102 graph:AddStartNode(node, data[3], end_list)
107 QuestHelper.teleport_info = QuestHelper:CreateTeleportInfo()