Files
WoW-Hybrid-gateway/ops/spell_restore_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

165 lines
16 KiB
Python

#!/usr/bin/env python3
"""Bounded corrections for existing instant self heal/resource spell definitions.
Uses the established spell encoders and child-ID allocator. No learned-spell,
racial or talent state is manufactured. New compound slots are constant only;
a pre-existing variable heal is retained only when its source range matches.
"""
from copy import deepcopy
import hashlib,math
from octo_client_data import canonical_sha256
from spell_passive_compat import (BUILD,SCHEMA,TABLES,SUPPLEMENTAL_TABLES,CONDITIONS,
NEW_EFFECT_NEUTRAL,integer,encode,allocate,registry_values,one,
new_registry_values,verified_spell_icon)
from item_batch_stage import available_index
from spell_family_compat import validate_family
POLICY='positive-instant-self-restoration-v1'
from spell_definition_common import (REQUIRED_REFERENCE_TABLES,
checked_constant_source,review_neutral_children as review_children,
NEW_DEFINITION_CHILD_TABLES,review_new_timing,new_definition_records,review_existing_effect_range)
def existing_restoration_range(base_points,die_sides,native):
"""Review an existing range; never create rolls or modify an effect.
Source SpellMgr's $s formatter uses base+1..base+die for variable amounts.
The pinned target SpellInfo uses base*(1 +/- abs(Variance*.5)). This is
the same positive HEAL/ENERGIZE check used by the restoration converter.
"""
if native.get('Effect')not in(10,30)or native.get('EffectAura')!=0:
raise ValueError('Existing variable heal range differs')
try:return review_existing_effect_range(base_points,die_sides,native)
except ValueError:raise ValueError('Existing variable heal range differs')from None
def validate_source(src):
categories=src.get('spell_category_context')
if categories is not None:
from spell_definition_common import validate_spell_category_namespace
validate_spell_category_namespace(categories)
integer(src.get('defense_type'),0,3,'restoration defense category')
integer(src.get('prevention_type'),0,2,'restoration prevention category')
elif src.get('defense_type',0)or src.get('prevention_type',0):raise ValueError('Explicit restoration category namespace required')
integer(src['entry'],1,0x7fffffff,'restoration source ID')
for key,count in(('attributes',5),('power',6),('equippedItem',3),('visuals',2)):
if not isinstance(src.get(key),list)or len(src[key])!=count or any(type(v)is not int for v in src[key]):raise ValueError('Restoration source shape/type: '+key)
if src['attributes']not in([0]*5,[262160,0,0,0,0])or(src['castingTimeIndex'],src['durationIndex'],src['rangeIndex'],src['speed'])!=(1,0,1,0):raise ValueError('Unreviewed instant-restoration attributes/timing')
for key in('castingTimeIndex','durationIndex','rangeIndex','spellIconId'):integer(src[key],0,0x7fffffff,'source '+key)
if type(src['speed'])not in(int,float)or not math.isfinite(src['speed']):raise ValueError('Restoration source speed type')
for value in src['visuals']:integer(value,0,0x7fffffff,'source visual')
integer(src['school'],0,6,'source school')
if src['power']!=[0]*6 or src['equippedItem'][0]!=-1 or src['equippedItem'][1]not in(-1,0)or src['equippedItem'][2]!=0:raise ValueError('Restoration has costs/equipment restrictions')
if not isinstance(src.get('conditions'),dict)or set(src['conditions'])!=set(CONDITIONS):raise ValueError('Complete restoration condition metadata required')
for key,value in src['conditions'].items():integer(value,0,255 if key=='procChance'else 0,'restoration condition '+key)
if not isinstance(src.get('timing'),dict)or set(src['timing'])!={'recoveryTime','categoryRecoveryTime','startRecoveryCategory','startRecoveryTime'}:raise ValueError('Complete restoration timing metadata required')
for key,value in src['timing'].items():integer(value,0,0x7fffffff,'source '+key)
if any(src['timing'][k]for k in('recoveryTime','categoryRecoveryTime','startRecoveryTime')):raise ValueError('Restoration cooldown/GCD requires separate conversion')
if not isinstance(src.get('levels'),dict)or set(src['levels'])!={'spellLevel','baseLevel','maxLevel'}:raise ValueError('Complete restoration level metadata required')
for key,value in src['levels'].items():integer(value,0,65535,'source '+key)
for key in('name','nameSubtext','description','auraDescription'):
if not isinstance(src.get(key),str)or '\0'in src[key]or len(src[key].encode())>4096:raise ValueError('Restoration source text bound')
if not src['name']or not isinstance(src.get('effects'),list)or len(src['effects'])!=3:raise ValueError('Complete restoration source name/effects required')
active=[]
for index,effect in enumerate(src['effects']):
if not isinstance(effect,list)or len(effect)!=12 or any(type(v)not in(int,float)or not math.isfinite(v)for v in effect)or any(type(effect[i])is not int for i in(0,1,2,3,4,7,8,9,10)):raise ValueError('Source restoration effect numeric type differs')
if not effect[0]:
if effect!=[0]*11+[-1]:raise ValueError('Unreviewed empty restoration effect')
continue
if effect[0]not in(10,30)or effect[1]!=0 or effect[3]!=1 or effect[4]<0 or effect[5:7]!=[0,0]or effect[8:11]!=[1,0,0]or effect[11]not in(-1,0):raise ValueError('Unreviewed heal/energize semantics')
if(effect[0]==10 and effect[7]!=0)or(effect[0]==30 and effect[7]not in(0,1,2,3)):raise ValueError('Unreviewed restorative resource namespace')
integer(effect[2]+1,0,0xffffff,'restoration minimum');integer(effect[2]+max(1,effect[4]),effect[2]+1,0xffffff,'restoration maximum')
active.append(index)
if not active:raise ValueError('No supported restoration effect')
return active
def source_spell(dbc,raw,offsets,*,family_namespace=None,category_context=None):
src=checked_constant_source(dbc,raw,offsets,family_namespace=family_namespace,category_context=category_context)
validate_source(src)
return src
def component(sources,native,schemas,maxima,registry):
if not isinstance(sources,list)or not 1<=len(sources)<=4096 or len({s['entry']for s in sources})!=len(sources):raise ValueError('Restoration source identities/count differ')
if any(table not in native for table in REQUIRED_REFERENCE_TABLES):raise ValueError('Complete explicit native reference exports required')
registry=deepcopy(registry);occupied={r['ID']for r in native['SpellEffect']};registry_values(registry,maxima['SpellEffect'],occupied)
records=[];verification=[]
for src in sorted(sources,key=lambda s:s['entry']):
validate_source(src);validate_family(src.get('class_family'),warrior=True)
ident=src['entry'];name=one(native['SpellName'],lambda r:r['ID']==ident,'restoration SpellName');text=one(native['Spell'],lambda r:r['ID']==ident,'restoration Spell');misc=one(native['SpellMisc'],lambda r:r['SpellID']==ident,'restoration SpellMisc')
if name['Name_lang']!=src['name']:raise ValueError('Same-ID restorative name collision')
attrs=misc['Attributes']
if len(attrs)!=17 or attrs[:5]!=src['attributes']or any(v for i,v in enumerate(attrs[5:],5)if i!=15)or attrs[15]&~0x2000:raise ValueError('Native restorative attribute context differs')
if (misc['DifficultyID'],misc['CastingTimeIndex'],misc['DurationIndex'],misc['RangeIndex'],misc['SchoolMask'])!=(0,1,0,1,1<<src['school'])or any(misc[k]for k in('Speed','PvPDurationIndex','LaunchDelay','MinDuration','ActiveIconFileDataID','ContentTuningID','ShowFutureSpellPlayerConditionID','SpellVisualScript','ActiveSpellVisualScript')):raise ValueError('Native restorative school/timing context differs')
category_change=None;review_native=native
if src.get('spell_category_context')is not None:
table='SpellCategories'
if table not in schemas or canonical_sha256(schemas[table])!=SUPPLEMENTAL_TABLES[table][2]:raise ValueError('Reviewed positive restoration category schema required')
rows=[r for r in native[table]if r['SpellID']==ident]
required=src['defense_type']or src['prevention_type']or src['timing']['startRecoveryCategory']
if not rows and not required:
old=None
else:old=one(rows,lambda r:True,'positive restoration category')
# This opt-in corrects only the two source-proven categories. All
# other restrictions still pass the complete neutral-child review.
if old is not None:
new=dict(old,DefenseType=src['defense_type'],PreventionType=src['prevention_type'])
encode(old,schemas[table]);encode(new,schemas[table]);category_change=(table,old,new)
review_native=dict(native,SpellCategories=[new if r['ID']==old['ID']else r for r in native[table]])
review=review_children(review_native,src);levels=one(native['SpellLevels'],lambda r:r['SpellID']==ident,'positive restoration levels')
if levels['DifficultyID']or levels['MaxPassiveAuraLevel']:raise ValueError('Native restorative level condition differs')
effects=[r for r in native['SpellEffect']if r['SpellID']==ident];indices={i for i,e in enumerate(src['effects'])if e[0]}
if not effects or len({r['EffectIndex']for r in effects})!=len(effects)or any(r['EffectIndex']not in indices for r in effects):raise ValueError('Ambiguous/extra native restorative effects')
changes=[('Spell',text,dict(text,NameSubtext_lang=src['nameSubtext'],Description_lang=src['description'],AuraDescription_lang=src['auraDescription'])),
('SpellLevels',levels,dict(levels,MaxLevel=src['levels']['maxLevel'],BaseLevel=src['levels']['baseLevel'],SpellLevel=src['levels']['spellLevel']))]
if category_change is not None:changes.append(category_change)
for index in sorted(indices):
e=src['effects'][index];old=next((r for r in effects if r['EffectIndex']==index),None)
if old is not None:
neutral={k:v for k,v in NEW_EFFECT_NEUTRAL.items()if k not in('Effect','EffectBonusCoefficient','Variance')}
if old['Effect']!=e[0]or old['EffectAura']!=0 or any(old[k]!=v for k,v in neutral.items())or old['EffectMiscValue']!=[e[7],0]or old['EffectBonusCoefficient']!=0:raise ValueError('Native restorative effect context differs')
new=deepcopy(old)
else:
if e[4]not in(0,1):raise ValueError('New variable restore requires a reviewed variance conversion')
new=dict(NEW_EFFECT_NEUTRAL,ID=allocate(registry,ident,index,maxima['SpellEffect'],occupied),SpellID=ident,EffectIndex=index,EffectAura=0,EffectMiscValue=[e[7],0])
new.update(Effect=e[0],EffectBasePointsF=e[2]+1,Variance=0)
if e[4]not in(0,1):
existing_restoration_range(e[2],e[4],new)
else:new.update(EffectBasePointsF=e[2]+1,Variance=0)
changes.append(('SpellEffect',old,new))
for table,old,new in changes:
wire=encode(new,schemas[table])
if old is not None:
encode(old,schemas[table]);integer(old['ID'],1,maxima[table],'native restorative baseline ID')
if old==new:continue
records.append(dict(table_name=table,table_hash=hex((TABLES|SUPPLEMENTAL_TABLES)[table][0]),id=new['ID'],record=new,wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest(),source_spell_id=ident,source_effect_index=new.get('EffectIndex'),baseline_record=deepcopy(old),baseline_record_sha256=canonical_sha256(old)if old else None,changed_fields=sorted(k for k in new if old is None or old[k]!=new[k]),allocation_policy='source-derived-constant-restoration-slot'if old is None else'same-ID-source-restoration-correction'))
verification.append(dict(spell_id=ident,source_record_sha256=canonical_sha256(src),native_child_review=review,known_spells_modified=False,engine_accepted=False))
return dict(kind='source-restoration-spell-components',build=BUILD,schema=SCHEMA,definition_policy=POLICY,records=records,spells=verification,child_id_registry=registry,dependency_complete=False,installable=False,installed=False,engine_accepted=False,gameplay_verified=False,
limitations=['Positive existing same-spell context only; no new spell-parent or variable-effect definition synthesized.',
'Components do not grant spells or simulate healing/resources. Server execution remains authoritative.',
'Actual tooltip tokens, visuals, cache acceptance and restorative effects remain unverified in the client.'],
inputs=dict(sources=deepcopy(sorted(sources,key=lambda s:s['entry'])),native=deepcopy(native),schemas=deepcopy(schemas),maxima=deepcopy(maxima),registry=deepcopy(registry)))
NEW_POLICY='new-constant-restoration-definition-candidate-v1'
def new_component(sources,native,schemas,maxima,registry,*,source_tables,
target_icon_names,new_icon_ids,icon_assets,read_icon):
"""New constant restore parents; never synthesizes variable rolls or casts."""
if not isinstance(sources,list)or not 1<=len(sources)<=4096 or len({s['entry']for s in sources})!=len(sources):raise ValueError('New restoration source identities/count differ')
if any(t not in native for t in(*REQUIRED_REFERENCE_TABLES,'SpellCastTimes','SpellRange')):raise ValueError('Complete new restoration native references required')
if set(new_icon_ids)!={str(s['entry'])for s in sources}or not callable(read_icon):raise ValueError('Explicit new restorative icon identities required')
review_new_timing(source_tables,native,0);available=available_index(icon_assets);registry=deepcopy(registry)
occupied={t:{r['ID']for r in native[t]}for t in NEW_DEFINITION_CHILD_TABLES};new_registry_values(registry,maxima,occupied,tables=NEW_DEFINITION_CHILD_TABLES)
records=[];verified=[]
for src in sorted(sources,key=lambda s:s['entry']):
indices=validate_source(src);ident=src['entry']
if not isinstance(src.get('class_family'),dict):raise ValueError('Explicit source spell-family metadata required')
validate_family(src['class_family'],warrior=True)
if any(src['visuals'])or any(src['timing'].values())or src['conditions']['procChance']not in(0,101):raise ValueError('Unreviewed new restoration visual/timing/chance conditions')
for t in REQUIRED_REFERENCE_TABLES:
if any((r.get('ID')if t in('Spell','SpellName')else r.get('SpellID'))==ident for r in native[t]):raise ValueError('New restoration has positive native reference: '+t)
if any(src['effects'][i][4]not in(0,1)for i in indices):raise ValueError('New variable restoration requires separate conversion')
fid,asset=verified_spell_icon(src,new_icon_ids,source_tables['SpellIcon'],target_icon_names,available,read_icon)
effects={i:dict(deepcopy(NEW_EFFECT_NEUTRAL),Effect=src['effects'][i][0],EffectAura=0,EffectBasePointsF=src['effects'][i][2]+1,EffectMiscValue=[src['effects'][i][7],0])for i in indices}
records.extend(new_definition_records(src,effects,fid,schemas,maxima,registry,occupied,allocation_prefix='new-source-restoration-definition'))
verified.append(dict(spell_id=ident,source_record_sha256=canonical_sha256(src),class_family=deepcopy(src['class_family']),levels=deepcopy(src['levels']),effect_indices=indices,icon_asset=dict(file_data_id=fid,**asset),known_spells_modified=False,installed_definition_absence_verified=False,engine_accepted=False,gameplay_verified=False))
return dict(kind='source-restoration-definition-candidates',build=BUILD,schema=SCHEMA,definition_policy=NEW_POLICY,records=records,spells=verified,child_id_registry=registry,installable=False,installed=False,dependency_complete=False,engine_accepted=False,gameplay_verified=False,limitations=['Constant instant self HEAL/ENERGIZE only; no variable roll, cast, cooldown, aura, proc or visual synthesized.','Source family and IDs preserved, without learned/racial/skill-line/talent state changes.','Filtered absence and neutral higher attributes are candidates, not original-client API or cache acceptance evidence.','Actual tooltip parsing and server-authoritative restoration remain unverified.'])