Пример #1
0
    def place_creatures(self, creatures, creature_list, level):
        """
        Place creatures into a level

        :param creatures: creatures to place
        :type creatures: [Character]
        :param creature_list: specification where to place creatures
        :type creature_list: dict
        :param level: level to place creatures
        :type level: Level
        """
        for creature in creatures:
            location_types = [x['location'] for x in creature_list
                              if x['name'] == creature.name]

            if not location_types:
                location_types = ['any']
               

            locations = []
            for location_type in location_types:
                locations.extend([location for location in (get_locations_by_tag(level,
                                                                                 location_type))
                                  if safe_passage(level, location)])

            if locations:
                location = self.rng.choice(locations)
                add_character(level, location, creature)
Пример #2
0
    def place_creatures(self, creatures, creature_list, level):
        """
        Place creatures into a level

        :param creatures: creatures to place
        :type creatures: [Character]
        :param creature_list: specification where to place creatures
        :type creature_list: dict
        :param level: level to place creatures
        :type level: Level
        """
        for creature in creatures:
            location_types = [
                x['location'] for x in creature_list
                if x['name'] == creature.name
            ]

            if not location_types:
                location_types = ['any']

            locations = []
            for location_type in location_types:
                locations.extend([
                    location for location in (
                        get_locations_by_tag(level, location_type))
                    if safe_passage(level, location)
                ])

            if locations:
                location = self.rng.choice(locations)
                add_character(level, location, creature)
Пример #3
0
    def setup(self):
        """
        Setup the test case
        """
        self.character = (CharacterBuilder()
                          .with_model(Model())
                          .build())

        self.level1 = (LevelBuilder()
                       .with_floor_tile("floor")
                       .with_wall_at((1, 0))
                       .build())

        self.level2 = (LevelBuilder()
                       .with_floor_tile("floor")
                       .build())
        self.portal1 = Portal((None, None), None)

        self.portal1.icon = 1
        self.portal2 = Portal(("stairs", "stairs"), None)
        self.portal2 = Portal(("stairs", "stairs"), None)

        add_portal(self.level1, (5, 5), self.portal1)
        add_portal(self.level2, (10, 10), self.portal2, self.portal1)

        add_character(self.level1, (5, 5), self.character)

        set_action_factory(ActionFactoryBuilder()
                           .build())
Пример #4
0
def place(character, location):
    """
    Place character to given location

    :param character: character to place
    :type character: Character
    :param location: location to place the character
    :type location: LevelLocation
    """
    add_character(location.level, location.location, character)
Пример #5
0
def place(character, location):
    """
    Place character to given location

    :param character: character to place
    :type character: Character
    :param location: location to place the character
    :type location: LevelLocation
    """
    add_character(location.level, location.location, character)
Пример #6
0
    def test_moving_when_stairs_are_blocked(self):
        """
        Moving should be possible, even if stairs other end is blocked
        """
        blocker = CharacterBuilder().build()

        add_character(self.level2, (10, 10), blocker)

        pyherc.vtable['\ufdd0:move'](character=self.character,
                                     direction=Direction.enter)

        assert_that(blocker.level, is_(equal_to(self.level2)))
        assert_that(self.character.level, is_(equal_to(self.level2)))
Пример #7
0
    def test_moving_when_stairs_are_blocked(self):
        """
        Moving should be possible, even if stairs other end is blocked
        """
        blocker = CharacterBuilder().build()

        add_character(self.level2, (10, 10), blocker)

        pyherc.vtable['\ufdd0:move'](character=self.character,
                                     direction=Direction.enter)

        assert_that(blocker.level, is_(equal_to(self.level2)))
        assert_that(self.character.level, is_(equal_to(self.level2)))
Пример #8
0
    def test_corners_are_rounded(self):
        """
        Spells with spherical area of effect should not target to square area
        """
        add_character(self.level, (7, 7), self.target3)

        params = SpellCastingParameters(caster=self.caster,
                                        direction=7,
                                        spell_name='proto')

        targets = targeting_spherical_area(params, radius=2)

        assert_that(self.target3, is_not(is_in(targets)))
Пример #9
0
    def test_corners_are_rounded(self):
        """
        Spells with spherical area of effect should not target to square area
        """
        add_character(self.level, (7, 7), self.target3)

        params = SpellCastingParameters(caster = self.caster,
                                        direction = 7,
                                        spell_name = 'proto')

        targets = targeting_spherical_area(params,
                                           radius = 2)

        assert_that(self.target3, is_not(is_in(targets)))
