feat: import monster fixed successes

This commit is contained in:
Dandaedre 2026-09-19 21:23:18 +02:00
parent 475fe17853
commit 7ac98f8d14
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
2 changed files with 26 additions and 1 deletions

View File

@ -2,7 +2,7 @@ import json
import sqlite3
import unittest
from tools.export_monsters import DEFAULT_DB, convert
from tools.export_monsters import DEFAULT_DB, convert, fixed_successes
class MonsterExportTests(unittest.TestCase):
@ -36,6 +36,20 @@ class MonsterExportTests(unittest.TestCase):
for name in attrs) +
sum(name.endswith("_description") and name.startswith("repeating_powers_")
for name in attrs))
for ability in source["abilities"]:
if not ability["damage_regular"]:
continue
prefix = f"repeating_attacks_dbability{ability['attack_id']}_"
successes = fixed_successes(ability["success"])
self.assertEqual(attrs[prefix + "auto_successes"], str(successes))
self.assertEqual(attrs[prefix + "roll_dice"], "0")
self.assertEqual(attrs[prefix + "rmax"], str(successes))
def test_fixed_success_notation(self):
self.assertEqual(fixed_successes("4r"), 4)
self.assertEqual(fixed_successes(" 10R "), 10)
self.assertEqual(fixed_successes(None), 0)
self.assertEqual(fixed_successes("variable"), 0)
def test_missing_creature_fails(self):
with self.assertRaisesRegex(ValueError, "No creature"):

View File

@ -5,6 +5,7 @@ remain in GM notes alongside the complete source rows.
"""
import argparse
import json
import re
import sqlite3
from pathlib import Path
@ -23,6 +24,12 @@ def text(value: object) -> str:
return "" if value is None else str(value)
def fixed_successes(value: object) -> int:
"""Read the monster database's fixed-success notation (for example ``4r``)."""
match = re.fullmatch(r"\s*(\d+)\s*[rR]?\s*", text(value))
return int(match.group(1)) if match else 0
def convert(db: sqlite3.Connection, creature_id: int) -> dict:
core_row = db.execute("SELECT * FROM creature WHERE id = ?", (creature_id,)).fetchone()
if core_row is None:
@ -71,10 +78,14 @@ def convert(db: sqlite3.Connection, creature_id: int) -> dict:
]))
if ability["damage_regular"]:
prefix = f"repeating_attacks_{ident}_"
successes = fixed_successes(ability["success"])
add(prefix + "name", ability["name"])
add(prefix + "dice", 0) # The database does not specify the hunter roll pool.
add(prefix + "auto_successes", successes)
add(prefix + "roll_dice", 0)
add(prefix + "base_damage", 0) # Damage may be phase dependent or Typst markup.
add(prefix + "break_damage", ability["armor_break"] or 0)
add(prefix + "rmax", successes)
add(prefix + "parry_threshold", ability["threshold_parry"] or 0)
add(prefix + "dodge_threshold", ability["threshold_dodge"] or 0)
add(prefix + "reposition_threshold", ability["threshold_repositionning"] or 0)