def get_item_config(self, item_config): config = ItemConfigurations(self.rng) configurators = self.get_configurators(item_config, 'init_items') for configurator in configurators: items = configurator() for item in items: config.add_item(item) return config
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 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 get_item_config(self, context): """ Load item configuration :param level_config: namespace of configurations :type level_config: Package :returns: configuration for items :rtype: ItemConfigurations """ config = ItemConfigurations(self.rng) configurators = self.get_configurators(context.config_package, 'init_items') for configurator in configurators: items = configurator(context) for item in items: config.add_item(item) return config
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)
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)
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')))
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')))