1 assert(nil) -- component oblsolete
2 local registerFeature
= function()
7 feature
.Description
= "A npc dialog test"
15 {Name
="Zone",Type
="Region"},
16 {Name
="Npcs",Type
="Table"},
17 {Name
="Actions",Type
="Table"},
18 {Name
="Name", Type
="String", MaxNumChar
="32"}
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
42 if dialog
.Actions
[i
].Action
== "npc_say"
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
)
54 feature
.getTextParam
= function(param
)
55 debugInfo("param:: "..param
)
56 local pos
=string.find(param
,"\n")
61 return string.sub(param
,pos
+1)
65 feature
.setTextParam
= function(param
,value
)
66 local pos
=string.find(param
,"\n")
71 local st
= string.sub(param
,1,pos
)
77 feature
.removeDialog
= function(dialog
)
78 local max = table.getn(dialog
.Actions
)
80 if dialog
.Actions
[i
].Action
== "npc_say"
82 r2
.unregisterText(dialog
.Actions
[i
].Parameters
)
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"
95 parameters
= getRtId(context
,parameters
)
96 debugInfo("npc_say:: "..parameters
)
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
)
107 feature
.loop
= function(name
)
108 action
= Actions
.createAction("begin_state",name
)
112 feature
.Translator
= function(context
)
113 local actions
= context
.Feature
.Actions
114 local max = table.getn(actions
)
115 local switch_action
= r2
.newComponent("RtNpcEventHandlerAction")
118 --endAction = feature.loop("init_"..context.Feature.Name)
119 endAction
= feature
.loop("dialog")
120 switch_action
.Action
="switch_actions"
121 switch_action
.Parameters
= "v0"
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
)
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)
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
)
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")
176 endAction
= feature
.loop("init_"..context
.Feature
.Name
)
178 switch_action
.Action
="switch_actions"
179 switch_action
.Parameters
= "v0"
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
)
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
)
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
)
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
)
225 event
= Actions
.createEvent("start_of_state","dialog")
226 table.insert(event
.ActionsId
,switch_action
.Id
)
227 table.insert(context
.RtAct
.Events
,event
)
236 r2
.Features
["Piece"] = registerFeature()