TakeableAction   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
dl 0
loc 21
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 2 1
A run() 0 13 2
1
from intelligine.synergy.event.move.MoveAction import MoveAction
2
from synergine.core.Core import Core
3
from synergine.synergy.event.Action import Action
4
from intelligine.synergy.event.transport.TakeableEvent import TakeableEvent
5
from intelligine.cst import CANT_PUT_STILL, BRAIN_PART_TAKE
6
from synergine.synergy.event.exception.ActionAborted import ActionAborted
7
8
9
class TakeableAction(Action):
10
11
    _listen = TakeableEvent
12
    _depend = [MoveAction]
13
14
    def __init__(self, object_id, parameters):
15
        super().__init__(object_id, parameters)
16
17
    def run(self, obj, context, synergy_manager):
18
        obj_id_transportable = self._parameters[TakeableEvent.PARAM_TAKE]
19
        obj_transportable = synergy_manager.get_map().get_object(obj_id_transportable)
20
21
        if not obj_transportable.is_takable():
22
            raise ActionAborted()
23
24
        obj_carried = obj_transportable.get_what_carry()
25
        obj_carried.set_carried_by(obj)
26
        obj.carry(obj_carried)
27
        cant_put_still = Core.get_configuration_manager().get('ant.take.cant_put_still')
28
        context.metas.value.set(CANT_PUT_STILL, obj.get_id(), cant_put_still)
29
        obj.get_brain().get_part(BRAIN_PART_TAKE).done(obj_carried)
30