Exemplo n.º 1
0
    def setup(self):
        """
        Setup test case
        """
        self.item_config = ItemConfigurations(Random())

        self.item_config.add_item(
            ItemConfiguration(name='apple',
                              cost=1,
                              weight=1,
                              icons=[500, 501],
                              types=['food'],
                              rarity='common'))

        self.item_config.add_item(
            ItemConfiguration(
                name='dagger',
                cost=2,
                weight=1,
                icons=[500],
                types=['weapon', 'light weapon', 'melee', 'simple weapon'],
                rarity='common',
                weapon_configration=WeaponConfiguration(
                    damage=[(2, 'piercing')],
                    critical_range=11,
                    critical_damage=2,
                    weapon_class='simple')))

        self.item_config.add_item(
            ItemConfiguration(name='healing potion',
                              cost=150,
                              weight=1,
                              icons=[100],
                              types=['potion'],
                              rarity='rare',
                              effect_handles=[
                                  EffectHandle(trigger='on drink',
                                               effect='cure medium wounds',
                                               parameters=None,
                                               charges=1)
                              ]))

        self.item_config.add_item(
            ItemConfiguration(name='bag of caltrops',
                              cost=150,
                              weight=1,
                              icons=['icon'],
                              types=['trap bag'],
                              rarity='common',
                              trap_configuration=TrapConfiguration(
                                  name='caltrops', count=2)))

        self.generator = ItemGenerator(self.item_config)
Exemplo n.º 2
0
    def initialise_generators(self, context):
        """
        Initialise generators
        """
        self.item_generator = ItemGenerator(self.get_item_config(context))

        pyherc.vtable["\ufdd0:generate-artefact"] = generate_artefact

        self.creature_generator = partial(generate_creature,
                                          self.get_creature_config(context),
                                          self.model, self.item_generator,
                                          self.rng)

        self.player_generator = partial(generate_creature,
                                        self.get_player_config(context),
                                        self.model, self.item_generator,
                                        self.rng)

        self.player_classes = self.get_player_config(context)

        configurators = self.get_configurators(context.config_package,
                                               'init_traps')

        traps = {}
        for configurator in configurators:
            temp_traps = traps.copy()
            temp_traps.update(configurator())
            traps = temp_traps

        self.trap_generator = get_trap_creator(traps)
Exemplo n.º 3
0
    def setup(self):
        """
        Setup test case
        """
        self.item_config = ItemConfigurations(Random())

        self.item_config.add_item(
                    ItemConfiguration(name = 'apple',
                                      cost = 1,
                                      weight = 1,
                                      icons = [500, 501],
                                      types = ['food'],
                                      rarity = 'common'))

        self.item_config.add_item(
                    ItemConfiguration(name = 'dagger',
                                      cost = 2,
                                      weight = 1,
                                      icons = [500],
                                      types = ['weapon',
                                               'light weapon',
                                               'melee',
                                               'simple weapon'],
                                      rarity = 'common',
                                      weapon_configration = WeaponConfiguration(
                                            damage = [(2, 'piercing')],
                                            critical_range = 11,
                                            critical_damage = 2,
                                            weapon_class = 'simple')))

        self.item_config.add_item(
                    ItemConfiguration(name = 'healing potion',
                                      cost = 150,
                                      weight = 1,
                                      icons = [100],
                                      types = ['potion'],
                                      rarity = 'rare',
                                      effect_handles = [EffectHandle(
                                            trigger = 'on drink',
                                            effect = 'cure medium wounds',
                                            parameters = None,
                                            charges = 1)]))

        self.item_config.add_item(
            ItemConfiguration(name = 'bag of caltrops',
                              cost = 150,
                              weight = 1,
                              icons = ['icon'],
                              types = ['trap bag'],
                              rarity = 'common',
                              trap_configuration = TrapConfiguration(name = 'caltrops',
                                                                     count = 2)))

        self.generator = ItemGenerator(self.item_config)
Exemplo n.º 4
0
    def setup(self):
        """
        Setup testcases
        """
        self.model = mock()
        self.rng = Random()

        inventory = [inventory_config('dagger', 1, 1, 100)]

        self.skeleton_config = creature_config(name='skeleton warrior',
                                               body=8,
                                               finesse=11,
                                               mind=0,
                                               hp=8,
                                               speed=2.5,
                                               icons=[405],
                                               attack=2,
                                               ai=MockAI,
                                               inventory=inventory)

        self.creature_config = {}

        self.creature_config['skeleton warrior'] = self.skeleton_config

        item_config = ItemConfigurations(self.rng)
        item_config.add_item(
            ItemConfiguration(name='dagger',
                              cost=2,
                              weight=2,
                              icons='foo',
                              types=['item'],
                              rarity='common'))
        items = ItemGenerator(item_config)

        self.creatures = partial(generate_creature, self.creature_config,
                                 self.model, items, self.rng)
