Files
WoW-Hybrid-gateway/tests/hunter_aspect_rows_test.py

112 lines
5.4 KiB
Python

import copy
import json
from pathlib import Path
import struct
import sys
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'ops'))
from hunter_aspect_rows import hunter_orders, prepare
from turtle_data import DBC
ROWS = ROOT / 'ops/content-hunter-aspects-20261127'
# Octo Spell.dbc bar-marked Hunter spells grouped by the signed order on disk.
FAMILIES = {
-1: (45651,), 0: (13163,), 1: (13165, 14318, 14319, 14320, 14321, 14322, 25296),
2: (45650, 51496, 51497, 51498, 51499, 51500, 51501),
3: (5118,), 4: (13159,), 5: (13161,), 6: (20043, 20190),
}
ORDERS = {spell: (order, 0, 0) for order, family in FAMILIES.items() for spell in family}
# Selected 6838d93c SpellMisc IDs, from the LOCAL parent via DB2Gameplay.
MISC_IDS = {
5118: 318170, 13159: 323513, 13161: 324139, 13163: 324140, 13165: 323912,
14318: 325178, 14319: 325179, 14320: 325459, 14321: 325787, 14322: 325397,
20043: 329546, 20190: 330248, 25296: 333847, 45650: 871686, 45651: 871687,
51496: 871985, 51497: 871986, 51498: 871987, 51499: 871988, 51500: 871989,
51501: 871990,
}
def load(name):
return json.loads((ROWS / (name + '.json')).read_text())
def parent_misc():
return [{'ID': ident, 'SpellID': spell, 'DifficultyID': 0,
'Attributes': [0, 0, 16 if spell in FAMILIES[-1] + FAMILIES[2] else 0] + [0] * 14}
for spell, ident in sorted(MISC_IDS.items())]
class HunterAspectRowsTest(unittest.TestCase):
def test_source_filter_and_signed_order(self):
fields = {'ID': 0, 'SpellClassSet': 160, 'AttributesExB': 8, 'StanceBarOrder': 166,
'ShapeshiftMask': 11, 'ShapeshiftExclude': 12}
examples = [(spell, 9, 16, order) for spell, (order, _, _) in ORDERS.items()]
# Octo Turtle and Snake, Hawk's teaching spell and the Paladin Devotion control.
examples.extend([(45649, 9, 0, 0), (45652, 9, 0, -1), (6385, 0, 0, 0), (465, 10, 16, 0)])
data = bytearray(struct.pack('<4s4I', b'WDBC', len(examples), 173, 692, 1))
for spell, family, flags, order in examples:
row = [0] * 173
row[0], row[160], row[8], row[166] = spell, family, flags, order
data.extend(struct.pack('<173i', *row))
with tempfile.TemporaryDirectory() as temp:
file = Path(temp) / 'Spell.dbc'
file.write_bytes(data + b'\0')
self.assertEqual(hunter_orders(DBC(file, 173), fields), ORDERS)
def test_pinned_component_fixes_each_native_mismatch(self):
attrs = parent_misc()
original = copy.deepcopy(attrs)
batches = prepare(ORDERS, attrs, [])
self.assertEqual(original, attrs)
self.assertEqual(len(batches['SpellMisc.setrows']), 13)
self.assertEqual(batches['SpellShapeshift.addrows'], load('SpellShapeshift.addrows'))
self.assertEqual(batches['SpellShapeshift.setrows'], [])
# The pinned bake's full attribute words come from the real parent. This fixture
# supplies its actual flag word and checks the same IDs with all other bits preserved.
changed_ids = {row['ID'] for row in batches['SpellMisc.setrows']}
shipped = {r['ID']: r['Attributes'] for r in load('SpellMisc.setrows')}
self.assertEqual(set(shipped), changed_ids)
for row in attrs:
if row['ID'] in shipped:
self.assertEqual(shipped[row['ID']][2], row['Attributes'][2] | 16)
row['Attributes'] = shipped[row['ID']]
added = load('SpellShapeshift.addrows')
orders_by_spell = {r['SpellID']: r['StanceBarOrder'] for r in added}
for row in attrs:
self.assertTrue(row['Attributes'][2] & 16)
self.assertEqual(orders_by_spell.get(row['SpellID'], 0), ORDERS[row['SpellID']][0])
self.assertEqual(prepare(ORDERS, attrs, added),
{'SpellMisc.setrows': [], 'SpellShapeshift.setrows': [],
'SpellShapeshift.addrows': []})
def test_existing_masks_and_non_display_attribute_bits_survive(self):
misc = parent_misc()
spell = 13165
hawk = next(r for r in misc if r['SpellID'] == spell)
hawk['Attributes'] = [41, 0x80, 0x123400, 0x200] + [8] * 13
shape = {'ID': 6000, 'SpellID': spell, 'StanceBarOrder': 4,
'ShapeshiftMask': [32, 0], 'ShapeshiftExclude': [2, 0]}
batches = prepare({spell: (1, 32, 2)}, misc, [shape])
self.assertEqual(batches['SpellMisc.setrows'], [{'ID': hawk['ID'],
'Attributes': [41, 0x80, 0x123410, 0x200] + [8] * 13}])
self.assertEqual(batches['SpellShapeshift.setrows'], [{'ID': 6000, 'StanceBarOrder': 1}])
self.assertEqual(batches['SpellShapeshift.addrows'], [])
def test_ambiguous_or_incomplete_relationships_stop_generation(self):
misc = parent_misc()
with self.assertRaisesRegex(ValueError, 'Missing base SpellMisc'):
prepare(ORDERS, misc[1:], [])
with self.assertRaisesRegex(ValueError, 'one base SpellMisc'):
prepare(ORDERS, misc + [misc[0]], [])
with self.assertRaisesRegex(ValueError, 'form restrictions'):
prepare({5118: (3, 4, 0)}, misc, [])
with self.assertRaisesRegex(ValueError, 'Unavailable SpellShapeshift ID'):
prepare(ORDERS, misc, [{'ID': 2605118, 'SpellID': 75, 'StanceBarOrder': 0}])
if __name__ == '__main__':
unittest.main()