367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
96 lines
10 KiB
Python
96 lines
10 KiB
Python
"""Catalogue-wide item property joins using existing reviewed relationship rules.
|
|
|
|
This separates exact source relationships from spell-mechanic certification.
|
|
Unreviewed names, triggers, charges and execution never become implicit approval.
|
|
"""
|
|
from collections import Counter,defaultdict
|
|
from item_effect_compat import effective_item_links,review_obtainability_reference
|
|
|
|
EFFECT_FIELDS=('LegacySlotIndex','TriggerType','Charges','CoolDownMSec','CategoryCoolDownMSec','SpellCategoryID','SpellID','ChrSpecializationID','PlayerConditionID')
|
|
TRIGGERS={0:'ON_USE',1:'ON_EQUIP',2:'CHANCE_ON_HIT'}
|
|
|
|
def expected_effect(source,index):
|
|
spell=source['spellid_'+str(index)]
|
|
if not spell:return None
|
|
trigger=source['spelltrigger_'+str(index)]
|
|
if type(spell)is not int or not 0<spell<0x80000000 or type(trigger)is not int or trigger not in TRIGGERS:
|
|
return None
|
|
return dict(LegacySlotIndex=index-1,TriggerType=trigger,Charges=source['spellcharges_'+str(index)],
|
|
CoolDownMSec=source['spellcooldown_'+str(index)],CategoryCoolDownMSec=source['spellcategorycooldown_'+str(index)],
|
|
SpellCategoryID=source['spellcategory_'+str(index)],SpellID=spell,ChrSpecializationID=0,PlayerConditionID=0)
|
|
|
|
def join_catalogue(catalogue,package,native_effects,native_links,native_names,definition_ledger,source_sets,*,reviewed_proc_ids=frozenset(),obtainability_reference=None):
|
|
"""Visit every source item exactly once; return complete rows and stage inputs.
|
|
|
|
Definition ledger entries must explicitly have accepted_complete=True.
|
|
Native SpellName/API presence is reported separately and never authorizes a
|
|
new source relationship. Existing exact links are preserved regardless of
|
|
whether their spell mechanics have received that independent review.
|
|
"""
|
|
flag4_allowed=review_obtainability_reference(obtainability_reference,missing_slots_only=True)
|
|
published={(r['table_name'],r['id']):r for r in package['rows']}
|
|
if len(published)!=len(package['rows']):raise ValueError('Duplicate published property identity')
|
|
effects={r['ID']:dict(r)for r in native_effects}
|
|
for r in package['rows']:
|
|
if r['table_name']=='ItemEffect'and r.get('record_status','valid')=='valid':effects[r['id']]=dict(r['record'],ID=r['id'])
|
|
by_item=defaultdict(list)
|
|
for r in effective_item_links(native_links,package['rows']):
|
|
effect=effects.get(r['ItemEffectID']);by_item[r['ItemID']].append(dict(link_id=r['ID'],effect_id=r['ItemEffectID'],effect=effect))
|
|
names={r['ID']for r in native_names}|{r['id']for r in package['rows']if r['table_name']=='SpellName'and r.get('record_status','valid')=='valid'}
|
|
known={i for i,d in definition_ledger.items()if d.get('accepted_complete')is True}
|
|
sets={r['id']:r for r in source_sets};seen=set();rows=[];eligible=[];complete=[];reasons=Counter();relation_counts=Counter();slot_count=0;source_ids=set();metadata_counts=Counter()
|
|
for item in sorted(catalogue,key=lambda x:x['entry']):
|
|
s=item['source'];ident=item['entry']
|
|
if ident in seen or ident!=s['entry']:raise ValueError('Duplicate or inconsistent source property identity')
|
|
seen.add(ident);pin=item['source_record_sha256'];metadata={};components=[]
|
|
for table in('Item','ItemSparse'):
|
|
p=published.get((table,ident));draft=next((c for c in item.get('components',[])if c['table_name']==table),None)
|
|
if not p or p.get('record_status','valid')!='valid':state='not-published'
|
|
elif p.get('source_record_sha256')==pin:state='source-pin-exact'
|
|
elif draft and draft.get('source_record_sha256')==pin and draft.get('wire_hex')==p.get('wire_hex'):state='reviewed-draft-exact';components.append(draft)
|
|
else:state='source-identity-not-proven'
|
|
metadata[table]=state
|
|
ready=all(x in('source-pin-exact','reviewed-draft-exact')for x in metadata.values());metadata_counts['paired-source-exact'if ready else 'paired-source-unresolved']+=1
|
|
actual=by_item.get(ident,[]);actual_slots=defaultdict(list)
|
|
for a in actual:
|
|
if a['effect']is not None:actual_slots[a['effect']['LegacySlotIndex']].append(a)
|
|
slots=[];wanted_slots=set();item_reasons=set();has_reviewed_missing=False;all_reviewed=True;has_changes=False;shape_complete=True
|
|
for index in range(1,6):
|
|
spell=s['spellid_'+str(index)]
|
|
if not spell:continue
|
|
slot_count+=1;source_ids.add(spell);slot=index-1;wanted_slots.add(slot);wanted=expected_effect(s,index);matches=actual_slots.get(slot,[])
|
|
exact=bool(wanted and len(matches)==1 and matches[0]['effect']and {k:matches[0]['effect'][k]for k in EFFECT_FIELDS}==wanted)
|
|
state='exact-existing'if exact else 'unsupported-source-trigger'if wanted is None else 'missing'if not matches else 'different-or-ambiguous'
|
|
relation_counts[state]+=1;has_changes|=not exact;reviewed=spell in known;all_reviewed&=reviewed
|
|
trigger=s['spelltrigger_'+str(index)];charges=s['spellcharges_'+str(index)];ppm=s.get('spellppmrate_'+str(index),0);category=s['spellcategory_'+str(index)];cooldown=s['spellcooldown_'+str(index)];category_cd=s['spellcategorycooldown_'+str(index)]
|
|
shape=wanted is not None and charges==0 and category==0 and trigger in(0,1,2)
|
|
shape=shape and ((trigger in(1,2)and cooldown in(-1,0)and category_cd in(-1,0))or(trigger==0 and s.get('class')in(2,4)and s.get('inventory_type')in(*range(1,18),19,20,21,22,23,26,28)and -1<=cooldown<=86400000 and -1<=category_cd<=86400000))
|
|
shape=shape and ((trigger!=2 and ppm==0)or(trigger==2 and spell in reviewed_proc_ids and type(ppm)in(int,float)and ppm>=0))
|
|
shape_complete&=shape
|
|
if not exact and not shape:item_reasons.add('source-use-proc-charge-category-or-timing-review-missing')
|
|
if not exact:
|
|
if not reviewed:item_reasons.add('complete-spell-definition-review-missing')
|
|
if wanted is None:item_reasons.add('source-trigger-namespace-unreviewed')
|
|
if matches:item_reasons.add('existing-slot-conflict-needs-explicit-migration')
|
|
if reviewed and not matches and wanted and wanted['TriggerType']==1 and wanted['Charges']==0 and wanted['SpellCategoryID']==0 and wanted['CoolDownMSec']in(-1,0)and wanted['CategoryCoolDownMSec']in(-1,0)and s.get('spellppmrate_'+str(index),0)==0:has_reviewed_missing=True
|
|
slots.append(dict(slot=slot,source_spell_id=spell,source_trigger=s['spelltrigger_'+str(index)],source_trigger_name=TRIGGERS.get(s['spelltrigger_'+str(index)],'UNREVIEWED_NAMESPACE'),source_charges=s['spellcharges_'+str(index)],source_cooldown_ms=s['spellcooldown_'+str(index)],source_category=s['spellcategory_'+str(index)],source_category_cooldown_ms=s['spellcategorycooldown_'+str(index)],source_ppm=s.get('spellppmrate_'+str(index),0),expected_native_effect=wanted,current_relationships=matches,relationship_status=state,native_or_published_name_present=spell in names,accepted_complete_definition=reviewed,definition_receipt=definition_ledger.get(spell)))
|
|
extras=[a for a in actual if a['effect']is None or a['effect']['LegacySlotIndex']not in wanted_slots]
|
|
if extras:has_changes=True;item_reasons.add('extra-native-or-published-source-slot-needs-retirement-review')
|
|
if has_changes and not ready:item_reasons.add('paired-source-item-metadata-unresolved')
|
|
execution={k:s.get(k)for k in('script_name','extra_flags','duration')if s.get(k)}
|
|
unreviewed_execution={k:v for k,v in execution.items() if not(k=='extra_flags' and type(v)is int and v==4 and flag4_allowed)}
|
|
if has_changes and unreviewed_execution:item_reasons.add('source-execution-dependency-unreviewed')
|
|
if ready and not execution and all_reviewed and shape_complete and has_changes:
|
|
complete.append(dict(entry=ident,source=s,source_record_sha256=pin,components=[]if all(v=='source-pin-exact'for v in metadata.values())else components))
|
|
if ready and not unreviewed_execution and has_reviewed_missing:
|
|
eligible.append(dict(entry=ident,source=s,source_record_sha256=pin,components=[]if all(v=='source-pin-exact'for v in metadata.values())else components))
|
|
sparse=published.get(('ItemSparse',ident));sr=(sparse or{}).get('record')or{};setid=s.get('set_id',0);published_set=sr.get('ItemSet',sr.get('ItemSetID'))
|
|
membership='none'if not setid and published_set in(0,None)else 'source-exact'if published_set==setid else 'not-published'if not sr else 'different'
|
|
if setid and setid not in sets:membership='native-reuse473-needs-recorded-proof'if setid==473 else 'source-set-parent-unavailable'
|
|
if membership in('different','not-published','source-set-parent-unavailable'):item_reasons.add('set-membership-dependency-unresolved')
|
|
stats=[dict(slot=i-1,type=s.get('stat_type'+str(i),0),value=s.get('stat_value'+str(i),0))for i in range(1,11)if s.get('stat_value'+str(i),0)]
|
|
if stats and not ready:item_reasons.add('intrinsic-stat-metadata-unresolved')
|
|
rows.append(dict(entry=ident,name=s['name'],source_record_sha256=pin,wire_positive=ident>0,metadata=metadata,source_intrinsic_stats=stats,intrinsic_stat_publication='source-metadata-exact'if ready else 'source-metadata-unresolved',source_set_id=setid,published_set_id=published_set,set_membership_status=membership,source_set_roster_member=bool(setid in sets and ident in sets[setid]['item_ids']),effects=slots,extra_current_relationships=extras,all_linked_definitions_accepted=all_reviewed,source_execution_dependencies=execution,relationship_change_needed=has_changes,holds=sorted(item_reasons),green_effects_or_set_declared=bool(stats or slots or setid),mechanics_verified=False))
|
|
reasons.update(item_reasons)
|
|
return dict(items=rows,eligible_missing_equipment_items=eligible,eligible_complete_items=complete,known_spell_ids=known,counts=dict(source_records=len(rows),positive_source_records=sum(r['wire_positive']for r in rows),property_bearing_items=sum(r['green_effects_or_set_declared']for r in rows),source_effect_slots=slot_count,distinct_item_spell_ids=len(source_ids),items_with_source_effects=sum(bool(r['effects'])for r in rows),items_with_intrinsic_stats=sum(bool(r['source_intrinsic_stats'])for r in rows),source_set_users=sum(bool(r['source_set_id'])for r in rows),relationship_change_items=sum(r['relationship_change_needed']for r in rows),items_with_holds=sum(bool(r['holds'])for r in rows),eligible_missing_equipment_items=len(eligible),eligible_complete_items=len(complete),metadata=dict(metadata_counts),effect_relationships=dict(relation_counts),hold_counts=dict(reasons)))
|