Generating an item

This section will have a look at item generation and how to add new items into the game.

Overview of generating item

pyherc.generators.item.ItemGenerator is used to generate items.

To generate item, following code can be used:

new_item = self.item_generator.generate_item(item_type = 'food')

This will generate a random item of type food. To generate item of specic name, following code can be used:

new_item = self.item_generator.generate_item(name = 'apple')

This will generate an apple.

Defining items

Items are defined in configuration scripts that are fed to pyherc.config.config.Configuration during system startup. Following example defines an apple and dagger for configuration.

from pyherc.generators import ItemConfigurations
from pyherc.generators import ItemConfiguration, WeaponConfiguration
from import EffectHandle

def init_items():
    Initialise common items
    config = []

                  ItemConfiguration(name = 'apple',
                                    cost = 1,
                                    weight = 1,
                                    icons = [501],
                                    types = ['food'],
                                    rarity = 'common'))

                  ItemConfiguration(name = 'dagger',
                                    cost = 2,
                                    weight = 1,
                                    icons = [602, 603],
                                    types = ['weapon',
                                               'light weapon',
                                               'simple weapon'],
                                    rarity = 'common',
                                    weapon_configration = WeaponConfiguration(
                                            damage = [(2, 'piercing'),
                                                      (2, 'slashing')],
                                            critical_range = 11,
                                            critical_damage = 2,
                                            weapon_class = 'simple')))

    return config

config = init_items()


Example creates a list containing two ItemConfiguration objects.

<pyherc.generators.item.ItemConfiguration object at 0x...>

For more details regarding to configuration, refer to Configuration page.