LonelinessSuicideEvent._prepare()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
1
from synergine.core.exceptions import NotConcernedEvent
2
from tests.src.event.TestEvent import TestEvent
3
from tests.src.cst import BEANS, COMPUTABLE
4
from tests.src.TestSimulation import TestSimulation
5
6
7
class LonelinessSuicideEvent(TestEvent):
8
9
    def _prepare(self, object_id, context, parameters={}):
10
        if self._has_friends_with_beans(context):
11
            raise NotConcernedEvent()
12
        return parameters
13
14
    @staticmethod
15
    def _has_friends_with_beans(context):
16
        friends_with_beans_count = 0
17
        for friend_id in context.metas.list.get(TestSimulation.STATE, COMPUTABLE):
18
            friend_beans = context.metas.value.get(BEANS, friend_id)
19
            if friend_beans > 1:
20
                friends_with_beans_count += 1
21
        if friends_with_beans_count == 0:
22
            return False
23
        return True
24