367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
547 lines
53 KiB
Python
547 lines
53 KiB
Python
"""Offline source item-proc definitions; no client roll, cast or learned state.
|
|
|
|
Initial policy: passive self proc auras using named direct-combat events and
|
|
already-converted constant restorative trigger definitions. Other mechanics fail
|
|
closed. Candidates are not installable without independent API/cache review.
|
|
"""
|
|
from copy import deepcopy
|
|
import hashlib
|
|
from octo_client_data import canonical_sha256
|
|
from spell_definition_common import (checked_constant_source,review_effect_shape,review_proc_conditions,
|
|
REQUIRED_REFERENCE_TABLES,NEW_DEFINITION_CHILD_TABLES,new_definition_records,review_new_timing)
|
|
from spell_family_compat import validate_family
|
|
from spell_passive_compat import (BUILD,SCHEMA,TABLES,SUPPLEMENTAL_TABLES,NEW_EFFECT_NEUTRAL,
|
|
CHILD_NEUTRAL,NEW_MISC_NEUTRAL,encode,integer,new_registry_values,verified_spell_icon)
|
|
from item_batch_stage import available_index
|
|
from spell_restore_compat import validate_source as validate_restore
|
|
|
|
POLICY='new-passive-direct-combat-proc-definition-candidate-v2'
|
|
EXTRA_ATTACK_POLICY='new-passive-melee-extra-attack-proc-definition-v1'
|
|
PRESENTED_POLICY='new-passive-named-presentation-proc-definition-v1'
|
|
CHILD_TABLES=NEW_DEFINITION_CHILD_TABLES+('SpellAuraOptions',)
|
|
|
|
def presentation_namespace(source_defines,target_defines):
|
|
"""Prove four passive/visibility/ability flags, independently of spell IDs."""
|
|
import re
|
|
from pathlib import Path
|
|
from spell_extra_attack_compat import HEADERS
|
|
proof=_presentation_contract()
|
|
for role,path in (('source',source_defines),('target',target_defines)):
|
|
raw=Path(path).read_bytes()
|
|
if hashlib.sha256(raw).hexdigest()!=HEADERS[role]:raise ValueError('Pinned passive proc presentation header changed')
|
|
text=re.sub(r'/\*.*?\*/|//[^\n]*','',raw.decode(),flags=re.S)
|
|
for flag in proof['flags']:
|
|
if not re.search(r'\b'+flag[role]+r'\s*=\s*0x'+format(flag['value'],'08X')+r'\s*,',text,re.I):raise ValueError('Named passive proc presentation flag differs')
|
|
return proof
|
|
|
|
def _presentation_contract():
|
|
from spell_extra_attack_compat import HEADERS
|
|
return dict(policy='named-passive-proc-ability-and-visibility-v1',header_sha256=dict(HEADERS),
|
|
flags=[dict(source=a,target=b,value=v)for a,b,v in (
|
|
('SPELL_ATTR_IS_ABILITY','SPELL_ATTR0_IS_ABILITY',16),
|
|
('SPELL_ATTR_PASSIVE','SPELL_ATTR0_PASSIVE',64),
|
|
('SPELL_ATTR_HIDDEN_CLIENTSIDE','SPELL_ATTR0_DO_NOT_DISPLAY_SPELLBOOK_AURA_ICON_COMBAT_LOG',128),
|
|
('SPELL_ATTR_HIDE_IN_COMBAT_LOG','SPELL_ATTR0_DO_NOT_LOG',256))])
|
|
|
|
def validate_presentation_namespace(proof):
|
|
if not isinstance(proof,dict)or proof!=_presentation_contract()or any(type(f.get('value'))is not int for f in proof.get('flags',[])):
|
|
raise ValueError('Verified named passive proc presentation namespace required')
|
|
|
|
def source_spell(dbc,raw,offsets,*,family_namespace,proc_proof,presentation_context=None,category_context=None,incoming_harmful=False):
|
|
return checked_constant_source(dbc,raw,offsets,family_namespace=family_namespace,proc_namespace_proof=proc_proof,passive_proc_presentation=presentation_context,category_context=category_context,incoming_harmful_proc=incoming_harmful)
|
|
|
|
def validate_source(src,proof,*,extra_attack_proof=None,constant_coefficient=False,existing_restoration=False,incoming_harmful=False):
|
|
if type(constant_coefficient)is not bool or type(existing_restoration)is not bool:raise ValueError('Typed coefficient/context review required')
|
|
extra=extra_attack_proof is not None
|
|
if extra and existing_restoration:raise ValueError('Distinct proc trigger mechanics required')
|
|
category=src.get('spell_category_context')
|
|
if category is not None:
|
|
from spell_definition_common import validate_spell_category_namespace
|
|
validate_spell_category_namespace(category)
|
|
integer(src.get('defense_type'),0,3,'proc defense category')
|
|
integer(src.get('prevention_type'),0,2,'proc prevention category')
|
|
if extra or existing_restoration:raise ValueError('Separate categorized proc mechanic review required')
|
|
elif src.get('defense_type',0)or src.get('prevention_type',0):raise ValueError('Proc category namespace missing')
|
|
if extra:
|
|
from spell_extra_attack_compat import validate_namespace
|
|
validate_namespace(extra_attack_proof)
|
|
integer(src.get('entry'),1,0x7fffffff,'proc source ID')
|
|
for key,count in(('attributes',5),('power',6),('equippedItem',3),('visuals',2)):
|
|
values=src.get(key)
|
|
if not isinstance(values,list)or len(values)!=count or any(type(v)is not int for v in values):raise ValueError('Typed source definition scalar group required')
|
|
integer(src.get('school'),0,6,'source school')
|
|
if type(src.get('speed'))not in(int,float):raise ValueError('Typed source speed required')
|
|
allowed_attrs=([64,0,0,0,0],[192,0,0,0,0])if extra else([192,0,0,0,0],)
|
|
presentation=src.get('passive_proc_presentation')
|
|
if presentation is not None:
|
|
validate_presentation_namespace(presentation)
|
|
if extra or existing_restoration:raise ValueError('Distinct passive proc presentation context required')
|
|
allowed_attrs=tuple([192|flags,0,0,0,0]for flags in(0,16,256,272))
|
|
school=src['school']if existing_restoration else 0
|
|
equipped=([-1,0,0],[-1,-1,0])if existing_restoration else([-1,0,0],)
|
|
if src.get('attributes')not in allowed_attrs or(src.get('school'),src.get('speed'),src.get('castingTimeIndex'),src.get('durationIndex'),src.get('rangeIndex'))!=(school,0,1,21,1)or src.get('equippedItem')not in equipped:raise ValueError('Unreviewed passive proc metadata')
|
|
if not isinstance(src.get('class_family'),dict):raise ValueError('Explicit proc family required')
|
|
family=validate_family(src['class_family'],warrior=True)
|
|
if extra or existing_restoration:
|
|
if family:raise ValueError('Generic existing proc family required')
|
|
if not isinstance(src.get('levels'),dict)or set(src['levels'])!={'spellLevel','baseLevel','maxLevel'}:raise ValueError('Complete existing proc levels required')
|
|
for value in src['levels'].values():integer(value,0,65535,'existing proc level')
|
|
if not isinstance(src.get('timing'),dict)or set(src['timing'])!={'recoveryTime','categoryRecoveryTime','startRecoveryCategory','startRecoveryTime'}:raise ValueError('Complete existing proc timing required')
|
|
for key,value in src['timing'].items():integer(value,0,65535 if existing_restoration and key=='startRecoveryCategory'else 0,'existing proc cooldown/category')
|
|
elif src.get('levels')!={'spellLevel':0,'baseLevel':0,'maxLevel':0}:raise ValueError('Unreviewed proc level')
|
|
if src.get('power')!=[0]*6 or any(src.get('visuals',[1]))or any(v for k,v in src.get('timing',{'missing':1}).items()if not(existing_restoration and k=='startRecoveryCategory')):raise ValueError('Unreviewed proc cost/timing/visuals')
|
|
for key in('name','nameSubtext','description','auraDescription'):
|
|
v=src.get(key)
|
|
if not isinstance(v,str)or '\0'in v or len(v.encode())>4096:raise ValueError('Proc source text bound')
|
|
if not src['name']:raise ValueError('Proc source name missing')
|
|
conditions=src.get('conditions')
|
|
if not isinstance(conditions,dict)or set(conditions)!=set(CHILD_CONDITIONS):raise ValueError('Complete proc conditions required')
|
|
if any(value for key,value in conditions.items()if key not in('procFlags','procChance','procCharges')):raise ValueError('Unreviewed proc restrictions')
|
|
raw=dict(entry=src['entry'],**conditions);disk=[0]*173;disk[0]=src['entry'];disk[1:4]=[conditions[k]for k in('procFlags','procChance','procCharges')]
|
|
context=review_proc_conditions(raw,disk,dict(ProcFlags=1,ProcChance=2,ProcCharges=3),proof,incoming_harmful=incoming_harmful)
|
|
if extra and (not conditions['procFlags']or conditions['procFlags']&~20):raise ValueError('Extra-attack proc requires named outgoing melee events')
|
|
if src.get('proc_context')!=context:raise ValueError('Normalized proc condition proof differs')
|
|
effects=src.get('effects')
|
|
if not isinstance(effects,list)or len(effects)!=3:raise ValueError('Complete proc effect slots required')
|
|
indices=[]
|
|
for i,e in enumerate(effects):
|
|
review_effect_shape(e)
|
|
if not e[0]:
|
|
if any(e[:11])or e[11]not in(-1,0):raise ValueError('Nonneutral unused proc slot')
|
|
continue
|
|
if e[:2]!=[6,42]or e[3]not in(0,1)or e[4]not in(0,1)or e[5:10]!=[0,0,0,1,0]or e[11]not in((-1,0,1)if constant_coefficient else(-1,0)):raise ValueError('Unreviewed proc trigger effect')
|
|
integer(e[2],-1,0x7ffffffe,'proc source magnitude');integer(e[10],1,0x7fffffff,'proc trigger ID');indices.append(i)
|
|
if not indices:raise ValueError('Missing proc trigger effects')
|
|
return indices,context
|
|
|
|
# Keep the original shared condition names; no narrower normalized dict accepted.
|
|
from spell_passive_compat import CONDITIONS as CHILD_CONDITIONS
|
|
|
|
def review_trigger(ident,source,records,schemas,*,native,source_tables,visual_links,extra_attack_proof=None,proc_proof=None):
|
|
if not isinstance(source,dict)or source.get('entry')!=ident:raise ValueError('Source trigger definition required')
|
|
timed=any(e[0]==6 for e in source.get('effects',[]))
|
|
defensive=source.get('defensive_context')is not None
|
|
reflection=source.get('reflection_context')is not None
|
|
extra=any(e[0]==19 for e in source.get('effects',[]))
|
|
if reflection and(defensive or extra):raise ValueError('Separate reflection trigger mechanic required')
|
|
visual=visual_links.get(ident)
|
|
visual_records=[]
|
|
if extra:
|
|
from spell_extra_attack_compat import validate_source as validate_extra,validate_namespace
|
|
validate_namespace(extra_attack_proof)
|
|
if source.get('extra_attack_semantics')!=extra_attack_proof:raise ValueError('Trigger extra-attack namespace differs')
|
|
indices=validate_extra(source)
|
|
if source['visuals'][0]:
|
|
from spell_visual_compat import review_candidate
|
|
if not isinstance(visual,dict)or visual.get('kind')!='source-owned-extra-attack-visual-dependency':raise ValueError('Explicit extra-attack trigger visual required')
|
|
candidate=review_candidate(visual.get('visual_candidate'),schemas,{t:{r['ID']for r in native[t]}for t in('SpellVisual','SpellVisualEvent')})
|
|
if candidate['kind']!='source-owned-visual-definition-candidates':raise ValueError('Extra-attack trigger requires the reviewed cast/impact visual family')
|
|
if candidate['source_visual_id']!=source['visuals'][0]:raise ValueError('Trigger source visual identity differs')
|
|
link=visual.get('record',{}).get('record',{})
|
|
expected=dict(ID=link.get('ID'),DifficultyID=0,SpellVisualID=candidate['native_visual_id'],Probability=1,Flags2=0,Priority=1,SpellIconFileID=0,ActiveIconFileID=0,ViewerUnitConditionID=0,ViewerPlayerConditionID=0,CasterUnitConditionID=0,CasterPlayerConditionID=0,SpellID=ident)
|
|
if link!=expected:raise ValueError('Conditional or incorrect extra-attack visual link')
|
|
visual_records=[r for r in records if r.get('source_visual_id')==candidate['source_visual_id']]
|
|
if visual_records!=candidate['records']:raise ValueError('Complete extra-attack visual records required')
|
|
elif visual is not None:raise ValueError('Unexpected neutral extra-attack visual')
|
|
elif extra_attack_proof is not None:raise ValueError('Extra-attack proc has an unrelated trigger mechanic')
|
|
elif reflection:
|
|
from spell_reflection_compat import validate_source as validate_reflection,review_visual
|
|
from spell_definition_common import review_duration_reference
|
|
indices,reflection_context=validate_reflection(source,proc_proof)
|
|
if source['visuals'][0]:review_visual(source,visual,schemas['SpellXSpellVisual'])
|
|
elif visual is not None:raise ValueError('Unexpected neutral reflection trigger visual')
|
|
if 'SpellDuration'not in source_tables or 'SpellDuration'not in native:raise ValueError('Reflection trigger duration references required')
|
|
duration=review_duration_reference(source_tables['SpellDuration'],native['SpellDuration'],source['durationIndex'])
|
|
if duration['duration_ms']<=0 or duration['duration_ms']!=duration['max_duration_ms']:raise ValueError('Reflection trigger requires fixed finite duration')
|
|
elif timed:
|
|
from spell_timed_buff_compat import validate_source as validate_timed
|
|
from spell_definition_common import review_duration_reference
|
|
indices=validate_timed(source,visual_link=visual,defensive=defensive)
|
|
if 'SpellDuration'not in source_tables or 'SpellDuration'not in native:raise ValueError('Timed trigger duration references required')
|
|
duration=review_duration_reference(source_tables['SpellDuration'],native['SpellDuration'],source['durationIndex'])
|
|
if duration['duration_ms']<=0 or duration['duration_ms']!=duration['max_duration_ms']:raise ValueError('Timed trigger requires fixed finite duration')
|
|
if visual is not None and visual.get('visual_candidate')is not None:
|
|
from spell_visual_compat import review_candidate
|
|
candidate=review_candidate(visual['visual_candidate'],schemas,{})
|
|
if candidate['kind']!='source-owned-state-visual-candidate':raise ValueError('Mapped haste trigger requires the reviewed hand-state visual family')
|
|
graph_tables={r['table_name']for r in candidate['records']}
|
|
visual_records=[r for r in records if r.get('source_visual_id')==candidate['source_visual_id']and r.get('table_name')in graph_tables]
|
|
if visual_records!=candidate['records']:raise ValueError('Complete mapped haste visual dependencies required')
|
|
else:
|
|
if visual is not None:raise ValueError('Unexpected restoration trigger visual')
|
|
indices=validate_restore(source)
|
|
rows={};seen=set()
|
|
for row in records:
|
|
if row.get('source_spell_id')!=ident:continue
|
|
table=row.get('table_name');record=row.get('record');key=(table,row.get('id'))
|
|
allowed={'Spell','SpellName',*NEW_DEFINITION_CHILD_TABLES,'SpellXSpellVisual'}
|
|
if reflection:allowed.add('SpellAuraOptions')
|
|
if source.get('spell_category_context')is not None:allowed.add('SpellCategories')
|
|
if table not in schemas or table not in allowed or not isinstance(record,dict)or key in seen or row.get('record_status','valid')!='valid':raise ValueError('Ambiguous trigger dependency')
|
|
seen.add(key);wire=encode(record,schemas[table])
|
|
if row.get('table_hash')!=hex((TABLES|SUPPLEMENTAL_TABLES)[table][0])or row.get('wire_hex')!=wire.hex()or row.get('sha256')!=hashlib.sha256(wire).hexdigest()or record.get('ID')!=row['id']or(record['ID']if table in('Spell','SpellName')else record.get('SpellID'))!=ident:raise ValueError('Trigger dependency wire/identity differs')
|
|
rows.setdefault(table,[]).append(record)
|
|
for table in('Spell','SpellName','SpellMisc','SpellEquippedItems'):
|
|
if len(rows.get(table,[]))!=1:raise ValueError('Complete trigger parents/children required')
|
|
family=validate_family(source.get('class_family'),warrior=True)
|
|
required={'Spell','SpellName','SpellMisc','SpellEquippedItems','SpellEffect'}
|
|
if visual is not None:required.add('SpellXSpellVisual')
|
|
if family:required.add('SpellClassOptions')
|
|
if any(source['levels'].values()):required.add('SpellLevels')
|
|
if source.get('spell_category_context')is not None:required.add('SpellCategories')
|
|
if reflection:required.add('SpellAuraOptions')
|
|
if set(rows)!=required or any(len(v)!=1 for k,v in rows.items()if k!='SpellEffect'):raise ValueError('Complete trigger dependency set differs')
|
|
def same(table,values):
|
|
actual=rows[table][0]
|
|
if actual!=dict(values,ID=actual['ID']):raise ValueError('Trigger source child semantics differ: '+table)
|
|
same('SpellName',dict(Name_lang=source['name']))
|
|
same('Spell',dict(NameSubtext_lang=source['nameSubtext'],Description_lang=source['description'],AuraDescription_lang=source['auraDescription']))
|
|
misc=rows['SpellMisc'][0]
|
|
same('SpellMisc',dict(NEW_MISC_NEUTRAL,SpellID=ident,Attributes=source['attributes']+[0]*12,SpellIconFileDataID=misc['SpellIconFileDataID'],DurationIndex=source['durationIndex'],SchoolMask=1<<source['school']))
|
|
same('SpellEquippedItems',dict(SpellID=ident,EquippedItemClass=source['equippedItem'][0],EquippedItemSubclass=source['equippedItem'][1],EquippedItemInvTypes=source['equippedItem'][2]))
|
|
if family:same('SpellClassOptions',dict(SpellID=ident,ModalNextSpell=0,SpellClassSet=family,SpellClassMask=[0]*4))
|
|
if 'SpellLevels'in required:same('SpellLevels',dict(CHILD_NEUTRAL['SpellLevels'],SpellID=ident,SpellLevel=source['levels']['spellLevel'],BaseLevel=source['levels']['baseLevel'],MaxLevel=source['levels']['maxLevel']))
|
|
if 'SpellCategories'in required:
|
|
categories=dict(CHILD_NEUTRAL['SpellCategories'],SpellID=ident,DefenseType=source['defense_type'],PreventionType=source['prevention_type'])
|
|
if reflection:categories['DispelType']=source['dispel_type']
|
|
same('SpellCategories',categories)
|
|
if reflection:
|
|
same('SpellAuraOptions',dict(CHILD_NEUTRAL['SpellAuraOptions'],SpellID=ident,
|
|
ProcTypeMask=reflection_context['target_proc_type_mask']if reflection_context else[0,0],
|
|
ProcChance=source['conditions']['procChance'],ProcCharges=source['conditions']['procCharges']))
|
|
if visual is not None and rows['SpellXSpellVisual']!=[visual['record']['record']]:raise ValueError('Timed trigger visual link differs')
|
|
effects=rows.get('SpellEffect',[])
|
|
if len(effects)!=len(indices)or {r['EffectIndex']for r in effects}!=set(indices):raise ValueError('Complete trigger effects required')
|
|
for row in effects:
|
|
e=source['effects'][row['EffectIndex']]
|
|
aura=e[1]if defensive or reflection else 138 if timed else 0
|
|
expected=dict(NEW_EFFECT_NEUTRAL,ID=row['ID'],SpellID=ident,EffectIndex=row['EffectIndex'],Effect=e[0],EffectAura=aura,EffectBasePointsF=e[2]+1,EffectMiscValue=[e[7],0])
|
|
if reflection:expected['EffectAmplitude']=source['effect_value_multipliers'][row['EffectIndex']]
|
|
if e[4]not in(0,1)or row!=expected:raise ValueError('Trigger restorative semantics differ')
|
|
return dict(source_spell_id=ident,definition_family='finite-self-school-reflection'if reflection else'finite-self-physical-reduction-defense'if defensive else'constant-self-extra-attack'if extra else'finite-self-melee-haste'if timed else'constant-restoration',source_sha256=canonical_sha256(source),record_sha256=[canonical_sha256(r)for r in records if r.get('source_spell_id')==ident]+[canonical_sha256(r)for r in visual_records],engine_acceptance_required=True)
|
|
|
|
def new_component(sources,native,schemas,maxima,registry,*,proc_proof,trigger_sources,trigger_records,proc_overrides,
|
|
source_tables,target_icon_names,new_icon_ids,icon_assets,read_icon,trigger_visual_links=None,extra_attack_proof=None,incoming_harmful=False):
|
|
if not isinstance(sources,list)or not 1<=len(sources)<=4096 or len({s['entry']for s in sources})!=len(sources):raise ValueError('Bounded unique proc sources required')
|
|
if any(t not in native for t in(*REQUIRED_REFERENCE_TABLES,'SpellCastTimes','SpellRange')):raise ValueError('Complete proc native references required')
|
|
if set(new_icon_ids)!={str(s['entry'])for s in sources}:raise ValueError('Explicit proc icon identities required')
|
|
categorized=any(s.get('spell_category_context')is not None for s in sources)
|
|
tables=CHILD_TABLES+('SpellCategories',)if categorized else CHILD_TABLES
|
|
for table in {'Spell','SpellName',*tables}:
|
|
if table not in schemas or canonical_sha256(schemas[table])!=(TABLES|SUPPLEMENTAL_TABLES)[table][2]:raise ValueError('Reviewed proc schema required')
|
|
trigger_visual_links={}if trigger_visual_links is None else trigger_visual_links
|
|
expected_visuals={i for i,s in trigger_sources.items()if s['visuals'][0]}
|
|
if not isinstance(trigger_visual_links,dict)or set(trigger_visual_links)!=expected_visuals:raise ValueError('Complete trigger visual dependencies required')
|
|
needed_ids={s['entry']for s in sources}|{e[10]for s in sources for e in s['effects']if e[0]}
|
|
if not isinstance(proc_overrides,dict)or proc_overrides.get('kind')!='local-source-proc-override-snapshot'or proc_overrides.get('table')!='tw_world.spell_proc_event'or proc_overrides.get('two_reads_equal')is not True or proc_overrides.get('database_modified')is not False or not isinstance(proc_overrides.get('source_spell_ids'),list)or any(type(i)is not int or i<=0 for i in proc_overrides['source_spell_ids'])or not needed_ids.issubset(proc_overrides['source_spell_ids'])or proc_overrides.get('rows')!=[]:raise ValueError('Reviewed empty source proc overrides required')
|
|
review_new_timing(source_tables,native,21);available=available_index(icon_assets);registry=deepcopy(registry)
|
|
occupied={t:{r['ID']for r in native[t]}for t in tables};new_registry_values(registry,maxima,occupied,tables=tables)
|
|
aura_registry=registry.pop('SpellAuraOptions',{});records=[];spells=[]
|
|
presented=any(s.get('passive_proc_presentation')is not None for s in sources)
|
|
for src in sorted(sources,key=lambda s:s['entry']):
|
|
indices,context=validate_source(src,proc_proof,extra_attack_proof=extra_attack_proof,incoming_harmful=incoming_harmful);ident=src['entry']
|
|
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('Proc candidate has positive native reference')
|
|
dependencies=[review_trigger(t,trigger_sources.get(t),trigger_records,schemas,native=native,source_tables=source_tables,visual_links=trigger_visual_links,extra_attack_proof=extra_attack_proof,proc_proof=proc_proof)for t in sorted({src['effects'][i][10]for i in indices})]
|
|
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),EffectAura=42,EffectBasePointsF=src['effects'][i][2]+1,EffectMiscValue=[0,0],EffectTriggerSpell=src['effects'][i][10])for i in indices}
|
|
records.extend(new_definition_records(src,effects,fid,schemas,maxima,registry,occupied,allocation_prefix='new-source-proc-definition'))
|
|
key=str(ident)
|
|
if key not in aura_registry:aura_registry[key]=max([maxima['SpellAuraOptions']]+list(aura_registry.values()))+1
|
|
row=dict(CHILD_NEUTRAL['SpellAuraOptions'],ID=aura_registry[key],SpellID=ident,ProcChance=context['proc_chance'],ProcCharges=context['proc_charges'],ProcTypeMask=context['target_proc_type_mask']);wire=encode(row,schemas['SpellAuraOptions'])
|
|
records.append(dict(table_name='SpellAuraOptions',table_hash=hex(SUPPLEMENTAL_TABLES['SpellAuraOptions'][0]),id=row['ID'],record=row,wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest(),source_spell_id=ident,baseline_record_sha256=None,allocation_policy='new-source-proc-definition-child'))
|
|
spells.append(dict(spell_id=ident,source_record_sha256=canonical_sha256(src),class_family=deepcopy(src['class_family']),levels=deepcopy(src['levels']),effect_indices=indices,proc_context=context,trigger_dependencies=dependencies,icon_asset=dict(file_data_id=fid,**asset),known_spells_modified=False,engine_accepted=False))
|
|
if extra_attack_proof is not None:spells[-1].update(source_definition=deepcopy(src),extra_attack_semantics=deepcopy(extra_attack_proof))
|
|
elif presented or incoming_harmful:spells[-1]['source_definition']=deepcopy(src)
|
|
registry['SpellAuraOptions']=aura_registry;new_registry_values(registry,maxima,occupied,tables=tables)
|
|
return dict(kind='source-item-proc-definition-candidates',build=BUILD,schema=SCHEMA,definition_policy=EXTRA_ATTACK_POLICY if extra_attack_proof is not None else PRESENTED_POLICY if presented else POLICY,records=records,spells=spells,child_id_registry=registry,incoming_harmful_proc=incoming_harmful,installable=False,installed=False,dependency_complete=False,engine_accepted=False,gameplay_verified=False,limitations=['Direct combat passive self proc definitions only; server executes all chance rolls and triggers.','Requires original API absence, complete schema/allocation/override review and actual-client acceptance before staging.','No learned spell, client-side proc execution, item-state or successful gameplay is synthesized.'])
|
|
|
|
EXISTING_EXTRA_POLICY='same-id-source-permanent-extra-attack-proc-correction-v1'
|
|
EXISTING_RESTORE_POLICY='same-id-source-permanent-restorative-proc-correction-v1'
|
|
EXISTING_RESTORE_TEXT_POLICY='same-id-source-restorative-proc-presentation-only-v1'
|
|
|
|
def existing_restoration_component(sources,native,schemas,*,proc_proof,proc_overrides,duration_reference,presentation_only=False, aura161_operands_only=False, flat_aura107_operands_only=False, affect_context=None):
|
|
"""Positive proc parents with independently exact existing restore triggers.
|
|
|
|
Uses the existing restoration converter to validate the complete trigger
|
|
context, including variable healing ranges. Any trigger corrections must be
|
|
staged separately first. No trigger, item, parent or child IDs are allocated.
|
|
The explicit presentation-only policy writes Spell text alone. It retains
|
|
source execution overrides as unresolved metadata, and cannot alter native
|
|
proc conditions, effect amounts, levels or any other execution definition.
|
|
"""
|
|
import re
|
|
from spell_restore_compat import component as restore_component
|
|
from spell_definition_common import review_neutral_children,review_proc_override_snapshot
|
|
from spell_passive_compat import one
|
|
if type(aura161_operands_only) is not bool:
|
|
raise ValueError('Typed aura161 operand role required')
|
|
if type(flat_aura107_operands_only) is not bool or (flat_aura107_operands_only and aura161_operands_only):
|
|
raise ValueError('One typed native-original operand role required')
|
|
operand_aura = 107 if flat_aura107_operands_only else 161
|
|
if aura161_operands_only or flat_aura107_operands_only:
|
|
if presentation_only or not isinstance(sources, list) or not 1 <= len(sources) <= 128 or len({r['entry'] for r in sources}) != len(sources):
|
|
raise ValueError('Unique bounded native-original aura161 operand sources required')
|
|
if any(k not in native for k in ('Spell', 'SpellName', 'SpellMisc', 'SpellEffect')):
|
|
raise ValueError('Complete original aura161 parent references required')
|
|
if set(schemas) not in ({'Spell', 'SpellEffect', 'SpellLevels'}, {'Spell', 'SpellName', 'SpellMisc', 'SpellEffect', 'SpellLevels', 'SpellAuraOptions'}) or any(canonical_sha256(schemas[k]) != (TABLES | SUPPLEMENTAL_TABLES)[k][2] for k in schemas):
|
|
raise ValueError('Pinned existing restoration operand schemas required')
|
|
changes, reviews, deferred = [], [], []
|
|
else:
|
|
if type(presentation_only)is not bool:raise ValueError('Typed presentation scope required')
|
|
if not isinstance(sources,list)or not 2<=len(sources)<=128 or len({s['entry']for s in sources})!=len(sources):raise ValueError('Unique bounded restoration proc/trigger sources required')
|
|
override_review=review_proc_override_snapshot(proc_overrides,[s['entry']for s in sources])
|
|
if not presentation_only and not override_review['overrides_absent']:raise ValueError('Source proc override requires separate execution review: '+','.join(map(str,override_review['override_row_ids'])))
|
|
timing=dict(source_duration_id=21,target_duration_id=21,duration_ms=-1,max_duration_ms=-1,source_duration_per_level=0,target_duration_per_resource=0,permanent=True)
|
|
if duration_reference!=timing or any(type(duration_reference.get(k))is not type(v)for k,v in timing.items()):raise ValueError('Exact source/native permanent duration required')
|
|
tables=('Spell','SpellName','SpellMisc','SpellEffect','SpellLevels','SpellAuraOptions')
|
|
if any(s.get('spell_category_context')is not None for s in sources):tables+=('SpellCategories',)
|
|
if any(t not in native for t in REQUIRED_REFERENCE_TABLES):raise ValueError('Complete original native contexts required')
|
|
for t in tables:
|
|
if t not in schemas or canonical_sha256(schemas[t])!=(TABLES|SUPPLEMENTAL_TABLES)[t][2]:raise ValueError('Pinned native correction schema required')
|
|
procs={};triggers={};changes=[];reviews=[];deferred=[]
|
|
for src in sources:
|
|
if src['conditions']['procFlags']:
|
|
slots,context=validate_source(src,proc_proof,constant_coefficient=True,existing_restoration=True)
|
|
if re.search(r'\$(?:[0-9]+)?h[1-3]',src['description']):raise ValueError('Legacy indexed proc-chance tooltip token requires semantic conversion')
|
|
procs[src['entry']]=(src,slots,context)
|
|
else:
|
|
validate_restore(src);triggers[src['entry']]=src
|
|
needed={s['effects'][i][10]for s,slots,_ in procs.values()for i in slots}
|
|
if not procs or needed!=set(triggers):raise ValueError('Exact restoration trigger dependency closure required')
|
|
maxima={t:max((r['ID']for r in native[t]),default=0)for t in tables}
|
|
trigger_review=restore_component(list(triggers.values()),native,schemas,maxima,dict(schema_version=1,build=BUILD,SpellEffect={}))
|
|
if trigger_review['records']:raise ValueError('Restorative trigger definitions require independent correction first')
|
|
def change(table,old,new,ident):
|
|
encode(old,schemas[table]);wire=encode(new,schemas[table])
|
|
if presentation_only and table!='Spell':
|
|
if old!=new:deferred.append(dict(table_name=table,id=old['ID'],source_spell_id=ident,changed_fields=sorted(k for k in new if old[k]!=new[k])))
|
|
return
|
|
if old!=new:changes.append(dict(table_name=table,table_hash=hex((TABLES|SUPPLEMENTAL_TABLES)[table][0]),id=old['ID'],source_spell_id=ident,record=new,wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest(),baseline_record=deepcopy(old),baseline_record_sha256=canonical_sha256(old),changed_fields=sorted(k for k in new if old[k]!=new[k]),allocation_policy='same-ID-source-restorative-proc-correction'))
|
|
|
|
if aura161_operands_only or flat_aura107_operands_only:
|
|
from spell_passive_compat import constant_server_row, CONDITIONS
|
|
from spell_item_food_regen_compat import source_columns
|
|
source_fields = source_columns()
|
|
class SourceScopeHold(ValueError):
|
|
pass
|
|
held_sources = []
|
|
if flat_aura107_operands_only:
|
|
from spell_set_modifier_compat import contract as modifier_contract, effective_affect_mask, native_mask_words
|
|
from spell_affect_compat import derive
|
|
required_affect = {'namespace', 'source_inventory', 'target_inventory', 'snapshot', 'slots'}
|
|
if not isinstance(affect_context, dict) or set(affect_context) != required_affect or affect_context['namespace'] != modifier_contract():
|
|
raise ValueError('Existing reviewed modifier namespace/context required')
|
|
namespace = affect_context['namespace']; primary_mask = 0
|
|
for item in namespace['attributes']: primary_mask |= item['source_value']
|
|
passive_bit = next(r['source_value'] for r in namespace['attributes'] if r['source_name'] == 'SPELL_ATTR_PASSIVE')
|
|
operations = {r['source_value']: r['target_value'] for r in namespace['operations']}
|
|
families = set(namespace['families'].values()); scope = set(); source_ids = {r['entry'] for r in sources}
|
|
for slot in affect_context['slots']:
|
|
if not isinstance(slot, dict) or set(slot) != {'source_spell_id', 'effect_index'} or slot['source_spell_id'] not in source_ids or type(slot['effect_index']) is not int or not 0 <= slot['effect_index'] <= 2:
|
|
raise ValueError('Explicit typed flat modifier operand slots required')
|
|
key = (slot['source_spell_id'], slot['effect_index'])
|
|
if key in scope: raise ValueError('Duplicate flat modifier operand scope')
|
|
scope.add(key)
|
|
if not scope or len(scope) > 384: raise ValueError('Bounded flat modifier operand scope required')
|
|
identity_proofs = {}; parents = {}; target_families = {}
|
|
for item in affect_context['target_inventory']:
|
|
parents.setdefault(item['SpellID'], []).append(item)
|
|
target_families.setdefault(item['SpellClassSet'], []).append(item)
|
|
for raw in sorted(sources, key=lambda row: row['entry']):
|
|
checkpoint = len(changes)
|
|
try:
|
|
if not isinstance(raw, dict) or set(raw) != source_fields:
|
|
raise ValueError('Complete original source server row required')
|
|
src = constant_server_row(raw); ident = src['entry']
|
|
if flat_aura107_operands_only:
|
|
family = raw['spellFamilyName']
|
|
if not src['attributes'][0] & passive_bit or src['attributes'][0] & ~primary_mask or family not in families:
|
|
raise SourceScopeHold('Flat107 passive role outside existing reviewed namespace')
|
|
family_rows = parents.get(ident, [])
|
|
if len(family_rows) != 1 or family_rows[0]['SpellClassSet'] != family:
|
|
raise ValueError('Flat107 original native parent family witness differs')
|
|
elif src['attributes'][0] not in (192, 448) or any(raw[k] for k in ('spellFamilyName', 'spellFamilyFlags')):
|
|
raise SourceScopeHold('Aura161 operand source is not a generic item passive')
|
|
if type(src['school']) is not int or not 0 <= src['school'] <= 6 or (src['castingTimeIndex'], src['durationIndex'], src['rangeIndex'], src['speed']) != (1, 21, 1, 0) or src['power'] != [0] * 6 or src['equippedItem'] not in ([-1, 0, 0], [-1, -1, 0]) or src['visuals'] != [0, 0]:
|
|
raise SourceScopeHold('Aura161 operand source has unreviewed passive context')
|
|
if any(v not in (0, 101) if k == 'procChance' else v != 0 for k, v in src['conditions'].items()) or set(src['conditions']) != set(CONDITIONS) or any(src['timing'].values()):
|
|
raise SourceScopeHold('Aura161 operand source has conditional, proc or timing mechanics')
|
|
one(native['SpellName'], lambda row: row['ID'] == ident, 'original aura161 name'); one(native['Spell'], lambda row: row['ID'] == ident, 'original aura161 text')
|
|
misc = [r for r in native['SpellMisc'] if r['SpellID'] == ident and r['DifficultyID'] == 0]
|
|
if len(misc) != 1 or misc[0]['Attributes'][:5] != src['attributes']:
|
|
raise ValueError('Aura161 original attribute retention witness differs')
|
|
native_misc = misc[0]
|
|
# Native timing/range/school references are retained, never remapped.
|
|
active = [i for i, e in enumerate(src['effects']) if e[0] and (not flat_aura107_operands_only or (ident, i) in scope)]
|
|
if not active:
|
|
raise SourceScopeHold('Aura161 operand source has no effects')
|
|
ids = []
|
|
for index, e in enumerate(src['effects']):
|
|
if flat_aura107_operands_only and (ident, index) not in scope:
|
|
continue # Every unselected effect retains native authority.
|
|
if not e[0]:
|
|
if e != [0] * 11 + [-1]: raise SourceScopeHold('Aura161 source inactive effect differs')
|
|
continue
|
|
if e[:2] != [6, operand_aura] or (not flat_aura107_operands_only and e[2] < 0) or e[3:7] != [1, 1, 0, 0] or e[8:11] != [1, 0, 0] or (not flat_aura107_operands_only and e[7] != 0) or e[11] not in (-1, 0):
|
|
raise SourceScopeHold('Aura161 source effect is not a positive constant self operand')
|
|
slot = str(index + 1)
|
|
if any(raw[k + slot] for k in (('effectAmplitude', 'effectMechanic', 'effectRadiusIndex', 'effectChainTarget') if flat_aura107_operands_only else ('effectAmplitude', 'effectItemType', 'effectMechanic', 'effectRadiusIndex', 'effectChainTarget'))):
|
|
raise SourceScopeHold('Aura161 source effect has unreviewed selectors or periodic mechanics')
|
|
effects = [r for r in native['SpellEffect'] if r['SpellID'] == ident and r['EffectIndex'] == index and r['DifficultyID'] == 0]
|
|
if len(effects) != 1: raise ValueError('Aura161 requires exact original native effect/slot witness')
|
|
old = effects[0]
|
|
expected_misc, expected_mask = [0, 0], [0, 0, 0, 0]
|
|
expected_item_type = old['EffectItemType'] if flat_aura107_operands_only else 0
|
|
if flat_aura107_operands_only:
|
|
if e[7] not in operations: raise SourceScopeHold('Flat107 operation outside existing reviewed namespace')
|
|
fallback = [raw['effectItemType' + str(i)] for i in (1, 2, 3)]
|
|
mask = effective_affect_mask({'entry': ident, 'source_effect_affect_fallbacks': fallback}, index, affect_context['snapshot'])
|
|
key = (family, mask)
|
|
if key not in identity_proofs:
|
|
identity_proofs[key] = derive(affect_context['source_inventory'], target_families.get(family, []), family, mask)
|
|
expected_mask = native_mask_words(identity_proofs[key]['target_mask'])
|
|
expected_misc = [operations[e[7]], 0]
|
|
if (old['Effect'], old['EffectAura'], old['ImplicitTarget'], old['EffectMiscValue'], old['EffectAuraPeriod'], old['EffectTriggerSpell'], old['EffectItemType'], old['EffectSpellClassMask']) != (6, operand_aura, [1, 0], expected_misc, 0, 0, expected_item_type, expected_mask):
|
|
raise ValueError('Aura161 original native constant self tuple differs')
|
|
if any(old[k] for k in ('EffectRealPointsPerLevel', 'EffectPointsPerResource', 'EffectBonusCoefficient', 'BonusCoefficientFromAP', 'Variance', 'ResourceCoefficient', 'ScalingClass')):
|
|
raise ValueError('Aura161 original has unreviewed scaling mechanics')
|
|
new = deepcopy(old); new['EffectBasePointsF'] = integer(e[2] + 1, -0x80000000 if flat_aura107_operands_only else 1, 0x7fffffff, 'native-original aura operand')
|
|
ids.append(old['ID'])
|
|
if old != new: change('SpellEffect', old, new, ident)
|
|
reviews.append(dict(spell_id=ident, projected_fields=['EffectBasePointsF'], retained_native_misc_sha256=canonical_sha256(native_misc), retained_effect_ids=ids, complete_source_definition=False, regeneration_application_verified=False))
|
|
if flat_aura107_operands_only:
|
|
reviews[-1].pop('regeneration_application_verified')
|
|
reviews[-1]['spell_modifier_application_verified'] = False
|
|
except SourceScopeHold as error:
|
|
del changes[checkpoint:]
|
|
held_sources.append(dict(source_spell_id=raw['entry'], reason=str(error)))
|
|
result = dict(kind='source-existing-restoration-proc-corrections', build=BUILD, schema=SCHEMA,
|
|
definition_policy='existing-native-flat-aura107-operand-only-v1' if flat_aura107_operands_only else 'existing-native-aura161-operand-only-v1', id_remapping=False,
|
|
records=changes, spells=reviews, held_sources=held_sources, source_scope=len(sources), validated_trigger_ids=[], proc_override_review=None,
|
|
presentation_only=False, deferred_metadata_corrections=deferred,
|
|
proc_execution_rules_converted=False, installed=False, engine_accepted=False,
|
|
gameplay_verified=False, installable=False,
|
|
inputs=dict(sources=deepcopy(sources), native=deepcopy(native), proc_proof=deepcopy(proc_proof),
|
|
proc_overrides=deepcopy(proc_overrides), duration_reference=deepcopy(duration_reference),
|
|
presentation_only=False, aura161_operands_only=aura161_operands_only))
|
|
if flat_aura107_operands_only:
|
|
result['inputs']['flat_aura107_operands_only'] = True
|
|
result['inputs']['affect_context'] = deepcopy(affect_context)
|
|
return result
|
|
for ident,(src,slots,context)in sorted(procs.items()):
|
|
name=one(native['SpellName'],lambda r:r['ID']==ident,'same-ID restorative proc name');text=one(native['Spell'],lambda r:r['ID']==ident,'same-ID restorative proc text');misc=one(native['SpellMisc'],lambda r:r['SpellID']==ident,'same-ID restorative proc misc')
|
|
if name['Name_lang']!=src['name']:raise ValueError('Native restorative proc identity collision')
|
|
attrs=misc['Attributes'];expected=dict(NEW_MISC_NEUTRAL,DurationIndex=src['durationIndex'],SchoolMask=1<<src['school']);expected.pop('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('Unreviewed positive restorative proc attributes')
|
|
if any(misc[k]!=v for k,v in expected.items()):raise ValueError('Positive restorative proc timing/school/cost differs')
|
|
integer(misc['SpellIconFileDataID'],1,0x7fffffff,'native restorative proc icon')
|
|
reviewed=dict(native);reviewed['SpellAuraOptions']=[r for r in native['SpellAuraOptions']if r['SpellID']!=ident];children=review_neutral_children(reviewed,src)
|
|
if src['timing']['startRecoveryCategory'] and not any(r['SpellID']==ident for r in native['SpellCategories']):raise ValueError('Positive proc recovery category context required')
|
|
options=one(native['SpellAuraOptions'],lambda r:r['SpellID']==ident,'native restorative proc conditions')
|
|
desired=dict(CHILD_NEUTRAL['SpellAuraOptions'],ID=options['ID'],SpellID=ident,ProcChance=context['proc_chance'],ProcCharges=context['proc_charges'],ProcTypeMask=context['target_proc_type_mask'])
|
|
if options!=desired:
|
|
mutable={'ProcChance','ProcCharges','ProcTypeMask'}
|
|
if (not presentation_only or set(options)!=set(desired)
|
|
or any(options[k]!=desired[k]for k in desired if k not in mutable)):
|
|
raise ValueError('Positive restorative proc conditions differ')
|
|
encode(options,schemas['SpellAuraOptions'])
|
|
# A text-only correction can retain independently recorded native
|
|
# chance/event differences. Never publish those execution fields
|
|
# when the source server has a separate PPM/outcome override.
|
|
change('SpellAuraOptions',options,desired,ident)
|
|
effects=[r for r in native['SpellEffect']if r['SpellID']==ident]
|
|
if len(effects)!=len(slots)or {r['EffectIndex']for r in effects}!=set(slots):raise ValueError('Complete same-ID restorative proc effects required')
|
|
for old in effects:
|
|
e=src['effects'][old['EffectIndex']];desired=dict(NEW_EFFECT_NEUTRAL,ID=old['ID'],SpellID=ident,EffectIndex=old['EffectIndex'],EffectAura=42,EffectBasePointsF=e[2]+1,EffectBonusCoefficient=max(0,e[11]),EffectMiscValue=[0,0],EffectTriggerSpell=e[10])
|
|
if any(old[k]!=v for k,v in desired.items()if k not in('EffectBasePointsF','EffectBonusCoefficient')):raise ValueError('Native restorative proc effect semantics differ')
|
|
change('SpellEffect',old,desired,ident)
|
|
levels=[r for r in native['SpellLevels']if r['SpellID']==ident]
|
|
# The established new-definition writer omits all-zero level rows.
|
|
# Preserve that neutral absence. Positive source requirements still
|
|
# need one verified existing native row; no requirements are dropped.
|
|
if levels or any(src['levels'].values()):
|
|
level=one(levels,lambda r:True,'native restorative proc levels')
|
|
if level['DifficultyID']or level['MaxPassiveAuraLevel']:raise ValueError('Native restorative proc level condition differs')
|
|
change('SpellLevels',level,dict(level,BaseLevel=src['levels']['baseLevel'],SpellLevel=src['levels']['spellLevel'],MaxLevel=src['levels']['maxLevel']),ident)
|
|
change('Spell',text,dict(text,NameSubtext_lang=src['nameSubtext'],Description_lang=src['description'],AuraDescription_lang=src['auraDescription']),ident)
|
|
reviews.append(dict(spell_id=ident,source_record_sha256=canonical_sha256(src),source_effect_indices=slots,proc_context=context,native_child_review=children,retained_icon=misc['SpellIconFileDataID'],known_spells_modified=False,engine_accepted=False,gameplay_verified=False))
|
|
return dict(kind='source-existing-restoration-proc-corrections',build=BUILD,schema=SCHEMA,definition_policy=EXISTING_RESTORE_TEXT_POLICY if presentation_only else EXISTING_RESTORE_POLICY,id_remapping=False,records=changes,spells=reviews,validated_trigger_ids=sorted(triggers),proc_override_review=override_review,presentation_only=presentation_only,deferred_metadata_corrections=deferred,proc_execution_rules_converted=False,installed=False,engine_accepted=False,gameplay_verified=False,installable=False,inputs=dict(sources=deepcopy(sources),native=deepcopy(native),proc_proof=deepcopy(proc_proof),proc_overrides=deepcopy(proc_overrides),duration_reference=deepcopy(duration_reference),presentation_only=presentation_only))
|
|
|
|
def existing_extra_attack_component(sources,native,schemas,*,proc_proof,extra_attack_proof,proc_overrides,duration_reference):
|
|
"""Correct positive native proc/trigger definitions; never delete shared rows.
|
|
|
|
A destination-only same-proc DUMMY slot can be represented as an explicit
|
|
source-empty NONE slot. Parents, child IDs and other spells remain intact.
|
|
No local extra attack, proc roll, cooldown or race bonus is executed here.
|
|
"""
|
|
from spell_definition_common import review_neutral_children
|
|
from spell_extra_attack_compat import validate_source as validate_extra
|
|
from spell_passive_compat import one
|
|
if not isinstance(sources,list)or not 2<=len(sources)<=128 or len({s['entry']for s in sources})!=len(sources):raise ValueError('Unique bounded proc and trigger sources required')
|
|
if not isinstance(proc_overrides,list)or proc_overrides:raise ValueError('Source proc override requires separate execution review')
|
|
timing=dict(source_duration_id=21,target_duration_id=21,duration_ms=-1,max_duration_ms=-1,source_duration_per_level=0,target_duration_per_resource=0,permanent=True)
|
|
if duration_reference!=timing or any(type(duration_reference.get(k))is not type(v)for k,v in timing.items()):raise ValueError('Exact source/native permanent duration required')
|
|
tables=('Spell','SpellName','SpellMisc','SpellEffect','SpellLevels','SpellAuraOptions')
|
|
if any(t not in native for t in REQUIRED_REFERENCE_TABLES):raise ValueError('Complete original native contexts required')
|
|
for t in tables:
|
|
if t not in schemas or canonical_sha256(schemas[t])!=(TABLES|SUPPLEMENTAL_TABLES)[t][2]:raise ValueError('Pinned native correction schema required')
|
|
by_source={s['entry']:s for s in sources};procs={};triggers={};changes=[];review=[]
|
|
for s in sources:
|
|
if s['conditions']['procFlags']:
|
|
slots,context=validate_source(s,proc_proof,extra_attack_proof=extra_attack_proof,constant_coefficient=True);procs[s['entry']]=(slots,context)
|
|
else:
|
|
slots=validate_extra(s,constant_coefficient=True);triggers[s['entry']]=slots
|
|
referenced={by_source[i]['effects'][j][10]for i,(slots,_)in procs.items()for j in slots}
|
|
if not procs or referenced!=set(triggers):raise ValueError('Exact source trigger dependency closure required')
|
|
def change(table,old,new,source):
|
|
encode(old,schemas[table]);wire=encode(new,schemas[table])
|
|
if old!=new:changes.append(dict(table_name=table,table_hash=hex((TABLES|SUPPLEMENTAL_TABLES)[table][0]),id=old['ID'],source_spell_id=source,record=new,wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest(),baseline_record=deepcopy(old),baseline_record_sha256=canonical_sha256(old),changed_fields=sorted(k for k in new if old[k]!=new[k]),allocation_policy='same-ID-source-proc-and-trigger-correction'))
|
|
for ident,src in sorted(by_source.items()):
|
|
is_proc=ident in procs;slots,context=procs[ident]if is_proc else(triggers[ident],None)
|
|
name=one(native['SpellName'],lambda r:r['ID']==ident,'same-ID proc name');text=one(native['Spell'],lambda r:r['ID']==ident,'same-ID proc text');misc=one(native['SpellMisc'],lambda r:r['SpellID']==ident,'same-ID proc misc')
|
|
if name['Name_lang']!=src['name']:raise ValueError('Native proc/trigger identity collision')
|
|
attrs=misc['Attributes'];expected=deepcopy(NEW_MISC_NEUTRAL);expected.pop('Attributes');expected.update(DurationIndex=src['durationIndex'],SchoolMask=1<<src['school'])
|
|
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('Unreviewed positive proc attributes')
|
|
check=dict(misc);check['DurationIndex']=src['durationIndex']if is_proc and misc['DurationIndex']in(0,21)else misc['DurationIndex']
|
|
if any(check[k]!=v for k,v in expected.items()):raise ValueError('Unreviewed positive proc timing/school/cost context')
|
|
integer(misc['SpellIconFileDataID'],1,0x7fffffff,'native proc icon')
|
|
reviewed=dict(native)
|
|
if is_proc:reviewed['SpellAuraOptions']=[r for r in native['SpellAuraOptions']if r['SpellID']!=ident]
|
|
review_neutral_children(reviewed,src)
|
|
visuals=[r for r in native['SpellXSpellVisual']if r['SpellID']==ident]
|
|
if src['visuals'][0]and (len(visuals)!=1 or visuals[0]['SpellVisualID']!=src['visuals'][0]or visuals[0]['Priority']!=1):raise ValueError('Source/native trigger visual identity differs')
|
|
effects=[r for r in native['SpellEffect']if r['SpellID']==ident]
|
|
if not effects or len({r['EffectIndex']for r in effects})!=len(effects):raise ValueError('Missing/duplicate positive proc effects')
|
|
if not set(slots).issubset({r['EffectIndex']for r in effects}):raise ValueError('Missing source effect in native proc')
|
|
zeroed=[]
|
|
for old in effects:
|
|
index=integer(old['EffectIndex'],0,2,'native effect slot');e=src['effects'][index]
|
|
if index in slots:
|
|
desired=dict(NEW_EFFECT_NEUTRAL,ID=old['ID'],SpellID=ident,EffectIndex=index,Effect=e[0],EffectAura=e[1],EffectBasePointsF=e[2]+1,EffectBonusCoefficient=max(0,e[11]),EffectMiscValue=[e[7],0],EffectTriggerSpell=e[10],ImplicitTarget=[e[8],e[9]])
|
|
# Source values may replace amounts/coefficient only, never a
|
|
# different native mechanic, target, scaling or trigger chain.
|
|
mutable={'EffectBasePointsF','EffectBonusCoefficient'}
|
|
if any(old[k]!=v for k,v in desired.items()if k not in mutable):raise ValueError('Native proc/trigger effect semantics differ')
|
|
else:
|
|
if not is_proc or e!=[0]*11+[-1]:raise ValueError('Unreviewed target-only effect')
|
|
primary=src['effects'][slots[0]]
|
|
desired=dict(NEW_EFFECT_NEUTRAL,ID=old['ID'],SpellID=ident,EffectIndex=index,Effect=0,EffectAura=0,EffectBasePointsF=0,EffectMiscValue=[0,0],ImplicitTarget=[0,0])
|
|
if old!=desired:
|
|
witness=dict(NEW_EFFECT_NEUTRAL,ID=old['ID'],SpellID=ident,EffectIndex=index,EffectAura=4,EffectBasePointsF=old['EffectBasePointsF'],EffectMiscValue=[0,0],EffectTriggerSpell=primary[10])
|
|
if old!=witness or not 0<old['EffectBasePointsF']<=100:raise ValueError('Target-only extra slot is not a witnessed same-proc dummy')
|
|
zeroed.append(index)
|
|
change('SpellEffect',old,desired,ident)
|
|
change('Spell',text,dict(text,NameSubtext_lang=src['nameSubtext'],Description_lang=src['description'],AuraDescription_lang=src['auraDescription']),ident)
|
|
change('SpellMisc',misc,dict(misc,DurationIndex=src['durationIndex']),ident)
|
|
level=one(native['SpellLevels'],lambda r:r['SpellID']==ident,'native proc levels')
|
|
if level['DifficultyID']or level['MaxPassiveAuraLevel']:raise ValueError('Unreviewed native proc level restrictions')
|
|
change('SpellLevels',level,dict(level,BaseLevel=src['levels']['baseLevel'],SpellLevel=src['levels']['spellLevel'],MaxLevel=src['levels']['maxLevel']),ident)
|
|
if is_proc:
|
|
old=one(native['SpellAuraOptions'],lambda r:r['SpellID']==ident,'native proc conditions');new=dict(CHILD_NEUTRAL['SpellAuraOptions'],ID=old['ID'],SpellID=ident,ProcChance=context['proc_chance'],ProcCharges=context['proc_charges'],ProcTypeMask=context['target_proc_type_mask'])
|
|
if any(old[k]!=v for k,v in new.items()if k not in('ProcChance','ProcCategoryRecovery')):raise ValueError('Unreviewed positive proc conditions')
|
|
integer(old['ProcChance'],0,100,'native proc chance');integer(old['ProcCategoryRecovery'],0,0x7fffffff,'native-only proc cooldown')
|
|
change('SpellAuraOptions',old,new,ident)
|
|
review.append(dict(spell_id=ident,source_record_sha256=canonical_sha256(src),source_is_proc=is_proc,source_effect_indices=slots,source_empty_indices_represented_as_native_none=zeroed,retained_icon=misc['SpellIconFileDataID'],retained_visuals=[r['ID']for r in visuals],known_spells_modified=False,engine_accepted=False,gameplay_verified=False))
|
|
return dict(kind='source-existing-extra-attack-proc-corrections',build=BUILD,schema=SCHEMA,definition_policy=EXISTING_EXTRA_POLICY,id_remapping=False,records=changes,spells=review,installed=False,engine_accepted=False,gameplay_verified=False,installable=False,inputs=dict(sources=deepcopy(sources),native=deepcopy(native),proc_proof=deepcopy(proc_proof),extra_attack_proof=deepcopy(extra_attack_proof),proc_overrides=deepcopy(proc_overrides),duration_reference=deepcopy(duration_reference)))
|