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

57 lines
2.9 KiB
Python

"""Prepare family rows for existing, independently qualified spell definitions.
Rows start with no private bits. The existing additive allocator supplies them
from its globally-unused-bit witness; source bit numbers are never copied.
No DB2, provider, client or publication writes occur here.
"""
from copy import deepcopy
from warrior_cooldown_modifier import _integer, _sha
from spell_family_membership_proof import approved_membership
def prepare(source, native, closure, spell_ids, *, family_corrections=None, membership_proofs=None):
source_by_id={r["id"]:r for r in source}
if len(source_by_id)!=len(source):
raise ValueError("duplicate source spell")
rows=deepcopy(native)
ids=set();by_spell={}
for r in rows:
_integer(r["ID"],1,0x7fffffff,"native row identity")
_integer(r["SpellID"],1,0x7fffffff,"native spell identity")
if r["ID"] in ids or r["SpellID"] in by_spell:
raise ValueError("duplicate native family identity")
ids.add(r["ID"]);by_spell[r["SpellID"]]=r
if len(spell_ids)!=len(set(spell_ids)):
raise ValueError("duplicate requested identity")
corrections=dict(family_corrections or {})
next_id=max(ids,default=0)+1
changes=[];added=[];used_membership={}
for ident in sorted(spell_ids):
s=source_by_id.get(ident);proof=closure.get(ident)
if not s or s["family"] not in (3,4,5,6,7,8,9,10,11):
raise ValueError("named source class family required")
if not proof or proof.get("spell_id")!=ident or proof.get("complete") is not True:
if membership_proofs is None:
raise ValueError("independent complete spell-definition closure required")
used_membership[ident]=approved_membership(membership_proofs,ident,s["family"],proof)
r=by_spell.get(ident)
if r is None:
_integer(next_id,1,0x7fffffff,"new native row identity")
r=dict(ID=next_id,SpellID=ident,SpellClassSet=s["family"],
SpellClassMask=[0,0,0,0],ModalNextSpell=0)
changes.append(dict(id=next_id,before=None,record=deepcopy(r)))
rows.append(r);by_spell[ident]=r;added.append(next_id);next_id+=1
elif r["SpellClassSet"]!=s["family"]:
if corrections.pop(ident,None)!=r["SpellClassSet"]:
raise ValueError("explicit pinned wrong-family correction required")
before=deepcopy(r);r["SpellClassSet"]=s["family"]
changes.append(dict(id=r["ID"],before=before,record=deepcopy(r)))
if corrections:
raise ValueError("unused or stale family correction")
result=dict(rows=sorted(rows,key=lambda r:r["ID"]),changes=changes,added_ids=added,
parent_sha256=_sha(native),source_sha256=_sha(source),
source_bits_copied=False,installable=False)
if used_membership:
result["membership_proofs_used"]=used_membership
return result