71 lines
3.6 KiB
Python
71 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Source creature weapon displays -> client item IDs for UnitData.VirtualItems.
|
|
|
|
Turtle Creature::SetVirtualItem writes UNIT_VIRTUAL_ITEM_DISPLAY (1.12 fields
|
|
37..39) = item_template.display_id; 70334 VirtualItems[].ItemID wants an Item ID
|
|
whose appearance the client renders. For every source weapon/shield/held/ranged
|
|
display, prefer a client item whose default appearance uses that display.
|
|
Otherwise, prefer a source item with the same display and a complete client
|
|
appearance chain. Displays with no renderable client item stay empty-handed (Q108).
|
|
|
|
usage: creature_virtual_item_profile.py <baked-db2-dir> <output.hpp>
|
|
"""
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent / 'claude_recipe_parity'))
|
|
import dbd
|
|
|
|
# Weapon (2) any; armor (4) shields (6); held-in-hand / ranged / thrown / relic inventory types.
|
|
HELD = {13, 14, 15, 17, 21, 22, 23, 25, 26, 28}
|
|
|
|
|
|
def source_items():
|
|
sql = 'SELECT entry,display_id,class,subclass,inventory_type FROM tw_world.item_template WHERE display_id>0;'
|
|
out = subprocess.run(['docker', 'exec', '-i', 'tortoise-docker-db-1', 'sh', '-c', 'mariadb -uroot -p"$MYSQL_ROOT_PASSWORD" -N'],
|
|
input=sql, capture_output=True, text=True, check=True).stdout
|
|
rows = [tuple(map(int, l.split('\t'))) for l in out.splitlines() if l.strip()]
|
|
return [r for r in rows if r[2] == 2 or (r[2] == 4 and r[3] == 6) or r[4] in HELD]
|
|
|
|
|
|
def main(baked, output):
|
|
baked = Path(baked)
|
|
items = set(dbd.table('Item', str(baked / 'Item.db2'))['rows'])
|
|
displays = set(dbd.table('ItemDisplayInfo', str(baked / 'ItemDisplayInfo.db2'))['rows'])
|
|
appearance = {i: r['ItemDisplayInfoID'] for i, r in dbd.table('ItemAppearance', str(baked / 'ItemAppearance.db2'))['rows'].items()}
|
|
own = {}
|
|
renderable = set()
|
|
for r in dbd.table('ItemModifiedAppearance', str(baked / 'ItemModifiedAppearance.db2'))['rows'].values():
|
|
if r.get('ItemAppearanceModifierID', 0) == 0 and r['ItemID'] in items:
|
|
d = appearance.get(r['ItemAppearanceID'])
|
|
if d and d in displays:
|
|
own.setdefault(d, set()).add(r['ItemID'])
|
|
renderable.add(r['ItemID'])
|
|
by_display = {}
|
|
for entry, display, *_ in source_items():
|
|
by_display.setdefault(display, set()).add(entry)
|
|
rows, unmapped = [], 0
|
|
for display in sorted(by_display):
|
|
source = by_display[display] & items
|
|
# Q108: never an item without a resolvable appearance (display 0 asserts in SheatheHandItem).
|
|
candidates = own.get(display) or (source & renderable)
|
|
pick = min(candidates, default=0)
|
|
if pick:
|
|
rows.append((display, pick))
|
|
else:
|
|
unmapped += 1
|
|
body = ',\n'.join(','.join('{%d,%d}' % r for r in rows[i:i + 12]) for i in range(0, len(rows), 12))
|
|
Path(output).write_text(
|
|
'// Generated by ops/creature_virtual_item_profile.py: source item display -> client item for creature VirtualItems.\n'
|
|
'#pragma once\n#include <algorithm>\n#include <cstdint>\n#include <iterator>\n'
|
|
'namespace gateway::creature_virtual_item_profile {\n'
|
|
'struct Row {uint32_t display,item;};\ninline constexpr Row Rows[]={\n' + body + '};\n'
|
|
'inline uint32_t item(uint32_t display){auto it=std::lower_bound(std::begin(Rows),std::end(Rows),display,[](const Row& r,uint32_t d){return r.display<d;});'
|
|
'return it!=std::end(Rows)&&it->display==display?it->item:0;}\n}\n')
|
|
print('displays', len(by_display), 'mapped', len(rows), 'unmapped', unmapped)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main(*sys.argv[1:3])
|