Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / common / data_common / r2 / r2_piece.lua
blob50ba9b7b4a63f23ddd33143fa977e26c5edb99df
1 assert(nil) -- component oblsolete
2 local registerFeature = function()
3 local feature = {}
4 feature.maxId=1
5 feature.Name = "Piece"
7 feature.Description = "A npc dialog test"
9 feature.Components=
12 Name="Piece",
13 Prop =
15 {Name="Zone",Type="Region"},
16 {Name="Npcs",Type="Table"},
17 {Name="Actions",Type="Table"},
18 {Name="Name", Type="String", MaxNumChar="32"}
22 Name="PieceEntry",
23 Prop=
25 {Name="Who",Type="String"},
26 {Name="Action",Type="String"},
27 {Name="Parameters",Type="String"},
28 {Name="Time",Type="String"}
34 feature.createDialog = function(dialog,x,y,r)
35 --local dialog = r2.newComponent("Piece")
36 local nbNpc = table.getn(dialog.Npcs)
37 local pas = (2 * math.pi) / nbNpc
39 local max = table.getn(dialog.Actions)
40 --adding the texts to the TextManager
41 for i=1,max do
42 if dialog.Actions[i].Action == "npc_say"
43 then
44 local textParam = feature.getTextParam(dialog.Actions[i].Parameters)
45 debugInfo("Text param: "..textParam)
46 local entry=r2.registerText(textParam)
47 dialog.Actions[i].Parameters = entry.InstanceId
48 debugInfo("New params: "..dialog.Actions[i].Parameters)
49 end
50 end
51 return dialog
52 end
54 feature.getTextParam = function(param)
55 debugInfo("param:: "..param)
56 local pos=string.find(param,"\n")
57 if pos==nil
58 then
59 return param
60 else
61 return string.sub(param,pos+1)
62 end
63 end
65 feature.setTextParam = function(param,value)
66 local pos=string.find(param,"\n")
67 if pos==nil
68 then
69 return param
70 else
71 local st = string.sub(param,1,pos)
72 st = st..value
73 return st
74 end
75 end
77 feature.removeDialog = function(dialog)
78 local max = table.getn(dialog.Actions)
79 for i=1,max do
80 if dialog.Actions[i].Action == "npc_say"
81 then
82 r2.unregisterText(dialog.Actions[i].Parameters)
83 end
84 end
85 end
87 feature.TranslateEntry = function(context)
88 local entry = context.Component
89 local multi_actions = r2.newComponent("RtNpcEventHandlerAction")
90 multi_actions.Action = "multi_actions"
91 local parameters = entry.Parameters
92 local getRtId = r2.Features["TextManager"].getRtId
93 if entry.Action == "npc_say"
94 then
95 parameters = getRtId(context,parameters)
96 debugInfo("npc_say:: "..parameters)
97 end
98 local action = Actions.createAction(entry.Action,parameters,entry.Who)
99 table.insert(multi_actions.Children,action)
102 action = Actions.createAction("set_timer_t0",entry.Time)
103 table.insert(multi_actions.Children,action)
104 return multi_actions
107 feature.loop = function(name)
108 action = Actions.createAction("begin_state",name)
109 return action
112 feature.Translator = function(context)
113 local actions = context.Feature.Actions
114 local max = table.getn(actions)
115 local switch_action = r2.newComponent("RtNpcEventHandlerAction")
116 local endAction
117 local action
118 --endAction = feature.loop("init_"..context.Feature.Name)
119 endAction = feature.loop("dialog")
120 switch_action.Action="switch_actions"
121 switch_action.Parameters = "v0"
124 for i=1,max do
125 context.Component = actions[i]
126 local tmpAction = feature.TranslateEntry(context)
127 table.insert(switch_action.Children,tmpAction)
129 table.insert(switch_action.Children,endAction)
130 table.insert(context.RtAct.Actions,switch_action)
133 --states creation
134 local aiState = r2.newComponent("RtAiState")
135 aiState.Name = "dialog"
136 table.insert(context.RtAct.AiStates, aiState)
137 --aiState = r2.newComponent("RtAiState")
138 --aiState.Name = "init_"..context.Feature.Name
139 --table.insert(context.RtAct.AiStates, aiState)
142 --next action
143 local event
144 event = Actions.createEvent("timer_t0_triggered","dialog")
145 table.insert(context.RtAct.Events,event)
146 local multi_action = r2.newComponent("RtNpcEventHandlerAction")
147 multi_action.Action = "multi_actions"
148 table.insert(multi_action.Children,switch_action)
149 action = Actions.createAction("modify_variable","v0 + 1")
150 table.insert(multi_action.Children,action)
151 table.insert(context.RtAct.Actions,multi_action)
152 table.insert(event.ActionsId,multi_action.Id)
155 --action
156 event = Actions.createEvent("start_of_state","dialog")
157 local m_action = r2.newComponent("RtNpcEventHandlerAction")
158 m_action.Action = "multi_actions"
159 table.insert(context.RtAct.Actions,m_action)
160 action = Actions.createAction("modify_variable","v0 = 0")
161 table.insert(m_action.Children,action)
162 action = Actions.createAction("set_timer_t0","1")
163 table.insert(m_action.Children,action)
164 table.insert(event.ActionsId,m_action.Id)
165 table.insert(context.RtAct.Events,event)
170 feature.Translator2 = function(context)
171 local actions = context.Feature.Actions
172 local max = table.getn(actions)
173 local switch_action = r2.newComponent("RtNpcEventHandlerAction")
174 local endAction
176 endAction = feature.loop("init_"..context.Feature.Name)
178 switch_action.Action="switch_actions"
179 switch_action.Parameters = "v0"
182 for i=1,max do
183 context.Component = actions[i]
184 local tmpAction = feature.TranslateEntry(context)
185 table.insert(switch_action.Children,tmpAction)
187 table.insert(switch_action.Children,endAction)
188 table.insert(context.RtAct.Actions,switch_action)
191 --states creation
192 local aiState = r2.newComponent("RtAiState")
193 aiState.Name = "dialog"
194 table.insert(context.RtAct.AiStates, aiState)
195 aiState = r2.newComponent("RtAiState")
196 aiState.Name = "init_"..context.Feature.Name
197 table.insert(context.RtAct.AiStates, aiState)
199 --next action
200 local event
201 event = Actions.createEvent("timer_t0_triggered","dialog")
202 table.insert(context.RtAct.Events,event)
203 local multi_action = r2.newComponent("RtNpcEventHandlerAction")
204 multi_action.Action = "multi_actions"
205 local action = Actions.createAction("modify_variable","v0 + 1")
206 table.insert(multi_action.Children,action)
207 action = Actions.createAction("begin_state","dialog")
208 table.insert(multi_action.Children,action)
209 table.insert(context.RtAct.Actions,multi_action)
210 table.insert(event.ActionsId,multi_action.Id)
212 --dialog start
213 event = Actions.createEvent("start_of_state","init_"..context.Feature.Name)
214 local m_action = r2.newComponent("RtNpcEventHandlerAction")
215 m_action.Action = "multi_actions"
216 action = Actions.createAction("modify_variable","v0 = 0")
217 table.insert(m_action.Children,action)
218 action = Actions.createAction("begin_state","dialog")
219 table.insert(m_action.Children,action)
220 table.insert(context.RtAct.Actions,m_action)
221 table.insert(event.ActionsId,m_action.Id)
222 table.insert(context.RtAct.Events,event)
224 --action
225 event = Actions.createEvent("start_of_state","dialog")
226 table.insert(event.ActionsId,switch_action.Id)
227 table.insert(context.RtAct.Events,event)
233 return feature
236 r2.Features["Piece"] = registerFeature()