367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
143 lines
7.1 KiB
Python
143 lines
7.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Audit class-trainer offers against Source and pinned 70334 skill assignments.
|
|
|
|
Inputs are read-only exports of the live world DB plus the server's actual DBCs.
|
|
The roster export has creature entry, name, class, trainer type, direct/template,
|
|
and service spell. The spell index export has ID, name, first taught spell,
|
|
first effect, and family. See the G3 report for the exact SELECT statements.
|
|
|
|
Only a taught spell with *no* SkillLineAbility row in either version is removed.
|
|
This conservative rule does not infer class assignment from an empty SQL table.
|
|
"""
|
|
import argparse
|
|
from collections import Counter
|
|
import csv
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from map_light_compat import read_wdc5
|
|
from turtle_data import DBC, spell_layout
|
|
|
|
NATIVE_SLA_TABLE = 0xFF4446F6
|
|
NATIVE_SLA_LAYOUT = 0x224F7EA0
|
|
CLASSES = {1, 2, 3, 4, 5, 7, 8, 9, 11}
|
|
|
|
|
|
def digest(path):
|
|
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
|
|
|
|
def tsv(path, fields):
|
|
with path.open(newline='') as source:
|
|
rows = list(csv.reader(source, delimiter='\t'))
|
|
if not rows or any(len(row) != fields for row in rows):
|
|
raise ValueError(f'Unexpected TSV shape: {path}')
|
|
return rows
|
|
|
|
|
|
def audit(roster_path, spell_index_path, source_dbc, native_sla_path):
|
|
source_spell_path = source_dbc / 'Spell.dbc'
|
|
source_sla_path = source_dbc / 'SkillLineAbility.dbc'
|
|
spells = DBC(source_spell_path, 173)
|
|
source_abilities = DBC(source_sla_path, 15)
|
|
native_table = read_wdc5(native_sla_path.read_bytes())
|
|
if (native_table['table'], native_table['layout']) != (NATIVE_SLA_TABLE, NATIVE_SLA_LAYOUT):
|
|
raise ValueError('Unreviewed native SkillLineAbility DB2 schema')
|
|
source_spell_counts = Counter(row[2] for row in source_abilities.rows)
|
|
native_spell_counts = Counter(row[4] for row in native_table['rows'].values())
|
|
sql_spells = {}
|
|
for ident, name, taught, effect, family in tsv(spell_index_path, 5):
|
|
key = int(ident)
|
|
if key in sql_spells:
|
|
raise ValueError(f'Duplicate SQL spell {key}')
|
|
sql_spells[key] = (name, int(taught), int(effect), int(family))
|
|
|
|
offsets = spell_layout()
|
|
roster = []
|
|
for entry, name, class_id, trainer_type, origin, service in tsv(roster_path, 6):
|
|
entry, class_id, trainer_type, service = map(int, (entry, class_id, trainer_type, service))
|
|
if class_id not in CLASSES or trainer_type != 0 or origin not in ('direct', 'template'):
|
|
raise ValueError('Roster contains a non-class trainer or unknown source')
|
|
if service not in sql_spells or service not in spells.by_id:
|
|
raise ValueError(f'Class trainer service missing from SQL or DBC: {service}')
|
|
service_name, taught, effect, _ = sql_spells[service]
|
|
if taught != spells.by_id[service][offsets['EffectTriggerSpell']]:
|
|
raise ValueError(f'Server/DBC taught-spell conflict: {service}')
|
|
if not taught or taught not in sql_spells:
|
|
raise ValueError(f'Class trainer service has no known taught spell: {service}')
|
|
roster.append(dict(creature_entry=entry, creature_name=name, class_id=class_id,
|
|
source=origin, service_spell=service, service_name=service_name,
|
|
taught_spell=taught, taught_name=sql_spells[taught][0],
|
|
source_skillline_rows=source_spell_counts[taught],
|
|
native_skillline_rows=native_spell_counts[taught]))
|
|
|
|
# The row counts above are useful review evidence; the membership sets are
|
|
# the actual filter criterion. They intentionally include non-class skills.
|
|
dropped = [row for row in roster if not source_spell_counts[row['taught_spell']]
|
|
and not native_spell_counts[row['taught_spell']]]
|
|
keys = [(r['creature_entry'], r['class_id'], r['service_spell'], r['taught_spell']) for r in dropped]
|
|
if len(keys) != len(set(keys)):
|
|
raise ValueError('Ambiguous duplicate class trainer drop key')
|
|
dropped.sort(key=lambda row: (row['creature_entry'], row['class_id'], row['service_spell']))
|
|
return dict(policy='unassigned-source-and-native-skillline-v1',
|
|
input_sha256={str(path): digest(path) for path in
|
|
(roster_path, spell_index_path, source_spell_path,
|
|
source_sla_path, native_sla_path)},
|
|
roster_rows=len(roster), trainers=len({r['creature_entry'] for r in roster}),
|
|
service_spells=len({r['service_spell'] for r in roster}),
|
|
by_class=dict(sorted(Counter(r['class_id'] for r in roster).items())),
|
|
source_skillline_rows=len(source_abilities.rows),
|
|
native_skillline_rows=len(native_table['rows']),
|
|
drop_rows=dropped,
|
|
drop_distinct=sorted({(r['class_id'], r['service_spell'], r['taught_spell'])
|
|
for r in dropped}))
|
|
|
|
|
|
def header(report):
|
|
rows = report['drop_rows']
|
|
lines = [
|
|
'#pragma once',
|
|
'// Generated by ops/trainer_offer_audit.py from the G3 full class-trainer audit.',
|
|
'// Rule: taught spell has no SkillLineAbility row in Source or native 70334.',
|
|
f'// Source SkillLineAbility SHA256: {next(v for k,v in report["input_sha256"].items() if k.endswith("/SkillLineAbility.dbc"))}',
|
|
f'// Native SkillLineAbility SHA256: {next(v for k,v in report["input_sha256"].items() if k.endswith("/SkillLineAbility.db2"))}',
|
|
'#include <array>',
|
|
'#include <cstdint>',
|
|
'namespace gateway::trainer_offer_filter {',
|
|
'struct DropOffer {uint32_t creature_entry; uint8_t class_id; uint32_t service_spell; uint32_t taught_spell;};',
|
|
f'inline constexpr std::array<DropOffer,{len(rows)}> Drops{{{{',
|
|
]
|
|
for row in rows:
|
|
lines.append(f' {{{row["creature_entry"]}, {row["class_id"]}, {row["service_spell"]}, {row["taught_spell"]}}},')
|
|
lines += [
|
|
'}};',
|
|
'inline const DropOffer* blocked(uint32_t entry, uint8_t cls, uint32_t service) {',
|
|
' for(const auto& row:Drops)',
|
|
' if(row.creature_entry==entry && row.class_id==cls && row.service_spell==service)return &row;',
|
|
' return nullptr;',
|
|
'}',
|
|
'}',
|
|
]
|
|
return '\n'.join(lines) + '\n'
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--roster', type=Path, required=True)
|
|
parser.add_argument('--spell-index', type=Path, required=True)
|
|
parser.add_argument('--source-dbc', type=Path, required=True)
|
|
parser.add_argument('--native-sla', type=Path, required=True)
|
|
parser.add_argument('--report', type=Path, required=True)
|
|
parser.add_argument('--header', type=Path, required=True)
|
|
args = parser.parse_args()
|
|
report = audit(args.roster, args.spell_index, args.source_dbc, args.native_sla)
|
|
args.report.write_text(json.dumps(report, indent=2, ensure_ascii=False) + '\n')
|
|
args.header.write_text(header(report))
|
|
print(f'{report["roster_rows"]} class-trainer rows; {len(report["drop_rows"])} drops; '
|
|
f'{len(report["drop_distinct"])} distinct class/service/taught triples')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|