124 lines
9.6 KiB
Python
124 lines
9.6 KiB
Python
"""ItemSparse components for the 773 Turtle items with no 70334 client row.
|
|
|
|
Inputs: Codex's exported public templates (missing-sparse-public-templates.json, from the Tortoise item_template),
|
|
native 70334 curve tables exported from the canonical client's CASC (export_native.py), and the published item
|
|
package (installed armor-curve override). Conversion is ops/item_catalog_stage.compile_catalog, unchanged.
|
|
Output: itemsparse-773.json (encodable ItemSparse rows) and holds-773.json (per-item reason, nothing dropped silently).
|
|
"""
|
|
import sys,json,copy,hashlib
|
|
from pathlib import Path
|
|
sys.path.insert(0,'/mnt/Games/@project/gateway/ops')
|
|
from item_catalog_stage import compile_catalog
|
|
from item_sparse_compat import fields,check_db2,TABLE,LAYOUT
|
|
from item_package_preflight import target_index
|
|
from item_armor_compat import ARMOR_TABLES,effective_armor_tables,native_armor_baseline
|
|
from item_damage_profile import WEAPON_CURVE_TABLES,native_weapon_baseline
|
|
HERE=Path(__file__).resolve().parent
|
|
G=Path('/mnt/Games/@project/gateway')
|
|
D=Path('/home/praxis/Projects/WoW-Hybrid/tools/WoWDBDefs/definitions')
|
|
SRC=G/'runtime/continuation-20261113/codex/codec-octo-recipes-20261122/missing-sparse-public-templates.json'
|
|
load=lambda p:json.loads(Path(p).read_text())
|
|
templates=load(SRC)
|
|
import source_fixes; source_fixes.apply(templates) # reviewed corrections (ops/claude_itemsparse_773/source_fixes.py)
|
|
# Material -1 ("no material") -> native 0; established rule (native row wins where one exists; none exist here).
|
|
for t in templates:
|
|
if t.get('material')==-1:t['material']=0
|
|
# Owner 2026-11-22: stat-bearing drops whose Tortoise item_level is 0 take the item level of the same boss's other
|
|
# drops of the same quality (local tw_world creature_loot_template). Both bosses: every other rare = 78, epic = 76.
|
|
ITEM_LEVEL_FROM_BOSS_SIBLINGS={
|
|
33285:dict(item_level=76,boss=62940,boss_name='Selenaxx Foulheart',quality=4,siblings=[33283,33284,33286]),
|
|
33287:dict(item_level=78,boss=62946,boss_name='Trioch the Devourer',quality=3,siblings=[33289,33290,33281]),
|
|
33288:dict(item_level=78,boss=62946,boss_name='Trioch the Devourer',quality=3,siblings=[33289,33290]),
|
|
}
|
|
for t in templates:
|
|
fix=ITEM_LEVEL_FROM_BOSS_SIBLINGS.get(t['entry'])
|
|
if fix:
|
|
assert t['item_level']==0 and t['quality']==fix['quality'],t['entry']
|
|
t['item_level']=fix['item_level']
|
|
PROFILE=HERE/'weapon-profile-ext/profile.json' # installed profile e38f8ba8 + post-snapshot weapons (ops/claude_itemsparse_773/extend_weapon_profile.py)
|
|
presentation=load(PROFILE) # the profile installed in the client's SourceWeaponDamageData.lua (sha e38f8ba8)
|
|
schema=fields(D/'ItemSparse.dbd')
|
|
points=target_index(load(HERE/'RandPropPoints.json'),'RandPropPoints')
|
|
package=load(G/'docs/evidence/data/item-sparse-compat/package.json')
|
|
schemas={n:fields(D/f'{n}.dbd',layout,count) for n,(table,layout,count) in ARMOR_TABLES.items()}
|
|
tables={n:load(HERE/f'{n}.json') for n in ARMOR_TABLES}
|
|
effective,applied=effective_armor_tables(tables,package,schemas)
|
|
def armor(proto):
|
|
# 70334 ItemTemplate::GetArmor returns 0 when no curve row exists for the item level (item level 0 here).
|
|
level=proto['item_level'];shield=proto['subclass']==6
|
|
ids=lambda n:{r['ID'] for r in effective[n]}
|
|
if (shield and level not in ids('ItemArmorShield')) or (not shield and (level not in ids('ItemArmorQuality') or level not in ids('ItemArmorTotal'))):
|
|
return dict(kind='native-70334-item-armor-baseline',identity={k:proto[k] for k in ('entry','class','subclass','inventory_type','item_level','quality')},
|
|
native_armor=0,inputs={'native_missing_level':level},policy='GetArmor-missing-curve-row-returns-0')
|
|
value=native_armor_baseline(proto,effective['ItemArmorQuality'],effective['ItemArmorTotal'],effective['ArmorLocation'],effective['ItemArmorShield'])
|
|
value['identity']['entry']=proto['entry'];return value
|
|
weapons={n:load(HERE/f'{n}.json') for n in WEAPON_CURVE_TABLES}
|
|
# ---- Owner 2026-11-22 "fix them all": every held item converts; nothing is dropped. Rules, each with its evidence:
|
|
RULES=dict(flags_dropped={},bag_family_zeroed={},stat_presentation={},armor_presentation={})
|
|
budget_ids={r['ID'] for r in load(HERE/'RandPropPoints.json')}
|
|
def budget_index(t):
|
|
inv=t['inventory_type']
|
|
if t['class']==2 and inv in (15,26) and t['subclass'] in (2,3,18,19):return 4
|
|
return 0 if inv in (1,4,5,7,15,17,20,25) else 1 if inv in (3,6,8,10,12) else 2 if inv in (2,9,11,14,16,23) else 3 if inv in (13,21,22) else (3 if t['subclass']==19 else 0) if inv==26 else 4 if inv==28 else None
|
|
RES=(('fire_res','Fire Resistance'),('frost_res','Frost Resistance'),('holy_res','Holy Resistance'),('shadow_res','Shadow Resistance'),('nature_res','Nature Resistance'),('arcane_res','Arcane Resistance'))
|
|
STAT_NAMES={0:'Mana',1:'Health',3:'Agility',4:'Strength',5:'Intellect',6:'Spirit',7:'Stamina'}
|
|
PAGE_ALIASES={int(k):v for k,v in load(G/'ops/claude_itemsparse_773/page-text-aliases.json').items()}
|
|
RULES['page_aliases']={}
|
|
for t in templates:
|
|
# Tortoise ITEM_FLAG_DEPRECATED 0x10 and ITEM_FLAG_UNK8 0x100 have no consumer in the Tortoise server; on 70334
|
|
# they are DEPRECATED ("cannot equip or use") and LEGACY (hidden). 0x40 stays on the reviewed deferral path.
|
|
if t['flags']&0x110:RULES['flags_dropped'][t['entry']]=t['flags']&0x110;t['flags']&=~0x110
|
|
# Turtle MEAT(10)/FISH(11) bag types: no Turtle bag uses them; the client's vanilla meats and fish carry 0.
|
|
# 70334 ItemSparse.PageID is u16: pages above 65535 use the gateway's client aliases (include/gateway/page_text_aliases.hpp).
|
|
if t['page_text']>0xffff:RULES['page_aliases'][t['entry']]=[t['page_text'],PAGE_ALIASES[t['page_text']]];t['page_text']=PAGE_ALIASES[t['page_text']]
|
|
if t['bag_family'] in (10,11):RULES['bag_family_zeroed'][t['entry']]=t['bag_family'];t['bag_family']=0
|
|
stats=[(t['stat_type%d'%k],t['stat_value%d'%k]) for k in range(1,11) if t['stat_value%d'%k]]
|
|
res=[(n,t[f]) for f,n in RES if t.get(f)]
|
|
budgetless=t['quality'] not in (2,3,4,5,6,7) or t['item_level'] not in budget_ids or budget_index(t) is None or any(s_ not in STAT_NAMES for s_,_ in stats)
|
|
if not budgetless:continue
|
|
# 70334 GetRandomPropertyPoints gives poor/common quality (and levels without a RandPropPoints row) a zero budget,
|
|
# so stats, resistances, bonus armor and block cannot be stored in ItemSparse. The source values go to the tooltip
|
|
# providers (SourceItemStats.lua / SourceItemArmor.lua); the server applies the real values.
|
|
lines=[[s_,v] for s_,v in stats]+[[n,v] for n,v in res]
|
|
for k in range(1,11):t['stat_value%d'%k]=0
|
|
for f,_ in RES:t[f]=0
|
|
if t.get('block'):lines.append(['Block',t['block']]);t['block']=0
|
|
if t['armor']:
|
|
if t['class']==4 and t['subclass'] in (1,2,3,4,6):
|
|
base=armor(t)['native_armor']
|
|
if t['armor']!=base:RULES['armor_presentation'][t['entry']]=t['armor'];t['armor']=base
|
|
else:lines.append(['Armor',t['armor']]);t['armor']=0
|
|
elif t['class']==4 and t['subclass'] in (1,2,3,4,6) and armor(t)['native_armor']:
|
|
RULES['armor_presentation'][t['entry']]=0;t['armor']=armor(t)['native_armor']
|
|
if lines:RULES['stat_presentation'][t['entry']]=lines
|
|
compiled=compile_catalog(templates,{},points,{},schema,{},armor,package,[],lambda p:native_weapon_baseline(p,weapons))
|
|
from item_sparse_compat import convert,encode,stat_budget
|
|
sys.path.insert(0,str(G/'ops/claude_itemsparse_773'))
|
|
import weapon_rules; weapon_rules.install() # owner-approved opt-in rules; pinned module untouched
|
|
projected=[]
|
|
for item in compiled['items']:
|
|
p=item['source']
|
|
if p['class']!=2 or any(c['table_name']=='ItemSparse' for c in item['components']):continue
|
|
try:
|
|
projection=weapon_rules.project(p,weapons,presentation)
|
|
row=convert(p,dict(ClassID=p['class'],SubclassID=p['subclass'],InventoryType=p['inventory_type']),stat_budget(p,points),schema,
|
|
weapon_projection=projection,weapon_presentation_profile=presentation,defer_instance_initializer=True)
|
|
raw=encode(row,schema)
|
|
item['components'].append(dict(table_name='ItemSparse',record=row,wire_hex=raw.hex(),sha256=hashlib.sha256(raw).hexdigest()))
|
|
item['dependencies']=[d for d in item['dependencies'] if d['kind']!='weapon-damage-bands-not-converted']+[dict(kind='source-primary-tooltip-provider-required')]
|
|
item['errors'].pop('ItemSparse',None);projected.append(p['entry'])
|
|
except (ValueError,OverflowError) as error:item['errors']['ItemSparse']=str(error)
|
|
rows=[];holds=[]
|
|
for item in compiled['items']:
|
|
sparse=[c for c in item['components'] if c['table_name']=='ItemSparse']
|
|
if sparse:rows.append(dict(id=item['entry'],record=sparse[0]['record'],wire_hex=sparse[0]['wire_hex'],sha256=sparse[0]['sha256'],
|
|
source_record_sha256=item['source_record_sha256'],dependencies=item['dependencies']))
|
|
else:holds.append(dict(id=item['entry'],name=item['source'].get('name'),cls=item['source']['class'],reason=item['errors'].get('ItemSparse')))
|
|
out=dict(kind='claude-itemsparse-773',rules=RULES,item_level_from_boss_siblings=ITEM_LEVEL_FROM_BOSS_SIBLINGS,projected_weapon_ids=projected,presentation_sha256=hashlib.sha256(PROFILE.read_bytes()).hexdigest(),source_sha256=hashlib.sha256(SRC.read_bytes()).hexdigest(),armor_overrides_applied=applied,
|
|
counts=compiled['counts'],rows=rows)
|
|
(HERE/'itemsparse-773.json').write_text(json.dumps(out,sort_keys=True,indent=1)+'\n')
|
|
(HERE/'holds-773.json').write_text(json.dumps(holds,sort_keys=True,indent=1)+'\n')
|
|
from collections import Counter
|
|
print('templates',len(templates),'rows',len(rows),'holds',len(holds),'projected weapons',len(projected))
|
|
for k,v in Counter(h['reason'] for h in holds).most_common(15):print(' ',v,k)
|