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

128 lines
6.4 KiB
Python

#!/usr/bin/env python3
"""Derive public raid item cohorts from Source loot relationships.
This is an input join for existing item pipelines, not an item converter.
LootMgr::AddEntry/Process distinguishes item rows from negative references;
reference group selection is retained and all unresolved edges remain explicit.
No probabilities, conditional eligibility, native assets or runtime acceptance
are inferred from this potential-drop cohort.
"""
from collections import defaultdict
import math
MAX_ROWS = 100000
MAX_ROOTS = 4096
MAX_STATES = 10000
MAX_DEPTH = 32
def derive(roots, stores, source_items):
if not isinstance(roots, list) or not 1 <= len(roots) <= MAX_ROOTS:
raise ValueError('Bounded public raid roots required')
if set(stores) != {'creature', 'gameobject', 'reference'}:
raise ValueError('Exact Source loot stores required')
if not isinstance(source_items, list) or not 1 <= len(source_items) <= MAX_ROWS:
raise ValueError('Bounded authoritative Source item catalogue required')
source = set()
for row in source_items:
ident = row.get('entry')
if type(ident) is not int or not 0 < ident < 2**31 or ident in source:
raise ValueError('Duplicate/invalid Source item identity')
source.add(ident)
tables = {}
for name, rows in stores.items():
if not isinstance(rows, list) or len(rows) > MAX_ROWS:
raise ValueError('Bounded Source loot rows required')
indexed = defaultdict(list)
seen = set()
for row in rows:
if set(row) != {'entry', 'item', 'chance', 'group', 'mincountOrRef', 'maxcount', 'condition'}:
raise ValueError('Typed Source loot row required')
for key in ('entry', 'item', 'group', 'mincountOrRef', 'maxcount', 'condition'):
if type(row[key]) is not int:
raise ValueError('Source loot integers required')
if (not 0 < row['entry'] < 2**31 or not 0 <= row['item'] < 2**31
or not 0 <= row['group'] < 128 or not 0 <= row['maxcount'] <= 255
or not -(2**31) < row['mincountOrRef'] < 2**31
or not 0 <= row['condition'] <= 65535
or type(row['chance']) not in (int, float) or not math.isfinite(row['chance'])):
raise ValueError('Source loot framing bound')
key = row['entry'], row['item']
if key in seen:
raise ValueError('Duplicate Source loot entry/item')
seen.add(key)
indexed[row['entry']].append(row)
tables[name] = indexed
memo = {}
def walk(store, entry, group, stack):
key = store, entry, group
if key in stack:
return set(), {('reference-cycle', *key)}, set(), set()
if len(stack) >= MAX_DEPTH:
return set(), {('reference-depth-bound', *key)}, set(), set()
if key in memo:
return memo[key]
if len(memo) >= MAX_STATES:
raise ValueError('Source loot traversal state bound')
rows = tables[store].get(entry)
if not rows:
return set(), {('missing-loot-template', *key)}, set(), set()
# Source AddEntry places only positive mincount rows into Groups.
# Process(groupId) visits only that group and returns before Entries.
selected = [r for r in rows if not group or r['mincountOrRef'] > 0 and r['group'] == group]
if group and not selected:
return set(), {('missing-reference-group', *key)}, set(), set()
items, holds, references, conditions = set(), set(), set(), set()
for row in selected:
ref = row['mincountOrRef']
chance = abs(row['chance'])
if row['condition']:
conditions.add(row['condition'])
if ref == 0:
holds.add(('invalid-zero-mincount', store, entry, row['item']))
elif ref < 0:
if not chance or not row['maxcount']:
continue # Rejected zero-chance or zero-iteration reference.
target = -ref
references.add((target, row['group']))
child = walk('reference', target, row['group'], (*stack, key))
items.update(child[0]); holds.update(child[1])
references.update(child[2]); conditions.update(child[3])
elif row['item'] not in source:
holds.add(('missing-Source-item', store, entry, row['item']))
elif row['maxcount'] < ref or not chance and not row['group'] or chance and chance < 0.000001:
holds.add(('invalid-item-count-or-chance', store, entry, row['item']))
else:
items.add(row['item'])
result = items, holds, references, conditions
memo[key] = result
return result
results = []
ownership = set()
by_map = defaultdict(set)
for root in roots:
if set(root) != {'map', 'owner_kind', 'owner_entry', 'loot_entry'}:
raise ValueError('Typed Source raid root required')
if root['owner_kind'] not in ('creature', 'gameobject') or any(
type(root[k]) is not int or not 0 < root[k] < 2**31
for k in ('map', 'owner_entry', 'loot_entry')):
raise ValueError('Source raid root identity bound')
identity = root['map'], root['owner_kind'], root['owner_entry'], root['loot_entry']
if identity in ownership:
raise ValueError('Duplicate Source raid root ownership')
ownership.add(identity)
items, holds, refs, conditions = walk(root['owner_kind'], root['loot_entry'], 0, ())
by_map[root['map']].update(items)
results.append(dict(root, items=sorted(items), holds=[list(r) for r in sorted(holds)],
references=[list(r) for r in sorted(refs)],
conditional_ids=sorted(conditions), closure_complete=not holds))
return dict(kind='Source-potential-raid-loot-item-cohort', schema_version=1,
items_by_map={str(k): sorted(v) for k, v in sorted(by_map.items())}, roots=results,
distinct_items=len(set().union(*by_map.values())), root_count=len(results),
complete_roots=sum(r['closure_complete'] for r in results),
held_roots=sum(not r['closure_complete'] for r in results),
native_metadata_verified=False, conditional_eligibility_verified=False,
drop_probability_verified=False, runtime_verified=False)