Files
WoW-Hybrid-gateway/ops/source_party_target_profile.py

42 lines
1.9 KiB
Python

#!/usr/bin/env python3
"""Source spells that buff a unit's whole party: an effect with ImplicitTarget 37
(Tortoise TARGET_UNIT_FRIEND_AND_PARTY: the target and its party). Turtle requires a
unit target for them (Prayer of Fortitude/Spirit/Shadow Protection/Healing, Gift of the
Wild, Arcane Brilliance ...). The 70334 client treats its versions as caster-party
spells and sends no unit, so the gateway supplies the current selection (or self).
usage: source_party_target_profile.py <Spell.dbc> <output.hpp>
"""
import struct
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
from turtle_data import spell_layout
FRIEND_AND_PARTY = 37
def main(source, output):
layout = spell_layout()
data = Path(source).read_bytes()
if data[:4] != b'WDBC':
raise ValueError('not a WDBC file')
count, fields, size, _ = struct.unpack_from('<4I', data, 4)
spells = []
for i in range(count):
row = struct.unpack_from('<%dI' % fields, data, 20 + i * size)
if any(row[layout['Effect'] + e] and FRIEND_AND_PARTY in (row[layout['ImplicitTargetA'] + e], row[layout['ImplicitTargetB'] + e]) for e in range(3)):
spells.append(row[0])
spells.sort()
body = ',\n'.join(','.join(map(str, spells[i:i + 16])) for i in range(0, len(spells), 16))
Path(output).write_text(f'''// Generated by ops/source_party_target_profile.py from the Source Spell.dbc; do not edit.
// Source spells with an ImplicitTarget 37 (target and its party) effect: Turtle needs a unit target.
#pragma once
#include <algorithm>
#include <array>
#include <cstdint>
namespace gateway::source_party_target_profile {{
inline constexpr std::array<uint32_t,{len(spells)}> spells{{
{body}}};
inline bool contains(uint32_t spell){{return std::binary_search(spells.begin(),spells.end(),spell);}}
}}
''')
if __name__ == '__main__':
main(*sys.argv[1:3])