Skip to main content

RPG Loot Drop Engine

Project description

RPG Loot Drop Engine

What started as a personal project of getting better at python and learning about lootboxes turned into something that might be useful to others.

These sites helped me understand the basic concept and mechanics of loot boxes/tables:

When I stumbled across this two article series, I was "Booyah!!!!". The original code was written in C#. This project is my resulting translation.

Differences between the original and this engine:

  • The flag always will always drop at least one item from a table or of that item. Initial testing showed that always would always drop one and only one. To always drop one and only one always and unique will both need to be true.
  • The Randomizer was not implemented
  • The IRDSObjectCreator and subsequent code was not implemented. I didn't see the need, based on what I was trying to do.

Install

pip install drop-generator

Sample code

from dropgen.RDSTable import RDSTable
from dropgen.RDSItem import RDSItem

if __name__ == '__main__':
    loot_table = RDSTable(count=5)

    loot_table.add_entry(RDSItem("Ham Sandwich"))
    loot_table.add_entry(RDSItem("Felt Hat"))
    loot_table.add_entry(RDSItem("Diamond Ring"))
    loot_table.add_entry(RDSItem("Red Brick"))
    loot_table.add_entry(RDSItem("Feral Cat"))
    loot_table.add_entry(RDSItem("Empty Flask"))
    loot_table.add_entry(RDSItem("Someone's garbage"))

    results = loot_table.rds_result

    print("Simple loot drop. Everything has the same chance")
    for result in results:
        print(f"\t{result}")

Code changes to try out

Flags can be set at RDSItem or RDSTable creation time or set/adjusted upon being added to the parent RDSTable.

loot_table.add_entry(RDSItem("Feral Cat", probability=5))

and

loot_table.add_entry(RDSItem("Feral Cat"), probability=5)

These two statements functionally achieve the same thing.

The flags you can set.

  • always: An item or item from a table will always drop at least once. If enough items/tables are marked with always, then actual drops could actually exceed what is defined (count)in the parent table.
  • unique: If the item is selected, then it will be dropped only once.
  • probability: The probability of the item dropping. Wikipedia
  • enabled: Will this item drop.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drop-generator-0.0.35.tar.gz (6.7 kB view hashes)

Uploaded Source

Built Distribution

drop_generator-0.0.35-py3-none-any.whl (9.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page