Example #1
0
    def get_priority(cls, actor):
        """
        Priority is based on health but adjusted when corpses are close
        """
        if actor.hp >= actor.max_hp:
            return Priority.Never

        corpses = actor.level.get_actors_by_team(Team.Corpse)
        if not corpses:
            return Priority.Never

        if not actor.level.get_actors_by_team(Team.Goblin):
            return Priority.High

        closest_corpse = utils.get_closest_actor(actor, corpses)
        dist = utils.get_distance(actor, closest_corpse)

        hp = actor.hp
        quarter_hp = actor.max_hp / 4
        if hp >= quarter_hp * 3:
            if dist <= 1:
                return Priority.High
            else:
                return Priority.VeryLow
        elif hp >= quarter_hp * 2:
            if dist <= 1:
                return Priority.High
            elif dist <= 3:
                return Priority.Medium
            else:
                return Priority.Low
        else:
            return Priority.High
Example #2
0
def test_get_distance_returns_actual_distance(expected, target_position):
    actor = actors.Egg(None, 0, 0)
    tx, ty = target_position
    target = actors.Goblin(None, tx, ty)
    result = utils.get_distance(actor, target)

    assert result == expected
Example #3
0
    def can_execute(self, actor, target):
        if target is None:
            return False

        distance = utils.get_distance(actor, target)
        if distance <= self.reach:
            return True
        return False
Example #4
0
    def execute(cls, actor, target=None):
        if target is None:
            target = cls._get_target(actor)
            if target is None:
                return False

        dist = utils.get_distance(actor, target)
        if dist <= 1:
            return actor.actions.try_execute("burrow_egg", target)
        else:
            return movement.step_to_target(actor, target)
Example #5
0
    def can_execute(self, actor, target):
        base_result = super().can_execute(actor, target)
        if not base_result:
            return base_result

        if utils.get_distance(actor, target) > self.reach:
            return False

        if not utils.has_clear_line_of_sight(actor, target):
            return False

        return True
Example #6
0
    def get_priority(cls, actor):
        goblins = actor.level.get_actors_by_team(Team.Goblin)
        if not goblins:
            return Priority.Never

        goblin = utils.get_closest_actor(actor, goblins)
        dist = utils.get_distance(actor, goblin)
        if dist <= 1:
            return Priority.Extreme
        elif dist == 2:
            return Priority.Medium
        else:
            return Priority.Low
Example #7
0
    def get_priority(cls, actor):
        if actor.cooldowns.get("lay_egg"):
            return Priority.Never

        enemies = actor.level.get_actors_by_team(Team.Goblin)
        if enemies:
            closest_enemy = utils.get_closest_actor(actor, enemies)
            dist = utils.get_distance(actor, closest_enemy)
            if dist >= 10:
                return Priority.High
            elif dist >= 5:
                return Priority.Medium
            else:
                return Priority.Never

        return Priority.High
Example #8
0
    def can_execute(self, actor, target):
        base_result = super().can_execute(actor, target)
        if not base_result:
            return base_result

        if target.team != Team.Goblin:
            actor.game.messaging.add_player_message(
                "That wouldn't make a nutritious meal.", actor)
            return False

        dist = utils.get_distance(actor, target)
        if dist <= self.reach:
            target_line = utils.get_target_line(actor, target)
            obstacles = utils.get_obstacles_in_target_line(target_line)
            self.target_line = target_line
            if obstacles:
                return False

        return True
Example #9
0
    def get_priority(cls, actor):
        if actor.cooldowns.get("spin_cocoon"):
            return Priority.Never

        enemies = actor.level.get_actors_by_team(Team.Goblin)
        if enemies:
            nearby_enemies = []
            for enemy in enemies:
                dist = utils.get_distance(actor, enemy)
                if dist <= 3:
                    nearby_enemies.append(enemy)

            amount_of_nearby_enemies = len(nearby_enemies)
            if amount_of_nearby_enemies == 1:
                return Priority.Extreme
            elif amount_of_nearby_enemies == 2:
                return Priority.Medium

        return Priority.Never