feat: import monster fixed successes
This commit is contained in:
parent
475fe17853
commit
7ac98f8d14
|
|
@ -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"):
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue