Files
WoW-Hybrid-gateway/ops/spell_affect_compat.py
praxisandClaude Fable 5.2 8a24c445b0 Content pipeline and operator tools
367 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

72 lines
3.6 KiB
Python

"""Derive modifier masks by spell identity, never by equal bit positions.
Source input must contain the complete effective spell-class inventory, and
target input the complete effective class-options inventory for the family.
Callers pin those inputs and separately review modifier enums and definitions.
This pure comparison does not install records or apply gameplay modifiers.
"""
from octo_client_data import canonical_sha256
from spell_passive_compat import integer
POLICY = 'identity-derived-source-spell-affect-mask-v1'
def derive(source, target, family, mask):
integer(family, 1, 255, 'modifier family')
integer(mask, 1, 0xffffffffffffffff, 'source affected-spell mask')
if not isinstance(source, list) or not 1 <= len(source) <= 100000:
raise ValueError('Complete bounded source spell inventory required')
if not isinstance(target, list) or not 1 <= len(target) <= 100000:
raise ValueError('Complete bounded target class inventory required')
old, new = {}, {}
for row in source:
if not isinstance(row, dict) or set(row) != {'id', 'family', 'mask'}:
raise ValueError('Typed source class identity required')
ident = integer(row['id'], 1, 0x7fffffff, 'source spell')
# Unused source rows may carry an unsigned sentinel family. Retain
# their identity for collateral-match checks; do not discard the row.
integer(row['family'], 0, 0xffffffff, 'source family')
integer(row['mask'], 0, 0xffffffffffffffff, 'source class mask')
if ident in old:
raise ValueError('Duplicate source spell identity')
old[ident] = row
for row in target:
ident = integer(row['SpellID'], 1, 0x7fffffff, 'target spell')
integer(row['SpellClassSet'], family, family, 'target family')
words = row['SpellClassMask']
if not isinstance(words, list) or len(words) != 4:
raise ValueError('Four target mask words required')
for word in words:
integer(word, -0x80000000, 0xffffffff, 'target mask word')
if ident in new:
raise ValueError('Duplicate target spell class identity')
new[ident] = sum((word & 0xffffffff) << (32*i) for i, word in enumerate(words))
wanted = {ident for ident, row in old.items()
if row['family'] == family and row['mask'] & mask}
if not wanted or not wanted <= new.keys():
raise ValueError('Affected source spells missing target class definitions')
candidates = 0
for ident in wanted:
candidates |= new[ident]
chosen, excluded = 0, []
for bit in range(128):
flag = 1 << bit
if not candidates & flag:
continue
matched = {ident for ident, value in new.items() if value & flag}
wrong = (matched & old.keys()) - wanted
if wrong:
excluded.append(dict(bit=bit, unintended_source_spell_ids=sorted(wrong)))
else:
chosen |= flag
matched = {ident for ident, value in new.items() if value & chosen}
if matched & old.keys() != wanted:
raise ValueError('No target mask represents exactly the affected source spells')
return dict(policy=POLICY, family=family, source_mask=mask,
target_mask=[(chosen >> (32*i)) & 0xffffffff for i in range(4)],
affected_source_spell_ids=sorted(wanted),
target_only_matches=sorted(matched - old.keys()),
excluded_bits=excluded, source_inventory_sha256=canonical_sha256(source),
target_inventory_sha256=canonical_sha256(target), installed=False,
gameplay_verified=False)