|
@@ -170,54 +170,51 @@ class MoveToBehaviour(SubjectBehaviour):
|
170
|
170
|
self._duration = float(self.config.resolve('game.move.walk_ref_time'))
|
171
|
171
|
|
172
|
172
|
def run(self, data):
|
173
|
|
- # TODO: on fait vraiment rien ici ? Note: meme si il n'y a pas de new_path, l'action doit s'effectuer
|
174
|
|
- # du moment qu'il y a une intention de move
|
175
|
173
|
move_to_data = data[self.move_to_mechanism]
|
176
|
174
|
if move_to_data:
|
177
|
175
|
|
178
|
|
- if time.time() - move_to_data['last_intention_time'] >= self._duration:
|
|
176
|
+ if self._can_move_to_next_step(move_to_data):
|
179
|
177
|
move_to_data['reach_next'] = True
|
180
|
|
- elif move_to_data['just_reach'] or move_to_data['initial']:
|
181
|
|
- move_to_data['reach_next'] = False
|
182
|
|
- else:
|
183
|
|
- return False
|
|
178
|
+ return move_to_data
|
184
|
179
|
|
185
|
|
- return move_to_data
|
|
180
|
+ if self._is_fresh_new_step(move_to_data):
|
|
181
|
+ move_to_data['reach_next'] = False
|
|
182
|
+ return move_to_data
|
186
|
183
|
|
187
|
184
|
return False
|
188
|
185
|
|
189
|
|
- def action(self, data) -> [Event]:
|
190
|
|
- # TODO: effectuer un move vers une nouvelle position ou faire progresser "l'entre-deux"
|
191
|
|
- new_path = data['new_path']
|
192
|
|
- try:
|
193
|
|
- # TODO: MoveToIntention doit être configurable
|
194
|
|
- move = self.subject.intentions.get(MoveToIntention)
|
195
|
|
- move = typing.cast(MoveToIntention, move)
|
196
|
|
-
|
197
|
|
- if new_path:
|
198
|
|
- move.path = new_path
|
199
|
|
- move.path_progression = -1
|
|
186
|
+ def _can_move_to_next_step(self, move_to_data: dict) -> bool:
|
|
187
|
+ return time.time() - move_to_data['last_intention_time'] >= self._duration
|
200
|
188
|
|
201
|
|
- previous_position = self.subject.position
|
202
|
|
- new_position = move.path[move.path_progression + 1]
|
|
189
|
+ def _is_fresh_new_step(self, move_to_data: dict) -> bool:
|
|
190
|
+ return move_to_data['just_reach'] or move_to_data['initial']
|
203
|
191
|
|
204
|
|
- if data['reach_next']:
|
205
|
|
- # TODO: fin de path
|
206
|
|
- move.path_progression += 1
|
207
|
|
- self.subject.position = new_position
|
208
|
|
- move.last_intention_time = time.time()
|
209
|
|
- move.just_reach = True
|
210
|
|
- event = FinishMoveEvent(self.subject.id, previous_position, new_position)
|
211
|
|
- else:
|
212
|
|
- move.just_reach = False
|
213
|
|
- event = StartMoveEvent(self.subject.id, previous_position, new_position)
|
|
192
|
+ def action(self, data) -> [Event]:
|
|
193
|
+ new_path = data['new_path']
|
|
194
|
+ # TODO: MoveToIntention doit être configurable
|
|
195
|
+ move = self.subject.intentions.get(MoveToIntention)
|
|
196
|
+ move = typing.cast(MoveToIntention, move)
|
214
|
197
|
|
215
|
|
- move.initial = False
|
216
|
|
- # Note: Need to explicitly set to update shared data
|
217
|
|
- self.subject.intentions.set(move)
|
|
198
|
+ if new_path:
|
|
199
|
+ move.path = new_path
|
|
200
|
+ move.path_progression = -1
|
218
|
201
|
|
219
|
|
- return [event]
|
|
202
|
+ previous_position = self.subject.position
|
|
203
|
+ new_position = move.path[move.path_progression + 1]
|
220
|
204
|
|
221
|
|
- except KeyError:
|
222
|
|
- # TODO: log ? Il devrait y avoir un move puisque data du run/mechanism !
|
223
|
|
- pass
|
|
205
|
+ if data['reach_next']:
|
|
206
|
+ # TODO: fin de path
|
|
207
|
+ move.path_progression += 1
|
|
208
|
+ self.subject.position = new_position
|
|
209
|
+ move.last_intention_time = time.time()
|
|
210
|
+ move.just_reach = True
|
|
211
|
+ event = FinishMoveEvent(self.subject.id, previous_position, new_position)
|
|
212
|
+ else:
|
|
213
|
+ move.just_reach = False
|
|
214
|
+ event = StartMoveEvent(self.subject.id, previous_position, new_position)
|
|
215
|
+
|
|
216
|
+ move.initial = False
|
|
217
|
+ # Note: Need to explicitly set to update shared data
|
|
218
|
+ self.subject.intentions.set(move)
|
|
219
|
+
|
|
220
|
+ return [event]
|