91 lines
4.2 KiB
Python
91 lines
4.2 KiB
Python
#!/usr/bin/env python3
|
|
"""#6 (2026-11-25): SpellXSpellVisual links for Octo spells the client can cast-render but has no link for.
|
|
|
|
Symptom: Turtle-only NPC spells such as Shoot 18561 (Barkskin Pathfinder), Throw 10277 deal damage with no draw/shoot
|
|
animation or projectile, because the codec sends SpellXSpellVisualID 0 (cast_visual_profile has no row) and the client
|
|
has no SpellXSpellVisual row of its own.
|
|
|
|
Rule, over every Octo Spell.dbc spell without a cast_visual_profile link (catalogue-wide, players and NPCs):
|
|
exact - a linked spell with the same Octo name, SpellVisual, Attributes and Effect1 -> its SpellVisualID
|
|
visual - a linked spell sharing the Octo SpellVisual (most common native visual of that 1.12 visual)
|
|
ranged - Attributes & 0x2 (ranged) with weapon-damage effect 2/58/121 -> Shoot 6660, or Throw 15795 by name
|
|
Spells whose Octo SpellVisual is 0 and match none of the above stay unlinked (no visual on Octo either).
|
|
New SpellXSpellVisual IDs from 2600000 (client rows end at 1123125). Writes <out>/SpellXSpellVisual.json (Db2Bake
|
|
addrows) and merges the links into include/gateway/cast_visual_profile.hpp.
|
|
|
|
usage: spell_visual_links.py <SpellXSpellVisual dump tsv> <out-dir> [--write-header]
|
|
"""
|
|
import collections
|
|
import json
|
|
import re
|
|
import struct
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
sys.path.insert(0, str(HERE / 'maps14-20261122'))
|
|
import octo_mpq # noqa: E402
|
|
|
|
BASE = 2600000
|
|
SHOOT, THROW = 6660, 15795
|
|
HEADER = HERE.parent / 'include/gateway/cast_visual_profile.hpp'
|
|
|
|
|
|
def main(dump, out_dir, write_header=False):
|
|
text = HEADER.read_text()
|
|
prof = {int(a): int(b) for a, b in re.findall(r'\{(\d+),(\d+)\}', text.split('Rows[]=', 1)[1].split(';', 1)[0])}
|
|
visual_of = {}
|
|
for line in open(dump):
|
|
m = re.search(r'^(\d+)\t.*\bSpellVisualID=(\d+)', line)
|
|
if m:
|
|
visual_of[int(m.group(1))] = int(m.group(2))
|
|
raw = octo_mpq.read('DBFilesClient\\Spell.dbc')
|
|
n, f, rs, _ = struct.unpack_from('<4I', raw, 4)
|
|
strings = raw[20 + n * rs:]
|
|
name = lambda o: strings[o:strings.index(b'\0', o)].decode('latin1')
|
|
spells = {}
|
|
for i in range(n):
|
|
r = struct.unpack_from('<%dI' % f, raw, 20 + i * rs)
|
|
spells[r[0]] = r
|
|
exact, by_visual = {}, collections.defaultdict(collections.Counter)
|
|
for sid, r in spells.items():
|
|
if sid in prof and prof[sid] in visual_of:
|
|
exact.setdefault((name(r[120]), r[115], r[6], r[61]), sid)
|
|
if r[115]:
|
|
by_visual[r[115]][visual_of[prof[sid]]] += 1
|
|
rows, links, plan = [], {}, collections.Counter()
|
|
for sid in sorted(spells):
|
|
if sid in prof:
|
|
continue
|
|
r = spells[sid]
|
|
key = (name(r[120]), r[115], r[6], r[61])
|
|
if key in exact:
|
|
kind, visual = 'exact', visual_of[prof[exact[key]]]
|
|
elif r[115] and r[115] in by_visual:
|
|
kind, visual = 'visual', by_visual[r[115]].most_common(1)[0][0]
|
|
elif r[6] & 2 and r[61] in (2, 58, 121):
|
|
kind, visual = 'ranged', visual_of[prof[THROW if 'throw' in name(r[120]).lower() else SHOOT]]
|
|
else:
|
|
plan['unlinked-visual' if r[115] else 'unlinked-no-octo-visual'] += 1
|
|
continue
|
|
link = BASE + len(rows)
|
|
rows.append(dict(ID=link, DifficultyID=0, SpellVisualID=visual, Probability=1.0, Priority=0, SpellID=sid))
|
|
links[sid] = link
|
|
plan[kind] += 1
|
|
out = Path(out_dir)
|
|
out.mkdir(parents=True, exist_ok=True)
|
|
(out / 'SpellXSpellVisual.json').write_text(json.dumps(rows))
|
|
(out / 'links.json').write_text(json.dumps(dict(plan=plan, links=links), indent=1))
|
|
if write_header:
|
|
merged = sorted({**prof, **links}.items())
|
|
body = ','.join('{%d,%d}' % r for r in merged)
|
|
text = re.sub(r'Rows\[\]=\{.*?\};', 'Rows[]={' + body + '};', text, count=1, flags=re.S)
|
|
if 'spell_visual_links.py' not in text:
|
|
text = text.replace('#pragma once', '// + Octo spells without links: ops/spell_visual_links.py (exact/visual/ranged donors, rows 2600000+).\n#pragma once', 1)
|
|
HEADER.write_text(text)
|
|
print(dict(plan), 'rows', len(rows))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main(sys.argv[1], sys.argv[2], '--write-header' in sys.argv)
|