|
@@ -6,31 +6,22 @@ from synergine.synergy.event.exception.ActionAborted import ActionAborted
|
6
|
6
|
|
7
|
7
|
|
8
|
8
|
class TakeableAction(Action):
|
9
|
|
- """
|
10
|
|
- TODO: Prendre le premier prenable, interrompre la recherche si trouve
|
11
|
|
- si au run de l'action objet non prenable, tant pis. ActionAborted.
|
12
|
|
- """
|
|
9
|
+
|
13
|
10
|
_listen = TakeableEvent
|
14
|
11
|
_depend = [MoveAction]
|
15
|
12
|
|
16
|
13
|
def __init__(self, object_id, parameters):
|
17
|
14
|
super().__init__(object_id, parameters)
|
18
|
15
|
|
19
|
|
- def prepare(self, context):
|
20
|
|
- # TODO: C l'event qui doit preparer les donnees
|
21
|
|
- pass
|
22
|
|
-
|
23
|
16
|
def run(self, obj, context, synergy_manager):
|
24
|
17
|
obj_id_transportable = self._parameters[TakeableEvent.PARAM_TAKE]
|
25
|
18
|
obj_transportable = synergy_manager.get_map().get_object(obj_id_transportable)
|
26
|
|
- if obj_transportable.is_carried(): # TODO: is_takable
|
|
19
|
+
|
|
20
|
+ if not obj_transportable.is_takable():
|
27
|
21
|
raise ActionAborted()
|
28
|
|
- try:
|
29
|
|
- obj_carried = obj_transportable.get_what_carry()
|
30
|
|
- obj_carried.set_carried_by(obj)
|
31
|
|
- obj.carry(obj_carried)
|
32
|
|
- context.metas.value.set(CANT_PUT_STILL, obj.get_id(), 5)
|
33
|
|
- obj.get_brain().get_part(BRAIN_PART_TAKE).done(obj, obj_carried, context)
|
34
|
|
- except ValueError: # Une NotCarriableError serais pus approprie
|
35
|
|
- # TODO: tmp? Si on as pas pu le porter c'est qu'il vient d'etre porte par une autre.
|
36
|
|
- pass
|
|
22
|
+
|
|
23
|
+ obj_carried = obj_transportable.get_what_carry()
|
|
24
|
+ obj_carried.set_carried_by(obj)
|
|
25
|
+ obj.carry(obj_carried)
|
|
26
|
+ context.metas.value.set(CANT_PUT_STILL, obj.get_id(), 5)
|
|
27
|
+ obj.get_brain().get_part(BRAIN_PART_TAKE).done(obj, obj_carried, context)
|