367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
116 lines
7.6 KiB
Python
116 lines
7.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Capture shared Source tables once and build a Source-only quest location census.
|
|
|
|
This is a read-only, non-atomic evidence snapshot. It is NOT a native POI
|
|
provider: map assignment, runtime spawn availability, indirect loot and script
|
|
credit are not inferred, and every candidate retains the upstream holds.
|
|
"""
|
|
import argparse
|
|
from collections import Counter
|
|
import datetime as dt
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import quest_objective_locations as q
|
|
|
|
LIMIT=1_000_000
|
|
QUEST_LIMIT=10_000
|
|
|
|
def capture_all(container):
|
|
hashes={}
|
|
def read(label,sql):
|
|
rows,digest=q._select(container,sql,LIMIT)
|
|
hashes[label]=digest
|
|
return rows
|
|
server=read('server','SELECT @@server_id,VERSION(),@@hostname;')
|
|
if len(server)!=1 or len(server[0])!=3:raise ValueError('unexpected Source server identity')
|
|
query=('SELECT entry,'+','.join('ReqCreatureOrGOId%d'%i for i in range(1,5))+','
|
|
+','.join('ReqCreatureOrGOCount%d'%i for i in range(1,5))+','
|
|
+','.join('ReqSpellCast%d'%i for i in range(1,5))+','
|
|
+','.join('ReqItemId%d'%i for i in range(1,5))+','
|
|
+','.join('ReqItemCount%d'%i for i in range(1,5))+' FROM quest_template ORDER BY entry LIMIT 10001;')
|
|
quests=[]
|
|
for row in read('quest',query):
|
|
if len(row)!=21:raise ValueError('unexpected quest query shape')
|
|
v=list(map(int,row));quests.append({'id':v[0],'creature_or_go':v[1:5],
|
|
'creature_or_go_count':v[5:9],'required_spells':v[9:13],'items':v[13:17],'item_count':v[17:21]})
|
|
if not quests or len(quests)>QUEST_LIMIT:raise ValueError('Source quest census bound')
|
|
# Source quest items form one indexed lookup; no per-quest table scans.
|
|
ids=q._numbers([i for quest in quests for i in quest['items'] if i>0])
|
|
rows=read('loot',('SELECT c.entry,c.loot_id,l.item,l.ChanceOrQuestChance,l.groupid,l.mincountOrRef,l.maxcount,l.condition_id '
|
|
'FROM creature_loot_template l JOIN creature_template c ON c.loot_id=l.entry WHERE l.item IN ('+ids+') '
|
|
'ORDER BY c.entry,l.item,l.groupid,l.mincountOrRef,l.condition_id LIMIT 1000001;'))
|
|
loot=[]
|
|
for r in rows:
|
|
if len(r)!=8:raise ValueError('unexpected creature loot query shape')
|
|
loot.append({'creature':int(r[0]),'loot_id':int(r[1]),'item':int(r[2]),'chance':float(r[3]),
|
|
'group':int(r[4]),'min_or_ref':int(r[5]),'max':int(r[6]),'condition':int(r[7])})
|
|
rows=read('templates','SELECT entry,loot_id,phase_quest_id FROM creature_template ORDER BY entry LIMIT 1000001;')
|
|
templates=[{'creature':int(r[0]),'loot_id':int(r[1]),'phase_quest_id':int(r[2])} for r in rows]
|
|
rows=read('spawns',('SELECT guid,id,id2,id3,id4,map,position_x,position_y,position_z,wander_distance,movement_type,spawn_flags,visibility_mod '
|
|
'FROM creature ORDER BY guid LIMIT 1000001;'))
|
|
spawns=[]
|
|
for r in rows:
|
|
if len(r)!=13:raise ValueError('unexpected creature spawn query shape')
|
|
spawns.append({'guid':int(r[0]),'entries':[int(x) for x in r[1:5]],'map':int(r[5]),
|
|
'x':float(r[6]),'y':float(r[7]),'z':float(r[8]),'wander':float(r[9]),'movement_type':int(r[10]),
|
|
'spawn_flags':int(r[11]),'visibility_mod':None if r[12]=='NULL' else float(r[12])})
|
|
rows=read('spawn_pools','SELECT guid,pool_entry,chance,flags FROM pool_creature ORDER BY guid,pool_entry LIMIT 1000001;')
|
|
pools=[{'guid':int(r[0]),'pool':int(r[1]),'chance':float(r[2]),'flags':int(r[3])} for r in rows]
|
|
rows=read('template_pools','SELECT id,pool_entry,chance,flags FROM pool_creature_template ORDER BY id,pool_entry LIMIT 1000001;')
|
|
template_pools=[{'creature':int(r[0]),'pool':int(r[1]),'chance':float(r[2]),'flags':int(r[3])} for r in rows]
|
|
rows=read('events','SELECT guid,event FROM game_event_creature ORDER BY guid,event LIMIT 1000001;')
|
|
events=[{'guid':int(r[0]),'event':int(r[1])} for r in rows]
|
|
return {'schema':q.SNAPSHOT,'capture_utc':dt.datetime.now(dt.timezone.utc).isoformat(),
|
|
'source':{'kind':'local-docker-read-only-select-batch','container':container,'database':'tw_world',
|
|
'server_id':server[0][0],'server_version':server[0][1],'server_hostname':server[0][2],
|
|
'consistency':'separate SELECTs; no atomic snapshot claimed','queries_sha256':hashes},
|
|
'quests':quests,'direct_loot_rows':loot,'templates':templates,'spawns':spawns,
|
|
'spawn_pools':pools,'template_pools':template_pools,'events':events}
|
|
|
|
def census(dataset):
|
|
objectives=[o for quest in dataset['quests'] for o in quest['objectives']]
|
|
candidates=[o for o in objectives if o['clusters']]
|
|
return {'quests':len(dataset['quests']),'quests_with_objectives':sum(bool(x['objectives']) for x in dataset['quests']),
|
|
'objectives':len(objectives),'objectives_with_source_anchors':len(candidates),
|
|
'quests_with_source_anchors':sum(any(o['clusters'] for o in x['objectives']) for x in dataset['quests']),
|
|
'objectives_without_anchors':len(objectives)-len(candidates),
|
|
'candidate_objectives_by_kind':dict(sorted(Counter(o['kind'] for o in candidates).items())),
|
|
'objective_hold_counts':dict(sorted(Counter(h for o in objectives for h in o['holds']).items())),
|
|
'quest_hold_counts':dict(sorted(Counter(h['reason'] for x in dataset['quests'] for h in x['holds']).items())),
|
|
'source_anchors_are_approximate':True,'native_map_assignment_and_delivery':'not established; no rows are native-ready'}
|
|
|
|
def compact(dataset):
|
|
# The complete point records remain in the hash-pinned Source snapshot.
|
|
# Keep objective-specific possible entries while sharing spawn metadata;
|
|
# pool/template-pool and event evidence can be rejoined from that snapshot.
|
|
for quest in dataset['quests']:
|
|
for objective in quest['objectives']:
|
|
for cluster in objective['clusters']:
|
|
points=cluster.pop('points')
|
|
cluster['point_refs']=[[p['guid'],p['possible_creature_entries']] for p in points]
|
|
dataset['point_reference_semantics']='[Source spawn GUID, possible source creature entries]; resolve spawn fields, pools and events from hash-pinned source snapshot'
|
|
return dataset
|
|
|
|
def main():
|
|
p=argparse.ArgumentParser(description=__doc__);sub=p.add_subparsers(dest='mode',required=True)
|
|
c=sub.add_parser('capture');c.add_argument('--container',required=True);c.add_argument('--output',type=Path,required=True)
|
|
b=sub.add_parser('build');b.add_argument('--snapshot',required=True,type=Path);b.add_argument('--output',required=True,type=Path);b.add_argument('--report',required=True,type=Path)
|
|
a=p.parse_args()
|
|
if a.mode=='capture':value=capture_all(a.container)
|
|
else:
|
|
data=a.snapshot.read_bytes();digest=hashlib.sha256(data).hexdigest()
|
|
value=q.build(json.loads(data),digest,max_quests=QUEST_LIMIT,max_rows=LIMIT)
|
|
value['source_snapshot_path']=str(a.snapshot.resolve());value['limitations'].append('batch rows are research evidence only; unresolved maps, phases, scripts and indirect loot are not native-ready')
|
|
coverage=census(value);compact(value)
|
|
a.output.parent.mkdir(parents=True,exist_ok=True)
|
|
temporary=a.output.with_name(a.output.name+'.tmp')
|
|
with temporary.open('w') as f:json.dump(value,f,separators=(',',':'),sort_keys=True,allow_nan=False);f.write('\n')
|
|
temporary.replace(a.output)
|
|
if a.mode=='build':
|
|
coverage['source_snapshot_sha256']=digest
|
|
with a.output.open('rb') as f:coverage['dataset_sha256']=hashlib.file_digest(f,'sha256').hexdigest()
|
|
a.report.parent.mkdir(parents=True,exist_ok=True);a.report.write_text(json.dumps(coverage,indent=2,sort_keys=True)+'\n')
|
|
print('Source objective batch '+a.mode+' complete')
|
|
if __name__=='__main__':main()
|