118 lines
5.6 KiB
Python
118 lines
5.6 KiB
Python
"""Add missing SpellPower rows for routed Turtle spells; never replace existing costs.
|
|
|
|
Read the shipped SpellPower/SpellMisc DB2s (FDIDs 982806/1003144) and either
|
|
Turtle's 173-column Spell.dbc or the existing spell_template TSV interface.
|
|
Units stay unchanged: rage is in tenths, mana/energy/focus are raw units, and
|
|
ManaCostPct is a percentage. --routed-spells optionally adds codec-served IDs
|
|
not yet present in the content SpellMisc table. Claude builds/ships the rows.
|
|
"""
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
|
|
|
|
def source_dbc(path):
|
|
from turtle_data import DBC
|
|
dbc = DBC(Path(path), 173)
|
|
# WoWDBDefs Spell 1.12.0.5595-1.12.3.6141 disk columns (not C++ struct offsets).
|
|
return [dict(SpellID=r[0], PowerType=r[31], ManaCost=r[32],
|
|
ManaCostPerLevel=r[33], ManaPerSecond=r[34],
|
|
ManaPerSecondPerLevel=r[35], PowerCostPct=r[156]) for r in dbc.rows]
|
|
|
|
|
|
def source_tsv(path):
|
|
rows = []
|
|
for line in Path(path).read_text().splitlines():
|
|
fields = line.split('\t')
|
|
if not fields[0].isdigit():
|
|
continue
|
|
if len(fields) < 6:
|
|
raise ValueError('Incomplete spell_template cost row')
|
|
values = [int(v) for v in fields[:6]]
|
|
rows.append(dict(zip(('SpellID', 'ManaCost', 'ManaCostPerLevel',
|
|
'ManaPerSecond', 'PowerCostPct', 'PowerType'), values)))
|
|
return rows
|
|
|
|
|
|
def plan(source, power, misc, first_id, routed_spells=()):
|
|
"""Fill only missing known spells; hold costs the native row cannot express."""
|
|
existing_ids = [r['ID'] for r in power]
|
|
if len(set(existing_ids)) != len(existing_ids):
|
|
raise ValueError('Duplicate native SpellPower row ID')
|
|
if type(first_id) is not int or not max(existing_ids, default=0) < first_id <= 0x7fffffff:
|
|
raise ValueError('First ID must be above all existing SpellPower rows')
|
|
known = {r['SpellID'] for r in misc} | set(routed_spells)
|
|
if any(type(s) is not int or not 0 < s <= 0x7fffffff for s in known):
|
|
raise ValueError('Invalid routed spell ID')
|
|
have = {r['SpellID'] for r in power}
|
|
sources = {}
|
|
for entry in source:
|
|
sid = entry['SpellID']
|
|
if type(sid) is not int or not 0 < sid <= 0x7fffffff or sid in sources:
|
|
raise ValueError('Invalid or duplicate source spell ID')
|
|
sources[sid] = entry
|
|
rows, held = [], []
|
|
for sid in sorted(known & sources.keys()):
|
|
if sid in have:
|
|
continue
|
|
entry = sources[sid]
|
|
costs = {k: entry.get(k, 0) for k in ('ManaCost', 'ManaCostPerLevel',
|
|
'ManaPerSecond', 'ManaPerSecondPerLevel', 'PowerCostPct')}
|
|
if any(type(v) is not int or not 0 <= v <= 0x7fffffff for v in costs.values()):
|
|
raise ValueError('Invalid source cost field')
|
|
if not any(costs.values()):
|
|
continue
|
|
reason = None
|
|
if entry['PowerType'] not in (0, 1, 2, 3):
|
|
reason = 'unsupported-source-power-type'
|
|
elif costs['ManaPerSecondPerLevel']:
|
|
reason = 'native-row-has-no-per-second-per-level-field'
|
|
if reason:
|
|
held.append(dict(SpellID=sid, reason=reason))
|
|
continue
|
|
ident = first_id + len(rows)
|
|
if ident > 0x7fffffff:
|
|
raise ValueError('SpellPower row ID overflow')
|
|
rows.append(dict(ID=ident, OrderIndex=0, ManaCost=costs['ManaCost'],
|
|
ManaCostPerLevel=costs['ManaCostPerLevel'],
|
|
ManaPerSecond=costs['ManaPerSecond'], PowerDisplayID=0,
|
|
AltPowerBarID=0, PowerCostPct=float(costs['PowerCostPct']),
|
|
PowerCostMaxPct=0.0, OptionalCostPct=0.0, PowerPctPerSecond=0.0,
|
|
PowerType=entry['PowerType'], RequiredAuraSpellID=0,
|
|
OptionalCost=0, SpellID=sid))
|
|
return dict(rows=rows, held=held)
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--spellpower', required=True)
|
|
parser.add_argument('--spellmisc', required=True)
|
|
source = parser.add_mutually_exclusive_group(required=True)
|
|
source.add_argument('--source-dbc')
|
|
source.add_argument('--source-tsv')
|
|
parser.add_argument('--routed-spells', help='Additional codec-routed spell IDs, one decimal ID per line')
|
|
parser.add_argument('--first-id', type=int, required=True)
|
|
parser.add_argument('--output', required=True)
|
|
parser.add_argument('--report', help='Write held cases and covered spell IDs')
|
|
args = parser.parse_args()
|
|
import sys
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent / 'claude_recipe_parity'))
|
|
import dbd
|
|
power = list(dbd.table('SpellPower', args.spellpower)['rows'].values())
|
|
misc = list(dbd.table('SpellMisc', args.spellmisc)['rows'].values())
|
|
entries = source_dbc(args.source_dbc) if args.source_dbc else source_tsv(args.source_tsv)
|
|
routed = [int(s) for s in Path(args.routed_spells).read_text().split()] if args.routed_spells else []
|
|
result = plan(entries, power, misc, args.first_id, routed)
|
|
# Never silently discard nonrepresentable costs in an apparently complete build.
|
|
if result['held'] and not args.report:
|
|
raise ValueError('Held source costs require --report for review')
|
|
Path(args.output).write_text(json.dumps(result['rows'], indent=1) + '\n')
|
|
ids = [r['SpellID'] for r in result['rows']]
|
|
if args.report:
|
|
Path(args.report).write_text(json.dumps(dict(spell_ids=ids, held=result['held']), indent=2) + '\n')
|
|
print(f'{len(ids)} rows; {len(result["held"])} held; spell IDs: ' + ','.join(map(str, ids)))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|