1
|
|
|
from intelligine.core.exceptions import NearNothingFound |
2
|
|
|
from intelligine.shorcut.brain import get_brain_part |
3
|
|
|
from synergine.core.exceptions import NotConcernedEvent |
4
|
|
|
from intelligine.synergy.event.src.NearEvent import NearEvent |
5
|
|
|
from synergine_xyz.mechanism.AroundMechanism import AroundMechanism |
6
|
|
|
from intelligine.cst import TRANSPORTABLE, CANT_CARRY_STILL, COL_TRANSPORTER_NOT_CARRYING, BRAIN_SCHEMA, BRAIN_PART_TAKE |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
class TakeableEvent(NearEvent): |
10
|
|
|
|
11
|
|
|
_mechanism = AroundMechanism |
12
|
|
|
PARAM_TAKE = 'take' |
13
|
|
|
_concern = COL_TRANSPORTER_NOT_CARRYING |
14
|
|
|
_near_name = 'objects_ids_transportable' |
15
|
|
|
_near_map = lambda self, near_object_id, context: context.metas.states.have(near_object_id, TRANSPORTABLE) |
16
|
|
|
|
17
|
|
|
def _prepare(self, object_id, context, parameters={}): |
18
|
|
|
if not self._can_carry(object_id, context): |
19
|
|
|
raise NotConcernedEvent() |
20
|
|
|
|
21
|
|
|
try: |
22
|
|
|
self.map(context, parameters, stop_at_first=True) |
23
|
|
|
except NearNothingFound: |
24
|
|
|
raise NotConcernedEvent() |
25
|
|
|
|
26
|
|
|
if not self._object_can_take(object_id, context, parameters[self._near_name][0]): |
27
|
|
|
raise NotConcernedEvent() |
28
|
|
|
|
29
|
|
|
parameters[self.PARAM_TAKE] = parameters[self._near_name][0] |
30
|
|
|
return parameters |
31
|
|
|
|
32
|
|
|
@staticmethod |
33
|
|
|
def _can_carry(object_id, context): |
34
|
|
|
return not context.metas.value.get(CANT_CARRY_STILL, object_id, allow_empty=True) |
35
|
|
|
|
36
|
|
|
@classmethod |
37
|
|
|
def _object_can_take(cls, object_id, context, object_to_take_id): |
38
|
|
|
object_take_brain_part = get_brain_part(context, object_id, BRAIN_PART_TAKE) |
39
|
|
|
return object_take_brain_part.can_take(context, object_id, object_to_take_id) |
40
|
|
|
|