|
@@ -1,10 +1,8 @@
|
1
|
1
|
from synergine.synergy.event.Action import Action
|
2
|
2
|
from intelligine.synergy.event.move.MoveEvent import MoveEvent
|
3
|
3
|
from synergine.synergy.event.exception.ActionAborted import ActionAborted
|
4
|
|
-from xyzworld.cst import POSITION
|
5
|
|
-from intelligine.cst import BRAIN_PART_MOVE, BRAIN_SCHEMA
|
|
4
|
+from intelligine.cst import BRAIN_PART_MOVE
|
6
|
5
|
from xyzworld.cst import BLOCKED_SINCE
|
7
|
|
-from intelligine.synergy.event.move.direction import get_position_with_direction_decal
|
8
|
6
|
|
9
|
7
|
|
10
|
8
|
class MoveAction(Action):
|
|
@@ -17,40 +15,22 @@ class MoveAction(Action):
|
17
|
15
|
self._move_to_direction = None
|
18
|
16
|
|
19
|
17
|
def prepare(self, context):
|
20
|
|
- object_point = context.metas.value.get(POSITION, self._object_id)
|
21
|
|
- direction = self._get_prepared_direction(context)
|
22
|
|
- self._set_prepared_direction(context, object_point, direction)
|
23
|
|
-
|
24
|
|
- def _get_prepared_direction(self, context):
|
25
|
|
- object_brain_schema = context.metas.value.get(BRAIN_SCHEMA, self._object_id)
|
26
|
|
- object_move_brain_part = object_brain_schema[BRAIN_PART_MOVE]
|
27
|
|
- return object_move_brain_part.get_direction(context, self._object_id)
|
28
|
|
-
|
29
|
|
- def _set_prepared_direction(self, context, object_point, direction):
|
30
|
|
- move_to_point = get_position_with_direction_decal(direction, object_point)
|
31
|
|
- if self._direction_point_is_possible(context, move_to_point):
|
32
|
|
- self._move_to_point = move_to_point
|
33
|
|
- self._move_to_direction = direction
|
34
|
|
- else:
|
35
|
|
- # TODO: mettre self._dont_move = True ?
|
36
|
|
- pass
|
37
|
|
-
|
38
|
|
- @staticmethod
|
39
|
|
- def _direction_point_is_possible(context, direction_point):
|
40
|
|
- return context.position_is_penetrable(direction_point)
|
|
18
|
+ # TODO: C'est event qui doit tout preparer. Action::prepare pourra meme disparaitre ?
|
|
19
|
+ pass
|
41
|
20
|
|
42
|
21
|
def run(self, obj, context, synergy_manager):
|
43
|
22
|
try:
|
44
|
23
|
self._apply_move(obj, context)
|
45
|
24
|
except ActionAborted:
|
|
25
|
+ # TODO: Dans l'obj ces lignes
|
46
|
26
|
blocked_since = context.metas.value.get(BLOCKED_SINCE, self._object_id, allow_empty=True, empty_value=0)
|
47
|
|
- context.metas.value.set(BLOCKED_SINCE, self._object_id, blocked_since+1)
|
|
27
|
+ context.metas.value.set(BLOCKED_SINCE, obj.get_id(), blocked_since+1)
|
48
|
28
|
|
49
|
29
|
def _apply_move(self, obj, context):
|
50
|
30
|
# TODO: il ne faut pas choisir une direction 14.
|
51
|
|
- if self._move_to_point is None or self._move_to_direction == 14:
|
|
31
|
+ if MoveEvent.PARAM_DIRECTION not in self._parameters or self._parameters[MoveEvent.PARAM_DIRECTION] == 14:
|
52
|
32
|
raise ActionAborted()
|
53
|
33
|
|
54
|
|
- obj.set_position(self._move_to_point)
|
55
|
|
- obj.set_previous_direction(self._move_to_direction)
|
|
34
|
+ obj.set_position(self._parameters[MoveEvent.PARAM_POSITION])
|
|
35
|
+ obj.set_previous_direction(self._parameters[MoveEvent.PARAM_DIRECTION])
|
56
|
36
|
obj.get_brain().get_part(BRAIN_PART_MOVE).done(obj, context)
|