Loot Generator

Loot Generator is a utility that provides mechanisms to define item rarities (otherwise treated as ‘weights’ or drop rate) and generate a return loot items from a list of items that can be filtered by the level(min and max) of item and rarity.

The loot generator module(loot.py) use a JSON file, which per default will search for the file called ‘items.json’ in the current directory. In the future: if no items.json is present in the current directory, the file which comes with the rpgtools will be used (actually D&D3.5 / PathFinder items).

The loot generator can be used directly from the CLI (Command Line) or can be used in other modules.

How to use the CLI Interface

The CLI interface can be used by the following way:

python -m rpgtools.loot

At this moment, the module dont support parameters(aka ‘opts’ or ‘args’) but it will be soon.

How to import and use the LootGenerator in your code

You can use the LootGenerator class in your code freely through the following statements:

from rpgtools import loot

my_loot = loot.LootGenerator()

With these statements, the following behaviours will occur:

  1. The number of loot items returned will be 10;
  2. The drop rate will be:
  • ‘common’: 10
  • ‘rare’: 1.5
  • ‘uncommon’: 7.5
  • unique’: 0.1
  • ‘wondrous’: 0.5
  1. The min level is 1 and the max level is 10.

You can override some of these statements at the instance creation, considering the following args:

  • rarities: A dictionary that have the rarity name and the weight integer, as follows:

    rarities={‘common’: 10, ‘unique’:0.0001, ‘uncommon’: 1, ‘rare’:0.1}

  • loot_limit: an integer value that indicates the number of loot items to be generated. loot_limit = 3

  • min_level and max_level: an integer value that indicates the min and max level of the items that will be generated respectively.

So, if you want to generate a loot with 4 items that matches levels throught 3 and 6 with your own drop rates, you can do the following:

from rpgtools import loot

rarities={'common': 10, 'unique':0.0001, 'uncommon': 1, 'rare':0.1}

my_loot =  loot.LootGenerator(rarities, loot_limit=4, min_level=3,

The name of arguments must match the values here; actually all these values are popped through **kwargs if you want to customize the loot.

INFO: items.json format

The items file used by the LootGenerator is plain text JSON file, that have the following information by default:

  • name: The name of the Item.
  • category: Normally the item category, like ‘weapon’, ‘armor’, ‘alchemical stuff’, etc.
  • subcategory: Normally something like ‘Two-handed Weapon’, ‘Full Plate Armor’, etc.
  • rarity: A string value that matches the rarities dict used to instantiate LootGeneratorClass.
  • level: A integer value that defines the item level.
  • reference: A reference (docstring) to help people to find more info about the item, usually an index of a book or a URL page of the item.

The following example shows a valid items.json file:

        "subcategory": null,
        "rarity": "common",
        "category": "Item",
        "name": "One pound of wheat",
        "reference": "SRD 3.5 Equipment",
        "level": 1
        "subcategory": null,
        "rarity": "common",
        "category": "Item",
        "name": "One pound of flour, or one chicken",
        "reference": "SRD 3.5 Equipment",
        "level": 1

We recommend the use of an editor (there are many online now) to make the editions.

If the created json file is invalid, an exception will be raised the json module (Maybe some more verification and tests can be created later).

Table Of Contents

Previous topic

Welcome to rpgtools’s documentation!

This Page