Files
WoW-Hybrid-gateway/ops/source_mount_compat.py
2026-11-23 03:28:32 +02:00

195 lines
9.8 KiB
Python

"""Source-owned mount journal requirements, without a foreign riding template.
The Source server checks item acquisition requirements and mount spell casting.
Its mounted/speed auras remain authoritative. Native70334 template6 is a Brown
Horse whose type469 adds Horse Riding824 and speed86457; it is not a generic
Source mount contract. Existing native type283/cap315 adds neither requirement
nor speed aura. No original native Mount record is rewritten here.
"""
from copy import deepcopy
POLICY = 'source-mounted-collection-native-environment-v1'
NATIVE_TYPE = {'ID': 1087, 'MountTypeID': 283, 'MountCapabilityID': 315, 'OrderIndex': 0}
NATIVE_CAPABILITY = dict(ID=315, Flags=17, ReqRidingSkill=0, ReqAreaID=0,
ReqSpellAuraID=0, ReqSpellKnownID=0, ModSpellAuraID=0, ReqMapID=-1,
PlayerConditionID=0, FlightCapabilityID=0, DriveCapabilityID=0)
def source_mount_environment(collection_records, spell_records, *,
native_type_records, native_capability_records):
"""Qualify the complete supplied collection by associated Source spell ID.
Scripted/unmounted or incomplete prototypes are explicit holds. Item level,
riding/engineering skill and item requirements are never inputs to this
journal-only translation and are never removed from ItemSparse.
"""
relations = [r for r in native_type_records if r.get('MountTypeID') == 283]
capabilities = [r for r in native_capability_records if r.get('ID') == 315]
if relations != [NATIVE_TYPE] or capabilities != [NATIVE_CAPABILITY]:
raise ValueError('Pinned native283/315 environment contract differs')
spells = {}
for row in spell_records:
ident = row.get('entry')
if type(ident) is not int or ident <= 0 or ident in spells:
raise ValueError('Unique Source spell prototype IDs required')
spells[ident] = row
associations = {}
item_ids, pairs = set(), set()
item_spells = {}
for row in collection_records:
item, spell = row.get('itemId'), row.get('spellId')
if any(type(v) is not int or v <= 0 for v in (item, spell)) or (item, spell) in pairs:
raise ValueError('Unique Source collection item/spell pair required')
pairs.add((item, spell))
item_ids.add(item)
item_spells.setdefault(item, set()).add(spell)
associations.setdefault(spell, []).append(item)
profiles, held = {}, []
for ident, items in sorted(associations.items()):
row = spells.get(ident)
fields = [name + str(i) for i in (1, 2, 3)
for name in ('effect', 'effectApplyAuraName', 'effectBasePoints',
'effectMiscValue', 'effectTriggerSpell')]
if row is None or any(type(row.get(k)) is not int for k in fields):
reason = 'incomplete-Source-mount-prototype'
else:
effects = [(row['effect'+str(i)], row['effectApplyAuraName'+str(i)])
for i in (1, 2, 3)]
mounted = [i for i, pair in enumerate(effects, 1) if pair == (6, 78)]
# This qualified class has one mounted aura plus Source movement
# speed, optionally water breathing. Other/scripted classes stay held.
if (len(mounted) != 1 or (6, 32) not in effects or
any(pair not in ((0, 0), (6, 78), (6, 32), (6, 58)) for pair in effects)):
reason = 'scripted-or-unqualified-Source-mounted-aura-family'
else:
reason = None
if reason:
held.append(dict(source_spell_id=ident, source_item_ids=sorted(items), reason=reason))
continue
profiles[ident] = dict(policy=POLICY, source_spell_id=ident,
source_item_ids=sorted(items), MountTypeID=283,
native_type=deepcopy(NATIVE_TYPE), native_capability=deepcopy(NATIVE_CAPABILITY))
return dict(profiles=profiles, held=held, collection_items=len(item_ids),
collection_rows=len(pairs), collection_spells=len(associations),
qualified_spells=len(profiles),
# Source MountManager's item lookup overwrites duplicates in DB
# iteration order. This journal translation uses explicit spell
# identity only; it neither chooses nor rewrites item acquisition.
ambiguous_acquisition_items={item: sorted(values) for item, values
in sorted(item_spells.items()) if len(values) > 1})
def source_item_mount_environment(item_records, spell_records, *,
native_type_records, native_capability_records):
"""Qualify direct on-use mount definitions without claiming learned ownership.
Some retained Source mounts are directly cast by an item, rather than learned
by the collection script. This branch changes journal definition environment
only; ItemSparse acquisition/use requirements and gateway ownership stay intact.
"""
spell_ids = {row['entry'] for row in spell_records}
associations, items = [], set()
for row in item_records:
ident = row.get('entry')
if type(ident) is not int or ident <= 0 or ident in items:
raise ValueError('Unique Source direct-mount item prototypes required')
items.add(ident)
for i in (1, 2, 3, 4, 5):
spell, trigger = row.get('spellid_'+str(i)), row.get('spelltrigger_'+str(i))
if type(spell) is not int or type(trigger) is not int:
raise ValueError('Complete Source item on-use bindings required')
pair = dict(itemId=ident, spellId=spell)
if trigger == 0 and spell in spell_ids and pair not in associations:
associations.append(pair)
plan = source_mount_environment(associations, spell_records,
native_type_records=native_type_records,
native_capability_records=native_capability_records)
for profile in plan['profiles'].values():
profile['association_kind'] = 'Source-direct-on-use-item-definition-only'
profile['learned_collection_ownership_claimed'] = False
return plan
def apply_source_mount_environment(record, profile):
"""Change only MountTypeID after explicit Source/native relationship proof."""
ident = record.get('SourceSpellID')
if (not isinstance(profile, dict) or profile.get('policy') != POLICY or
profile.get('source_spell_id') != ident or profile.get('MountTypeID') != 283 or
profile.get('native_type') != NATIVE_TYPE or
profile.get('native_capability') != NATIVE_CAPABILITY or
not profile.get('source_item_ids')):
raise ValueError('Qualified Source mounted collection environment required')
return dict(deepcopy(record), MountTypeID=283)
def qualify_existing_source_mounts(native_records, environment):
"""Join native same-ID mounts to the qualified Source spell catalogue.
Preserve every native field except the environment type, including its name,
display relationships and conditions. A native spell outside the explicit
Source authority is unrelated and remains byte-for-byte unchanged. A Source
script/prototype hold stays held rather than inheriting the generic type.
"""
if not isinstance(environment, dict) or not isinstance(environment.get('profiles'), dict):
raise ValueError('Qualified Source mount environment catalogue required')
profiles = environment['profiles']
source_holds = {r['source_spell_id']: r for r in environment.get('held', [])}
ids, spells, records, unchanged, held = set(), set(), [], [], []
for row in native_records:
ident, spell = row.get('ID'), row.get('SourceSpellID')
if (any(type(v) is not int or v <= 0 for v in (ident, spell)) or
ident in ids or spell in spells):
raise ValueError('Unique native Mount ID/SourceSpellID records required')
ids.add(ident); spells.add(spell)
if spell in profiles:
records.append(apply_source_mount_environment(row, profiles[spell]))
else:
unchanged.append(deepcopy(row))
if spell in source_holds:
held.append(dict(id=ident, **source_holds[spell]))
return dict(records=records, unchanged=unchanged, held=held,
native_rows=len(ids), Source_qualified_rows=len(records),
unrelated_native_rows=sum(row['SourceSpellID'] not in source_holds
for row in unchanged))
def dismount_profile():
"""Render the local Source world's mounted spell IDs for CancelMountAura."""
from local_tortoise import db
# Both fields must match in the same effect slot. Scripted learning spells
# and movement-speed auras alone cannot identify a mounted holder.
mounted = ' OR '.join(
f'(effect{slot} = 6 AND effectApplyAuraName{slot} = 78)'
for slot in (1, 2, 3))
ids = [int(row) for row in db(
f'SELECT entry FROM tw_world.spell_template WHERE {mounted} ORDER BY entry;'
).splitlines()]
if not ids or ids != sorted(set(ids)) or not (0 < ids[0] <= ids[-1] <= 0xffffffff):
raise ValueError('Expected unique ordered Source mounted spell IDs')
lines = [' ' + ', '.join(map(str, ids[i:i + 12])) + ','
for i in range(0, len(ids), 12)]
return '''// Generated by ops/source_mount_compat.py dismount-profile.
#pragma once
#include <algorithm>
#include <cstdint>
#include <iterator>
namespace gateway::source_mounted_spells {
inline constexpr std::uint32_t Spells[] = {
''' + '\n'.join(lines) + '''
};
inline bool contains(std::uint32_t spell) {
return std::binary_search(std::begin(Spells), std::end(Spells), spell);
}
}
'''
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description='Generate Source mount gameplay profiles')
parser.add_argument('action', choices=['dismount-profile'])
parser.parse_args()
print(dismount_profile(), end='')