zzstat
A deterministic, hardcode-free stat calculation engine designed for MMORPGs.
Features
- Deterministic stat resolution (same input → same output)
- Hardcode-free design (no built-in stat names like "HP" or "ATK")
- Event-driven resolution (only resolves when invalidated)
- Phase-based transformation pipeline
- Dependency Graph: Automatically resolves dependencies in correct order
- Cycle Detection: Prevents circular dependencies
- Caching: Resolved stats are cached until invalidated
- Context-Aware: Supports conditional calculations via
StatContext - Debug-Friendly: Full breakdown of sources and transforms
Core Concepts
Stat Pipeline
Stats flow through a simple pipeline:
[StatSource] → [StatTransform] → [ResolvedStat]
- Sources produce base values (additive)
- Transforms modify values (can depend on other stats)
- ResolvedStat contains the final value with full breakdown
Quick Start
Add to your Cargo.toml:
[]
= "0.1.0"
Example
use *;
use ConstantSource;
use MultiplicativeTransform;
let mut resolver = new;
let hp_id = from_str;
// Register sources (additive)
resolver.register_source;
resolver.register_source;
// Register transform
resolver.register_transform;
// Resolve
let context = new;
let resolved = resolver.resolve.unwrap;
assert_eq!; // (100 + 50) * 1.5
Examples
The examples/ directory contains several example programs:
basic.rs- Basic stat resolution with sources and transformsdependencies.rs- Stats that depend on other statscomplex.rs- Complex character stat systemcycle_detection.rs- Error handling for circular dependenciescontext.rs- Using StatContext for conditional calculations
Run examples with:
See examples/README.md for more details.
Modules
stat_id- Stat identifier typesource- Stat sources (produce base values)transform- Stat transforms (modify values)resolver- Main stat resolverresolved- Resolved stat resultscontext- Context for conditional calculationsgraph- Dependency graph managementerror- Error types
License
This project is licensed under the MIT License. See LICENSE file for details.