Example #1
0
    def handle_event(self, entity, event, resident_map):
        event_type, event_data = event
        is_paralyzed = entity.component('Stats').has_status('PARALYZE')

        # Remove this creature's threatened positions after they die
        if event_type == 'KILLED_ENTITY' and event_data == entity and self._delayed_targets is not None:
            targeted_positions = self._delayed_targets[1]
            resident_map.remove_threatened_positions(entity.ident())
            return False

        # Rest the target to None if the target died
        if event_type == 'KILLED_ENTITY' and event_data.ident() == self._target:
            self._target = None

        if event_type == 'ENDED_TURN':
            self._handle_passive_attacks(entity, resident_map)
            if is_paralyzed:
                return False
            elif self._delayed_attack is not None:
                if self._handle_delayed_attack(entity, resident_map) is False:
                    return False

        # If no delayed attack, get action from state instead
        state = self._states.get(self._current_state)
        if state is not None:
            return state.handle_event(entity, self, event)
        return False
Example #2
0
 def perform_passive_attack_against(self, entity, target, usable, delay):
     import settings
     if delay == 0:
         usable.use(entity, entity, settings.current_map, None)
         return
     passive_targets = usable.choose_targets(entity, entity, settings.current_map, None)
     self._passive_attacks.append((usable, delay, passive_targets))
     settings.current_map.add_threatened_positions(passive_targets[1], delay, entity.ident())
Example #3
0
 def _handle_delayed_attack(self, entity, resident_map):
     self._delay -= 1
     if self._delay > 0:
         return False
     targeted_positions = self._delayed_targets[1]
     # TODO: make this work with / without friendly fire
     excluded_components = ['Item'] + (['Ally', 'Player', 'Neutral'] if entity.ident() == 'PLAYER' or \
                                         entity.has_component('Ally') else ['NPC'])
     excluded_components += ([] if not entity.has_component('Ally') else ['PlayerLogic'])
     targets = resident_map.entities().without_components(excluded_components)\
                                      .with_component('Position')\
                                      .where(lambda ent: ent.component('Position').get() in targeted_positions), targeted_positions
     self._delayed_attack.use_on_targets(entity, entity, resident_map, targets, None)
     self._delay = None
     self._delayed_attack = None
     return False
Example #4
0
 def _handle_passive_attacks(self, entity, resident_map):
     new_passive_attacks = []
     for passive_attack, delay, passive_targets in self._passive_attacks:
         delay -= 1
         if delay == 0:
             targeted_positions = passive_targets[1]
             # TODO: make this work with / without friendly fire
             excluded_components = ['Item'] + (['Ally', 'Player', 'Neutral'] if entity.ident() == 'PLAYER' or \
                                               entity.has_component('Ally') else ['NPC'])
             excluded_components += ([] if not entity.has_component('Ally') else ['PlayerLogic'])
             targets = resident_map.entities().without_components(excluded_components)\
                                              .with_component('Position')\
                                              .where(lambda ent: ent.component('Position').get() in targeted_positions), targeted_positions
             passive_attack.use_on_targets(entity, entity, resident_map, targets, None)
         else:
             new_passive_attacks.append((passive_attack, delay, passive_targets))
     self._passive_attacks = new_passive_attacks
     return False
Example #5
0
 def f(self, entity, ai, event_data):
     target, amount = event_data
     if target.ident() == entity.ident():
         handler(entity, ai, event_data)
         return should_stop
     return False
Example #6
0
 def perform_delayed_attack_against(self, entity, target, usable, delay):
     import settings
     if delay == 0:
         usable.use(entity, entity, settings.current_map, None)
         return
     self._delayed_attack = usable
     self._delay = delay
     self._delayed_targets = usable.choose_targets(entity, entity, settings.current_map, None)
     settings.current_map.add_threatened_positions(self._delayed_targets[1], delay, entity.ident())
Example #7
0
 def f(self, entity, ai, event_data):
     if event_data.ident() == entity.ident():
         handler(entity, ai, event_data)
         return should_stop
     return False