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

53 lines
2.6 KiB
Python

"""Partition a complete source target inventory by modifier applicability.
Each output group can receive one unused native family bit. This establishes
membership only: definition closure, wire coherence, effect timing, operation
mapping and mixed-kind arithmetic must be qualified separately.
"""
from collections import defaultdict
def partition(targets, modifiers, *, family):
if type(family) is not int or not 3 <= family <= 11:
raise ValueError('named class family required')
predicates = set()
for modifier in modifiers:
if modifier['family'] != family:
continue
op, aura, mask = (modifier[k] for k in ('operation', 'aura', 'application_mask'))
exception = modifier.get('arcane_icon_exception', False)
if (type(op) is not int or not 0 <= op <= 33 or
aura not in (107, 108) or type(mask) is not int or
not 0 < mask < 1 << 64 or type(exception) is not bool):
raise ValueError('invalid effective modifier predicate')
if exception and (family != 3 or op != 15):
raise ValueError('unsupported source applicability exception')
predicates.add((op, aura, mask, exception))
predicates = sorted(predicates)
groups = defaultdict(list)
seen = set()
for target in targets:
ident = target['id']
if type(ident) is not int or ident <= 0 or ident in seen:
raise ValueError('unique positive target identities required')
seen.add(ident)
if target['family'] != family:
continue
mask = target['mask']
if type(mask) is not int or not 0 <= mask < 1 << 64:
raise ValueError('source target mask must be uint64')
if any(p[3] for p in predicates) and type(target.get('school')) is not int:
raise ValueError('effective school required for icon exception')
signature = tuple(index for index, (_, _, application, exception) in
enumerate(predicates) if mask & application or
(exception and target['school'] == 6))
if signature:
groups[signature].append(ident)
return dict(family=family,
predicates=[dict(operation=o, aura=a, application_mask=m,
arcane_icon_exception=e) for o, a, m, e in predicates],
groups=sorted((dict(spell_ids=sorted(ids), responses=list(signature))
for signature, ids in groups.items()),
key=lambda group: group['spell_ids']),
installable=False)