367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
110 lines
8.9 KiB
Python
110 lines
8.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Source-backed aura effect-mask admission for named threat/block/proc families.
|
|
|
|
This changes presentation admission only. It never creates spells, enables extra
|
|
native effects, changes server mechanics or claims native aura UI acceptance.
|
|
"""
|
|
import re
|
|
|
|
POLICY='named-source-threat-block-proc-effect-mask-v1'
|
|
NAMES=('SPELL_AURA_MOD_THREAT','SPELL_AURA_PROC_TRIGGER_DAMAGE','SPELL_AURA_MOD_BLOCK_PERCENT')
|
|
|
|
def enum_witness(text):
|
|
out={}
|
|
for name in NAMES:
|
|
matches=re.findall(r'(?m)^[ \t]*'+re.escape(name)+r'[ \t]*=[ \t]*(\d+)[ \t]*,',text)
|
|
if len(matches)!=1:raise ValueError('Unique named aura enum required: '+name)
|
|
value=int(matches[0])
|
|
if not 0<value<1024:raise ValueError('Aura enum out of range')
|
|
out[name]=value
|
|
if len(set(out.values()))!=len(out):raise ValueError('Ambiguous named aura namespace')
|
|
return out
|
|
|
|
def namespace(source_text,target_text):
|
|
return {'source':enum_witness(source_text),'target':enum_witness(target_text)}
|
|
|
|
def _namespace(proof):
|
|
if not isinstance(proof,dict) or set(proof)!={'source','target'}:raise ValueError('Exact named namespace proof required')
|
|
for side in ('source','target'):
|
|
values=proof[side]
|
|
if set(values)!=set(NAMES) or any(type(v)is not int or not 0<v<1024 for v in values.values()) or len(set(values.values()))!=len(NAMES):raise ValueError('Invalid named namespace witness')
|
|
return {proof['source'][name]:proof['target'][name] for name in NAMES}
|
|
|
|
def effective_table(native_rows,package_rows,table):
|
|
"""Apply only valid overlays; tombstones need a separately reviewed policy."""
|
|
if table not in ('SpellEffect','Spell','SpellName') or not isinstance(native_rows,list) or not isinstance(package_rows,list) or max(len(native_rows),len(package_rows))>500000:raise ValueError('Bounded supported native table required')
|
|
by_id={}
|
|
for row in native_rows:
|
|
if not isinstance(row,dict) or type(row.get('ID'))is not int or row['ID']<0 or row['ID'] in by_id:raise ValueError('Unique typed native identity required')
|
|
by_id[row['ID']]=dict(row)
|
|
seen_overlay=set()
|
|
for overlay in package_rows:
|
|
if not isinstance(overlay,dict):raise ValueError('Typed package row required')
|
|
if overlay.get('table_name')!=table:continue
|
|
if overlay.get('record_status','valid')!='valid':raise ValueError('Nonvalid relevant overlay status requires separate review')
|
|
row=overlay.get('record')
|
|
if type(overlay.get('id'))is not int or not isinstance(row,dict) or type(row.get('ID'))is not int or row['ID']!=overlay['id'] or row['ID']<0:raise ValueError('Overlay native row identity differs')
|
|
if row['ID'] in seen_overlay:raise ValueError('Duplicate relevant overlay row identity')
|
|
seen_overlay.add(row['ID']);by_id[row['ID']]=dict(row)
|
|
return list(by_id.values())
|
|
|
|
def generate(source,native,*,enum_proof,native_parent_ids):
|
|
mapping=_namespace(enum_proof)
|
|
if not isinstance(native_parent_ids,(set,frozenset)) or len(native_parent_ids)>500000 or any(type(i)is not int or not 0<i<=2147483647 for i in native_parent_ids):raise ValueError('Typed native Spell/SpellName parent identity set required')
|
|
if not isinstance(source,list) or len(source)>100000 or not isinstance(native,list) or len(native)>500000:raise ValueError('Bounded source/native inventories required')
|
|
by_spell={};native_ids=set()
|
|
for row in native:
|
|
if not isinstance(row,dict) or any(type(row.get(k))is not int for k in ('ID','SpellID','DifficultyID','EffectIndex','Effect','EffectAura')):raise ValueError('Typed native effect projection required')
|
|
if row['ID'] in native_ids:raise ValueError('Duplicate effective native row ID')
|
|
native_ids.add(row['ID'])
|
|
if not 0<=row['EffectIndex']<32 or row['DifficultyID']<0:raise ValueError('Native effect index/difficulty invalid')
|
|
if row['DifficultyID']==0:by_spell.setdefault(row['SpellID'],{}).setdefault(row['EffectIndex'],[]).append(row)
|
|
seen=set();definitions=[];excluded=[];eligible=0
|
|
for row in source:
|
|
if not isinstance(row,dict) or type(row.get('entry'))is not int or not 0<row['entry']<=2147483647 or row['entry'] in seen:raise ValueError('Unique typed source spell ID required')
|
|
sid=row['entry'];seen.add(sid)
|
|
keys=[k+str(i) for i in range(1,4) for k in ('effect','effectApplyAuraName')]
|
|
if any(type(row.get(k))is not int or not 0<=row[k]<=65535 for k in keys):raise ValueError('Typed source effect shape required')
|
|
if not any(row['effect'+str(i)]==6 and row['effectApplyAuraName'+str(i)] in mapping for i in range(1,4)):continue
|
|
eligible+=1
|
|
def hold(reason):excluded.append({'spell':sid,'reason':reason})
|
|
if sid not in native_parent_ids:hold('same-ID native Spell/SpellName parent missing');continue
|
|
if any(row['effect'+str(i)] not in (0,6) for i in range(1,4)):hold('source has non-aura execution dependency');continue
|
|
indices=[i-1 for i in range(1,4) if row['effect'+str(i)]==6]
|
|
if not indices:hold('source has no active aura holder');continue
|
|
if any(row['effectApplyAuraName'+str(i+1)] not in mapping for i in indices):hold('source mixes an unreviewed aura family');continue
|
|
if any(row['effect'+str(i)]==0 and row['effectApplyAuraName'+str(i)]!=0 for i in range(1,4)):hold('inactive source effect carries an ambiguous aura kind');continue
|
|
native_rows=by_spell.get(sid,{})
|
|
if any(len(native_rows.get(i,[]))!=1 for i in indices):hold('same-ID native effect index missing or ambiguous');continue
|
|
if any(native_rows[i][0]['Effect']!=6 or native_rows[i][0]['EffectAura']!=mapping[row['effectApplyAuraName'+str(i+1)]] for i in indices):hold('named source/native aura kind mismatch');continue
|
|
definitions.append({'spell':sid,'active_flags':sum(1<<i for i in indices),'source_effect_indices':indices,'source_aura_types':[row['effectApplyAuraName'+str(i+1)] for i in indices],'native_aura_types':[native_rows[i][0]['EffectAura'] for i in indices],'native_effect_ids':[native_rows[i][0]['ID'] for i in indices],'excluded_native_only_indices':sorted(set(native_rows)-set(indices))})
|
|
return {'policy':POLICY,'native_parent_ids':sorted(native_parent_ids&seen),'enum_proof':{k:dict(v) for k,v in enum_proof.items()},'definitions':sorted(definitions,key=lambda x:x['spell']),'excluded':sorted(excluded,key=lambda x:x['spell']),'counts':{'source_rows':len(source),'family_candidates':eligible,'supported':len(definitions),'held':len(excluded)},'limits':['Mask admission only; existing same-ID native Spell definitions are required.','Source indices only; extra native effects are excluded.','No server mechanic/proc/visual/visible aura acceptance claimed.']}
|
|
|
|
def extend(profile,review):
|
|
if review.get('policy')!=POLICY:raise ValueError('Wrong named-family review policy')
|
|
mapping=_namespace(review.get('enum_proof'));rows={};original=[]
|
|
for row in profile['definitions']:
|
|
sid=row['spell'];mask=row['active_flags']
|
|
if type(sid)is not int or type(mask)is not int or not 0<mask<256 or sid in rows:raise ValueError('Unique existing aura masks required')
|
|
rows[sid]=dict(row);original.append((sid,mask))
|
|
conflicts=[];added=[];proposed=set()
|
|
for row in review['definitions']:
|
|
required={'spell','active_flags','source_effect_indices','source_aura_types','native_aura_types','native_effect_ids','excluded_native_only_indices'}
|
|
if set(row)!=required:raise ValueError('Exact reviewed family projection required')
|
|
sid=row['spell'];mask=row['active_flags'];indices=row['source_effect_indices']
|
|
if sid in proposed:raise ValueError('Duplicate proposed source spell')
|
|
proposed.add(sid)
|
|
if sid not in review.get('native_parent_ids',[]):raise ValueError('Same-ID native parent proof missing')
|
|
if type(sid)is not int or not 0<sid<=2147483647 or not isinstance(indices,list) or not indices or any(type(i)is not int or not 0<=i<3 for i in indices) or indices!=sorted(set(indices)) or type(mask)is not int or mask!=sum(1<<i for i in indices):raise ValueError('Source-only effect mask changed')
|
|
if any(not isinstance(row[k],list) or len(row[k])!=len(indices) for k in ['source_aura_types','native_aura_types','native_effect_ids']):raise ValueError('Incomplete effect mapping proof')
|
|
if any(type(a)is not int or a not in mapping or type(b)is not int or mapping[a]!=b for a,b in zip(row['source_aura_types'],row['native_aura_types'])):raise ValueError('Named aura mapping changed')
|
|
if any(type(i)is not int or i<=0 for i in row['native_effect_ids']) or len(set(row['native_effect_ids']))!=len(indices):raise ValueError('Native row identity proof changed')
|
|
extra=row['excluded_native_only_indices']
|
|
if not isinstance(extra,list) or any(type(i)is not int or not 0<=i<32 or i in indices for i in extra) or extra!=sorted(set(extra)):raise ValueError('Native-only effect exclusion changed')
|
|
if sid in rows:
|
|
if rows[sid]['active_flags']!=mask:conflicts.append({'spell':sid,'retained_mask':rows[sid]['active_flags'],'proposed_mask':mask})
|
|
else:rows[sid]=dict(row);added.append(sid)
|
|
result=dict(profile);result['definitions']=[rows[sid] for sid in sorted(rows)]
|
|
if any(rows[sid]['active_flags']!=mask for sid,mask in original):raise ValueError('Existing mask changed')
|
|
return result,{'added':added,'conflicts':conflicts,'retained':len(original)}
|