Пример #10
0
def impl(context, character_name, target_name):
    character = get_character(context, character_name)
    target = get_character(context, target_name)

    if not target.level:
        room = Level()
        room['name'] = 'room'
        context.places.append(room)
        place(target, middle_of(room))

    level = target.level
    location = (target.location[0] + 3,
                target.location[1])

    remove_character(level, character)
    add_character(level, location, character)
Пример #11
0
    def setup(self):
        """
        Test setup
        """
        self.level = LevelBuilder().build()

        self.monster_1 = (CharacterBuilder().with_name('Pete').build())

        self.monster_2 = (CharacterBuilder().with_name('Uglak').build())

        self.monster_1.artificial_intelligence = lambda: None
        self.monster_2.artificial_intelligence = lambda: None

        add_character(self.level, (5, 5), self.monster_1)
        add_character(self.level, (6, 5), self.monster_2)

        set_action_factory(ActionFactoryBuilder().build())
Пример #12
0
    def build(self):
        """
        Build level

        Returns:
            Level
        """
        level = new_level(self.model)

        for x_loc in range(self.level_size[0]):
            for y_loc in range(self.level_size[1]):
                wall_tile(level, (x_loc, y_loc), self.wall_tile)
                floor_tile(level, (x_loc, y_loc), self.floor_tile)

        for wall in self.walls:
            wall_tile(level, wall, self.solid_wall_tile)

        for creature in self.characters:
            add_character(level, creature.location, creature)

        return level
Пример #13
0
    def setup(self):
        """
        Setup the test case
        """
        self.character = (CharacterBuilder().with_model(Model()).build())

        self.level1 = (LevelBuilder().with_floor_tile("floor").with_wall_at(
            (1, 0)).build())

        self.level2 = (LevelBuilder().with_floor_tile("floor").build())
        self.portal1 = Portal((None, None), None)

        self.portal1.icon = 1
        self.portal2 = Portal(("stairs", "stairs"), None)
        self.portal2 = Portal(("stairs", "stairs"), None)

        add_portal(self.level1, (5, 5), self.portal1)
        add_portal(self.level2, (10, 10), self.portal2, self.portal1)

        add_character(self.level1, (5, 5), self.character)

        set_action_factory(ActionFactoryBuilder().build())
Пример #14
0
    def setup(self):
        """
        Test setup
        """
        self.level = LevelBuilder().build()

        self.monster_1 = (CharacterBuilder()
                          .with_name('Pete')
                          .build())

        self.monster_2 = (CharacterBuilder()
                          .with_name('Uglak')
                          .build())

        self.monster_1.artificial_intelligence = lambda : None
        self.monster_2.artificial_intelligence = lambda : None

        add_character(self.level, (5, 5), self.monster_1)
        add_character(self.level, (6, 5), self.monster_2)

        set_action_factory(ActionFactoryBuilder()
                           .build())
Пример #15
0
    def setup(self):
        """
        Setup test cases
        """
        self.character = (CharacterBuilder()
                            .with_hit_points(10)
                            .build())

        self.target = (CharacterBuilder()
                            .with_hit_points(10)
                            .build())

        self.level = (LevelBuilder()
                        .build())

        add_character(self.level, (2, 2), self.character)
        add_character(self.level, (5, 2), self.target)

        bow = (ItemBuilder()
                    .with_name('bow')
                    .with_required_ammunition_type('arrow')
                    .with_damage(1, 'crushing')
                    .build())
        self.arrows = (ItemBuilder()
                        .with_name('arrows')
                        .with_ammunition_type('arrow')
                        .with_range_damage(3, 'piercing')
                        .with_count(10)
                        .build())

        self.character.inventory.append(bow)
        self.character.inventory.append(self.arrows)
        self.character.inventory.weapon = bow
        self.character.inventory.projectiles = self.arrows

        set_action_factory(ActionFactoryBuilder()
                           .build())
    def setup(self):
        """
        Setup test cases
        """
        self.character = (CharacterBuilder().with_hit_points(10).build())

        self.target = (CharacterBuilder().with_hit_points(10).build())

        self.level = (LevelBuilder().build())

        add_character(self.level, (2, 2), self.character)
        add_character(self.level, (5, 2), self.target)

        bow = (ItemBuilder().with_name('bow').with_required_ammunition_type(
            'arrow').with_damage(1, 'crushing').build())
        self.arrows = (ItemBuilder().with_name('arrows').with_ammunition_type(
            'arrow').with_range_damage(3, 'piercing').with_count(10).build())

        self.character.inventory.append(bow)
        self.character.inventory.append(self.arrows)
        self.character.inventory.weapon = bow
        self.character.inventory.projectiles = self.arrows

        set_action_factory(ActionFactoryBuilder().build())