Files

62 lines
3.3 KiB
Python

"""Bind a separately baked gathering lock only to the verified herb chest entries."""
SOURCE_LOCK = 259
CLIENT_LOCK = 4582
# Each of these spawned chests has a plant item in its source loot table.
HERBS = {13891, 17282, 141853, 164958, 175566, 175928, 176753, 2020023}
DECLARATION = 'inline std::optional<GameObjectTemplateAuthority> lookup('
DEFAULT_RESOLVER = 'out.references=reference;return out;'
HERB_RESOLVER = f'''out.references=reference;
if(r->type==3 && r->data[0]=={SOURCE_LOCK} &&
std::binary_search(std::begin(TrackedHerbEntries),std::end(TrackedHerbEntries),r->entry))
out.references=herb_reference;
return out;'''
def tracking_profile(header, links, templates, native, quests, link):
if CLIENT_LOCK not in native:
if CLIENT_LOCK in links or 'TrackedHerbEntries' in header:
raise ValueError('Gathering profile requires the paired baked Lock.db2')
return header
def shape(row):
return (int(row['Flags']), *(tuple(map(int, row[field].split(',')))
for field in ('Index', 'Skill', 'Type', 'Action')))
zeros = (0,) * 8
source = (0, (0, 13, 2, 0, 0, 0, 0, 0), zeros, (0, 2, 2, 0, 0, 0, 0, 0), zeros)
target = (0, (2, 13, 0, 0, 0, 0, 0, 0), zeros, (2, 2, 0, 0, 0, 0, 0, 0), zeros)
if shape(native[SOURCE_LOCK]) != source or shape(native[CLIENT_LOCK]) != target:
raise ValueError('Unexpected stock or baked gathering lock definition')
target_link = link(CLIENT_LOCK, native[CLIENT_LOCK])
if CLIENT_LOCK in links and links[CLIENT_LOCK] != target_link:
raise ValueError('Gathering lock collides with an existing profile link')
quest_bits = {962: 907, 2641: 619}
if any(quests.get(q, {}).get('UniqueBitFlag') != str(bit) for q, bit in quest_bits.items()):
raise ValueError('Gathering profile requires the two reviewed native QuestV2 rows')
# These two source herbs need a quest to gather. Verify all eight source quest fields.
required_quests = {13891: 962, 141853: 2641}
matched = {}
for entry, kind, fields in templates:
if int(entry) in HERBS and int(kind) == 3:
words = fields.split(',')
if int(words[0]) == SOURCE_LOCK:
matched[int(entry)] = int(words[8])
if matched != {entry: required_quests.get(entry, 0) for entry in HERBS}:
raise ValueError('A reviewed herb template changed type, source lock or required quest')
links[CLIENT_LOCK] = target_link
entries = ','.join(str(n) for n in sorted(HERBS))
helper = ('inline constexpr uint32_t TrackedHerbEntries[]={' + entries + '};\n'
'inline std::optional<uint32_t> herb_reference(GameObjectTemplateReference kind,uint32_t value){\n'
' if(kind==GameObjectTemplateReference::Quest && (value==962 || value==2641))return value;\n'
f' return reference(kind,kind==GameObjectTemplateReference::Lock && value=={SOURCE_LOCK}?{CLIENT_LOCK}:value);\n'
'}\n')
if helper in header and HERB_RESOLVER in header:
return header
if (header.count(DECLARATION) != 1 or header.count(DEFAULT_RESOLVER) != 1 or
'TrackedHerbEntries' in header):
raise ValueError('Unrecognized game-object authority lookup')
return header.replace(DECLARATION, helper + DECLARATION).replace(DEFAULT_RESOLVER, HERB_RESOLVER)