示例#1
0
    def test_merging_ammunition_in_pickup(self):
        """
        Same kind of ammunition should be merged when picked up
        """
        ammo_1 = (ItemBuilder()
                    .with_name('arrow')
                    .with_count(10)
                    .build())
        ammo_2 = (ItemBuilder()
                    .with_name('arrow')
                    .with_count(20)
                    .build())

        add_item(self.level, self.character.location, ammo_1)
        add_item(self.level, self.character.location, ammo_2)

        pick_up(self.character,
                ammo_1)
        pick_up(self.character,
                ammo_2)

        assert_that(len(self.character.inventory), is_(equal_to(1)))

        item = self.character.inventory[0]

        assert_that(item.ammunition_data.count, is_(equal_to(30)))
示例#2
0
    def test_merging_ammunition_in_pickup(self):
        """
        Same kind of ammunition should be merged when picked up
        """
        ammo_1 = (ItemBuilder()
                    .with_name('arrow')
                    .with_count(10)
                    .build())
        ammo_2 = (ItemBuilder()
                    .with_name('arrow')
                    .with_count(20)
                    .build())

        add_item(self.level, self.character.location, ammo_1)
        add_item(self.level, self.character.location, ammo_2)

        pick_up(self.character,
                ammo_1)
        pick_up(self.character,
                ammo_2)

        assert_that(len(self.character.inventory), is_(equal_to(1)))

        item = self.character.inventory[0]

        assert_that(item.ammunition_data.count, is_(equal_to(30)))
示例#3
0
    def execute(self):
        """
        Executes this action
        """
        if not self.is_legal():
            return Left(self.character)

        self.character.inventory.remove(self.item)
        add_item(self.character.level, self.character.location, self.item)

        self.character.add_to_tick(Duration.fast)
        self.character.raise_event(new_drop_event(self.character, self.item))

        return Right(self.character)
示例#4
0
    def execute(self):
        """
        Executes this action
        """
        if not self.is_legal():
            return Left(self.character)

        self.character.inventory.remove(self.item)
        add_item(self.character.level, self.character.location, self.item)

        self.character.add_to_tick(Duration.fast)
        self.character.raise_event(new_drop_event(self.character,
                                                  self.item))

        return Right(self.character)
示例#5
0
    def place_items(self, items, level):
        """
        Place items to level

        :param items: list of tupples (item_spec, item)
        :param level: level to place items
        :type level: Level
        """
        for item in items:
            location_type = item[0]['location']

            if location_type is None:
                location_type = 'any'

            locations = [location for location in (get_locations_by_tag(level, location_type))
                         if safe_passage(level, location)]

            if locations:
                location = self.rng.choice(locations)
                add_item(level, location, item[1])
示例#6
0
    def setup(self):
        """
        Setup test cases
        """
        self.item = (ItemBuilder()
                        .build())

        self.model = Model()

        self.level = LevelBuilder().build()

        self.character = (CharacterBuilder()
                            .with_location((5, 5))
                            .with_level(self.level)
                            .with_model(self.model)
                            .build())

        add_item(self.level, (5, 5), self.item)

        set_action_factory(ActionFactoryBuilder()
                           .with_inventory_factory()
                           .build())
示例#7
0
    def setup(self):
        """
        Setup test cases
        """
        self.item = (ItemBuilder()
                        .build())

        self.model = Model()

        self.level = LevelBuilder().build()

        self.character = (CharacterBuilder()
                            .with_location((5, 5))
                            .with_level(self.level)
                            .with_model(self.model)
                            .build())

        add_item(self.level, (5, 5), self.item)

        set_action_factory(ActionFactoryBuilder()
                           .with_inventory_factory()
                           .build())
示例#8
0
    def place_items(self, items, level):
        """
        Place items to level

        :param items: list of tupples (item_spec, item)
        :param level: level to place items
        :type level: Level
        """
        for item in items:
            location_type = item[0]['location']

            if location_type is None:
                location_type = 'any'

            locations = [
                location
                for location in (get_locations_by_tag(level, location_type))
                if safe_passage(level, location)
            ]

            if locations:
                location = self.rng.choice(locations)
                add_item(level, location, item[1])