A data-driven attribute management system for RPGs
Project description
DataRPG 🎮
DataRPG is a lightweight, flexible, and data-driven attribute management system for RPGs and game engines. It handles complex math, derived stats, temporary buffs, and data serialization with ease.
Features
- Dynamic Calculations: Support for "Flat" and "Percent" modifiers.
- Attribute Derivation: Create dependencies (e.g.,
Manadepends onIntelligence). - Time-Aware: Built-in engine to handle expiring buffs and debuffs.
- Anti-Stacking: Tag-based system to prevent similar bonuses from stacking.
- Data-Driven: Full support for JSON, YAML, and TOML.
- Templates: Define character "blueprints" and spawn instances instantly.
Installation
Install the core package:
pip install datarpg
To enable YAML or TOML support, install the optional dependencies:
pip install datarpg[yaml]
pip install datarpg[toml]
# Or install everything
pip install datarpg[all]
Quick Start
1. Basic Usage
from datarpg.core import Actor
# Create a character
hero = Actor("Artorias")
# Add a base attribute
hero.add_attribute("strength", 10)
# Add a derived attribute (Attack = Strength \* 2.0)
hero.add_derived("attack", parent_id="strength", multiplier=2.0)
print(hero.attack.value) # Output: 20.0
2. Modifiers and Buffs
# Add a flat bonus (+5 Strength)
hero.strength.add_modifier("iron_sword", 5, kind="flat")
# Add a timed percentage buff (+10% Strength for 5 seconds)
hero.strength.add_modifier("potion", 0.1, kind="percent", duration=5)
# Automatic recalculation
print(hero.attack.value) # (10 + 5) _ 1.1 _ 2.0 = 33.0
3. Using Templates and Serialization
Define your classes in YAML and spawn them:
# warrior.yaml
name: "Warrior Class"
attributes:
str: { type: "base", value: 15 }
vit: { type: "base", value: 10 }
hp: { type: "derived", parent_id: "vit", multiplier: 10.0 }
from datarpg.utils import AttrifySerializer
# Load template
warrior_tpl = AttrifySerializer.load_template("warrior.yaml")
# Spawn a new instance
my_hero = warrior_tpl.create_actor("Geralt")
print(my_hero.hp.value) # Output: 100.0
Advanced: The Tick Engine
To make temporary modifiers expire, integrate the TickEngine into your game loop:
from datarpg.engines import TickEngine
engine = TickEngine(my_hero)
# Inside your game loop (delta_time in seconds/frames)
engine.update(delta_time)
Running Tests
Ensure everything is working correctly:
pytest
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file datarpg-0.1.0.tar.gz.
File metadata
- Download URL: datarpg-0.1.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e19083727e74567757dee427a57aac6c081d7fb5185e0345a78fa4a606b03b6
|
|
| MD5 |
6a72b9a789a2918c595cc71dd6760b5f
|
|
| BLAKE2b-256 |
26b4758eb4188ab39e2606d86e1ad278a4bbd17ba72991e5db54622fea364cb5
|
File details
Details for the file datarpg-0.1.0-py3-none-any.whl.
File metadata
- Download URL: datarpg-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4934356a36078c18b089f885be50af17357b0592d2e9053baace891027327f0d
|
|
| MD5 |
c55cca6e5b9bd80be276d68138c8fd6c
|
|
| BLAKE2b-256 |
a199472dfd4b87e9d6a40938338fdf489c2e76eb8211d40edc48ee85aa95b205
|