ravenous_roll20/tools/generate_character.py

113 lines
5.7 KiB
Python

"""Generate a deterministic, randomized Ravenous character import fixture.
The output intentionally includes every repeating section and awkward text
characters. It is useful both as an example for consumers of the exchange
format and as a lightweight fuzz fixture for the Roll20 importer.
"""
import argparse
import json
import random
import string
from pathlib import Path
FORMAT = "ravenous-roll20-character"
VERSION = 1
CHARACTERISTICS = ("force", "agilite", "perception", "intelligence", "volonte",
"psy", "chance", "charisme")
def generate(seed: int) -> dict:
rng = random.Random(seed)
attributes: dict[str, dict[str, str]] = {}
def add(name: str, current: object = "", maximum: object = "") -> None:
attributes[name] = {"name": name, "current": str(current), "max": str(maximum)}
def row_id() -> str:
# Roll20 row IDs are opaque to the importer. A local deterministic ID
# makes diffs and reproducing a failed seed straightforward.
return "fuzz" + "".join(rng.choice(string.ascii_lowercase + string.digits) for _ in range(10))
names = ("Églantine", "Maël", "Ysabeau", "Noé", "Sélène")
name = f"{rng.choice(names)} — essai #{seed}"
add("character_name", name)
add("player_name", "Fixture <MJ> & joueuse")
add("stage", rng.randint(0, 5))
add("skill_die", rng.choice((4, 6, 8, 10, 12, 20, 30, 100)))
for characteristic in CHARACTERISTICS:
add(characteristic, rng.randint(0, 12))
add(characteristic + "_manual", rng.randint(-2, 3))
for resource, maximum in (("jauge", 20), ("fatigue", 12), ("toxicite", 9),
("satiete", 6), ("sang", 15), ("actions", 6)):
top = rng.randint(1, maximum)
add(resource, rng.randint(0, top), top)
add(resource + "_max", top)
for resistance in ("slash", "pierce", "blunt", "fire", "earth", "wood", "magma",
"water", "wind", "ice", "lightning", "abyssal", "celestial",
"alterations", "mental", "fatigue", "sangressence", "void",
"transcendental"):
add("resist_" + resistance, rng.randint(-2, 8))
add("notes", "Fixture reproductible : accents, apostrophe ' et balises <test> & symboles ◆.")
rows = [
("locations", {"name": "Aile gauche", "hp": 3, "hp_max": 7, "protection": 1,
"armor": 2, "armor_max": 4}),
("customskills", {"name": "Cartographie céleste", "characteristic": "intelligence",
"rank": 3, "temp": -1, "total": 2}),
("attacks", {"name": "Lame d'éclipse", "threshold": 6, "temp": 1,
"base_damage": 5, "damage_per_success": 2, "break_damage": 1,
"rmax": 3, "dodge_threshold": 7, "parry_threshold": 5,
"reposition_threshold": 2, "notes": "Feu & glace ; portée <courte>."}),
("protections", {"active": 1, "name": "Manteau renforcé", "protection": 2,
"integrity": 4, "integrity_max": 6, "parry": 1, "dodge": -1,
"effects": "Résiste aux éclats — test."}),
("consumables", {"kind": "Potion", "name": "Élixir \"Aube\"", "quantity": 2,
"duration": "3 tours", "description": "Récupère 1 jauge/tour.",
"duration_type": "turns", "remaining": 3,
"countdown_phase": "end", "start_reminder": "Récupérez 1 Jauge."}),
("modifiers", {"name": "Brûlure persistante", "duration": "2 tours",
"description": "Subit 2 DMG au début du tour.", "active": 1,
"duration_type": "turns", "remaining": 2,
"countdown_phase": "start", "start_reminder": "Subissez 2 DMG.",
"removal_reminder": "La brûlure prend fin."}),
("techniques", {"source_key": "fixture:technique", "name": "Pas du néant",
"owned": 1, "school": "Liminale", "tier": 2, "level": 1,
"blood": 1, "gauge": 2, "other": "—", "type": "Active",
"effect": "Traverse un obstacle <fin>."}),
("powers", {"source_key": "fixture:pouvoir", "name": "Œil d'orage",
"origin": "Fuzz", "stage": 2, "type": "Passif",
"description": "Voit malgré l'obscurité & les illusions."}),
]
for section, fields in rows:
prefix = f"repeating_{section}_{row_id()}_"
for field, value in fields.items():
add(prefix + field, value)
abilities = [{"name": "Fixture : rappel", "action": "/w gm Test <&> réussi",
"istokenaction": True}]
return {"format": FORMAT, "version": VERSION, "name": name,
"controlledby": "", "inplayerjournals": "", "bio": "Personnage généré pour test.",
"gmnotes": f"Généré avec tools/generate_character.py --seed {seed}",
"attributes": list(attributes.values()), "abilities": abilities}
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--seed", type=int, default=0,
help="integer seed; identical seeds produce identical JSON (default: 0)")
parser.add_argument("--output", type=Path,
help="write to this file instead of standard output")
args = parser.parse_args()
rendered = json.dumps(generate(args.seed), ensure_ascii=False, indent=2) + "\n"
if args.output:
args.output.parent.mkdir(parents=True, exist_ok=True)
args.output.write_text(rendered, encoding="utf-8")
print(f"seed {args.seed} -> {args.output}")
else:
print(rendered, end="")
if __name__ == "__main__":
main()