Exemplo n.º 5
0
class TestItemGeneration():
    """
    Tests for new item generator
    """
    def __init__(self):
        """
        Default constructor
        """
        super(TestItemGeneration, self).__init__()
        self.item_config = None
        self.generator = None

    def setup(self):
        """
        Setup test case
        """
        self.item_config = ItemConfigurations(Random())

        self.item_config.add_item(
                    ItemConfiguration(name = 'apple',
                                      cost = 1,
                                      weight = 1,
                                      icons = [500, 501],
                                      types = ['food'],
                                      rarity = 'common'))

        self.item_config.add_item(
                    ItemConfiguration(name = 'dagger',
                                      cost = 2,
                                      weight = 1,
                                      icons = [500],
                                      types = ['weapon',
                                               'light weapon',
                                               'melee',
                                               'simple weapon'],
                                      rarity = 'common',
                                      weapon_configration = WeaponConfiguration(
                                            damage = [(2, 'piercing')],
                                            critical_range = 11,
                                            critical_damage = 2,
                                            weapon_class = 'simple')))

        self.item_config.add_item(
                    ItemConfiguration(name = 'healing potion',
                                      cost = 150,
                                      weight = 1,
                                      icons = [100],
                                      types = ['potion'],
                                      rarity = 'rare',
                                      effect_handles = [EffectHandle(
                                            trigger = 'on drink',
                                            effect = 'cure medium wounds',
                                            parameters = None,
                                            charges = 1)]))

        self.item_config.add_item(
            ItemConfiguration(name = 'bag of caltrops',
                              cost = 150,
                              weight = 1,
                              icons = ['icon'],
                              types = ['trap bag'],
                              rarity = 'common',
                              trap_configuration = TrapConfiguration(name = 'caltrops',
                                                                     count = 2)))

        self.generator = ItemGenerator(self.item_config)

    def test_create_mundane_item(self):
        """
        Test that creating a simple item is possible
        """
        item = self.generator.generate_item(name = 'apple')

        assert_that(item.name, is_(equal_to('apple')))

    def test_create_weapon(self):
        """
        Test that a weapon can be created
        """
        item = self.generator.generate_item(name = 'dagger')

        weapon_data = item.weapon_data

        assert_that(item, has_damage(2, 'piercing'))

    def test_create_trap_bag(self):
        """
        Test that trap bag can be created
        """
        item = self.generator.generate_item(name = 'bag of caltrops')
        trap_data = item.trap_data

        assert_that(trap_data.trap_name, is_(equal_to('caltrops')))
        assert_that(trap_data.count, is_(equal_to(2)))

    def test_configuring_item_generation(self):
        """
        Test that configuration can be added
        """
        specs = [x for x in self.item_config.get_all_items()
                 if x.name == 'apple']

        assert_that(len(specs), is_(equal_to(1)))

    def test_generate_item_with_effect(self):
        """
        Test that item with effect can be generated
        """
        item = self.generator.generate_item(name = 'healing potion')

        assert_that(item, is_(not_none()))

        assert_that(item, has_effect_handle())

    def test_generating_random_item(self):
        """
        Test that a random item can be generated
        """
        item = self.generator.generate_item(item_type = 'food')

        assert_that(item.name, is_(equal_to('apple')))
Exemplo n.º 6
0
class TestItemGeneration():
    """
    Tests for new item generator
    """
    def __init__(self):
        """
        Default constructor
        """
        super(TestItemGeneration, self).__init__()
        self.item_config = None
        self.generator = None

    def setup(self):
        """
        Setup test case
        """
        self.item_config = ItemConfigurations(Random())

        self.item_config.add_item(
            ItemConfiguration(name='apple',
                              cost=1,
                              weight=1,
                              icons=[500, 501],
                              types=['food'],
                              rarity='common'))

        self.item_config.add_item(
            ItemConfiguration(
                name='dagger',
                cost=2,
                weight=1,
                icons=[500],
                types=['weapon', 'light weapon', 'melee', 'simple weapon'],
                rarity='common',
                weapon_configration=WeaponConfiguration(
                    damage=[(2, 'piercing')],
                    critical_range=11,
                    critical_damage=2,
                    weapon_class='simple')))

        self.item_config.add_item(
            ItemConfiguration(name='healing potion',
                              cost=150,
                              weight=1,
                              icons=[100],
                              types=['potion'],
                              rarity='rare',
                              effect_handles=[
                                  EffectHandle(trigger='on drink',
                                               effect='cure medium wounds',
                                               parameters=None,
                                               charges=1)
                              ]))

        self.item_config.add_item(
            ItemConfiguration(name='bag of caltrops',
                              cost=150,
                              weight=1,
                              icons=['icon'],
                              types=['trap bag'],
                              rarity='common',
                              trap_configuration=TrapConfiguration(
                                  name='caltrops', count=2)))

        self.generator = ItemGenerator(self.item_config)

    def test_create_mundane_item(self):
        """
        Test that creating a simple item is possible
        """
        item = self.generator.generate_item(name='apple')

        assert_that(item.name, is_(equal_to('apple')))

    def test_create_weapon(self):
        """
        Test that a weapon can be created
        """
        item = self.generator.generate_item(name='dagger')

        weapon_data = item.weapon_data

        assert_that(item, has_damage(2, 'piercing'))

    def test_create_trap_bag(self):
        """
        Test that trap bag can be created
        """
        item = self.generator.generate_item(name='bag of caltrops')
        trap_data = item.trap_data

        assert_that(trap_data.trap_name, is_(equal_to('caltrops')))
        assert_that(trap_data.count, is_(equal_to(2)))

    def test_configuring_item_generation(self):
        """
        Test that configuration can be added
        """
        specs = [
            x for x in self.item_config.get_all_items() if x.name == 'apple'
        ]

        assert_that(len(specs), is_(equal_to(1)))

    def test_generate_item_with_effect(self):
        """
        Test that item with effect can be generated
        """
        item = self.generator.generate_item(name='healing potion')

        assert_that(item, is_(not_none()))

        assert_that(item, has_effect_handle())

    def test_generating_random_item(self):
        """
        Test that a random item can be generated
        """
        item = self.generator.generate_item(item_type='food')

        assert_that(item.name, is_(equal_to('apple')))