def trigger(self, **kwargs): source_entity = kwargs[action.SOURCE_ENTITY] target_entity = kwargs[action.TARGET_ENTITY] distance = geometry.chess_distance(source_entity.position.value, source_entity.position.value) if (distance <= 1 and source_entity.has(self.entity_trigger_chance_attribute) and random.random() < source_entity.get_child(self.entity_trigger_chance_attribute).value): source_entity.melee_attacker.try_hit(target_entity)
def get_seen_entities_closest_first(self): """ Gets all seen entities sorted on distance from self not including self. """ return sorted(self.get_seen_entities(), key=lambda entity: (geometry.chess_distance(self.parent.position.value, entity.position.value), -entity.health.hp.ratio_of_full(), hash(entity)))
def can_hit(self, entity): if geometry.chess_distance(self.parent.position.value, entity.position.value) > 1: return False # TODO This check should not be here! if entity is None or entity.faction.value == self.parent.faction.value: return False return True
def get_seen_entities_closest_first(self): """ Gets all seen entities sorted on distance from self not including self. """ return sorted(self.get_seen_entities(), key=lambda entity: (geometry.chess_distance( self.parent.position.value, entity.position.value ), -entity.health.hp.ratio_of_full(), hash(entity)))
def is_something_blocking(self, destination): """ What about selfish creatures? that don't care about other creatures. Must know what kind of obstacle is blocking """ path = get_path(self.parent.position.value, destination) hit_detector = shoot.MissileHitDetection(False, False) dungeon_level = self.parent.dungeon_level.value path_taken = hit_detector.get_path_taken(path, dungeon_level) return geometry.chess_distance(self.parent.position.value, destination) != len(path_taken)
def try_step_path(self): """ Tries to step the entity along the path, relies on the mover module. """ if not self.has_path(): return 0 next_point = self.position_list.pop() if not geometry.chess_distance(next_point, self.parent.position.value) == 1: self.set_line_path(next_point) next_point = self.position_list.pop() energy_spent = self.parent.stepper.try_move_or_bump(next_point) if energy_spent <= 0: energy_spent = self.try_step_left_or_right(next_point) if energy_spent <= 0: self.clear() return energy_spent
def player_select_missile_path(source_entity, max_throw_distance, game_state): """ Method initiating a prompt for the player to select a missile path. """ choose_target_prompt = statestack.StateStack() target_entity = source_entity.vision.get_closest_seen_entity() if (not target_entity is None and geo.chess_distance( target_entity.position.value, source_entity.position.value) <= max_throw_distance): init_target = target_entity.position.value else: init_target = source_entity.position.value destination_selector = positionexaminer.\ MissileDestinationSelector(choose_target_prompt, source_entity.position.value, source_entity, game_state, max_throw_distance, init_target=init_target) choose_target_prompt.push(destination_selector) choose_target_prompt.main_loop() return destination_selector.selected_path
def player_select_missile_path(source_entity, max_throw_distance, game_state): """ Method initiating a prompt for the player to select a missile path. """ choose_target_prompt = statestack.StateStack() target_entity = source_entity.vision.get_closest_seen_entity() if(not target_entity is None and geo.chess_distance(target_entity.position.value, source_entity.position.value) <= max_throw_distance): init_target = target_entity.position.value else: init_target = source_entity.position.value destination_selector = positionexaminer.\ MissileDestinationSelector(choose_target_prompt, source_entity.position.value, source_entity, game_state, max_throw_distance, init_target=init_target) choose_target_prompt.push(destination_selector) choose_target_prompt.main_loop() return destination_selector.selected_path
def can_hit(self, entity): if geometry.chess_distance(self.parent.position.value, entity.position.value) > 1: return False return True
def is_destination_within_range(self, destination): return (1 < geometry.chess_distance(self.parent.position.value, destination) <= self.parent.sight_radius.value)
def is_destination_within_range(self, destination): return self.min_range <= geometry.chess_distance( self.parent.position.value, destination) <= self.max_range
def distance_to_optimal_distance(self, position1, position2): return abs(geo.chess_distance(position1, position2) - self.optimal_distance)
def _get_seen_entities_within_max_distance(self): return [entity for entity in self.entity.vision.get_seen_entities_closest_first() if geo.chess_distance(entity.position.value, self.entity.position.value) <= self.max_distance]