367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
180 lines
12 KiB
Python
180 lines
12 KiB
Python
"""Source constant self extra-attack definitions, not client-side execution.
|
|
|
|
Uses original source spell IDs and shared row allocation/serialization. A visual
|
|
collision requires explicit separately allocated visual/event dependencies; no
|
|
source visual is dropped to fit an unrelated restoration policy. Generated rows
|
|
remain uninstalled candidates until dependency and actual-engine checks pass.
|
|
"""
|
|
from copy import deepcopy
|
|
import hashlib
|
|
from pathlib import Path
|
|
from octo_client_data import canonical_sha256
|
|
from spell_result_profile import enum
|
|
from spell_family_compat import validate_family
|
|
from spell_definition_common import (checked_constant_source, review_effect_shape,
|
|
REQUIRED_REFERENCE_TABLES, NEW_DEFINITION_CHILD_TABLES, review_new_timing,
|
|
new_definition_records)
|
|
from spell_passive_compat import (BUILD, SCHEMA, TABLES, SUPPLEMENTAL_TABLES, CONDITIONS,
|
|
NEW_EFFECT_NEUTRAL, integer, encode, new_registry_values, verified_spell_icon)
|
|
from item_batch_stage import available_index
|
|
from spell_visual_compat import review_candidate as review_visual
|
|
|
|
POLICY = 'new-constant-self-extra-attack-definition-v2'
|
|
HEADERS = {'source': 'fd1c65c0266b77a310c066bc3ccce86fe39f73a6cd10f67192d419009f95ead1',
|
|
'target': '9b0e2ad90eea77c961b00f1fc482e9d9e521aa85c58b63863a35d3a338a31799'}
|
|
|
|
|
|
def namespace(source, target):
|
|
for role, path in (('source', source), ('target', target)):
|
|
path = Path(path)
|
|
if hashlib.sha256(path.read_bytes()).hexdigest() != HEADERS[role]:
|
|
raise ValueError('Pinned extra-attack header changed')
|
|
if enum(path, 'SpellEffects')[0].get('SPELL_EFFECT_ADD_EXTRA_ATTACKS') != 19:
|
|
raise ValueError('Named extra-attack effect differs')
|
|
if enum(path, 'SpellTarget' if role == 'source' else 'Targets')[0].get('TARGET_UNIT_CASTER') != 1:
|
|
raise ValueError('Named self target differs')
|
|
if enum(path, 'SpellAttributes' if role == 'source' else 'SpellAttr0')[0].get(
|
|
'SPELL_ATTR_PASSIVE' if role == 'source' else 'SPELL_ATTR0_PASSIVE') != 64:
|
|
raise ValueError('Named passive attribute differs')
|
|
return dict(policy='named-self-extra-attack-v1', header_sha256=dict(HEADERS),
|
|
effect_name='SPELL_EFFECT_ADD_EXTRA_ATTACKS', source_effect=19, target_effect=19,
|
|
target_name='TARGET_UNIT_CASTER', source_target=1, target_target=1,
|
|
source_passive_name='SPELL_ATTR_PASSIVE', target_passive_name='SPELL_ATTR0_PASSIVE',
|
|
source_passive=64, target_passive=64)
|
|
|
|
|
|
def validate_namespace(proof):
|
|
expected = dict(policy='named-self-extra-attack-v1', header_sha256=HEADERS,
|
|
effect_name='SPELL_EFFECT_ADD_EXTRA_ATTACKS', source_effect=19, target_effect=19,
|
|
target_name='TARGET_UNIT_CASTER', source_target=1, target_target=1,
|
|
source_passive_name='SPELL_ATTR_PASSIVE', target_passive_name='SPELL_ATTR0_PASSIVE',
|
|
source_passive=64, target_passive=64)
|
|
if (not isinstance(proof, dict) or proof != expected or
|
|
any(type(proof.get(k)) is not int for k in
|
|
('source_effect', 'target_effect', 'source_target', 'target_target',
|
|
'source_passive', 'target_passive'))):
|
|
raise ValueError('Pinned named extra-attack namespace required')
|
|
|
|
|
|
def source_spell(dbc, raw, offsets, *, family_namespace, semantics):
|
|
src = checked_constant_source(dbc, raw, offsets, family_namespace=family_namespace)
|
|
src['extra_attack_semantics'] = deepcopy(semantics)
|
|
validate_source(src)
|
|
return src
|
|
|
|
|
|
def validate_source(src,*,constant_coefficient=False):
|
|
if type(constant_coefficient)is not bool:raise ValueError('Typed coefficient review required')
|
|
validate_namespace(src.get('extra_attack_semantics'))
|
|
integer(src.get('entry'), 1, 0x7fffffff, 'extra-attack source ID')
|
|
for key, count in (('attributes', 5), ('power', 6), ('equippedItem', 3), ('visuals', 2)):
|
|
if (not isinstance(src.get(key), list) or len(src[key]) != count or
|
|
any(type(v) is not int for v in src[key])):
|
|
raise ValueError('Typed extra-attack scalar groups required')
|
|
for key in ('school', 'castingTimeIndex', 'durationIndex', 'rangeIndex'):
|
|
integer(src.get(key), 0, 0x7fffffff, 'extra-attack ' + key)
|
|
if (src['attributes'] != [0] * 5 or
|
|
(src['school'], src['castingTimeIndex'], src['durationIndex'], src['rangeIndex']) != (0, 1, 0, 1) or
|
|
type(src.get('speed')) not in (int, float) or src['speed'] != 0):
|
|
raise ValueError('Unreviewed extra-attack metadata')
|
|
if (src['power'] != [0] * 6 or src['equippedItem'] != [-1, 0, 0] or
|
|
validate_family(src.get('class_family')) != 0):
|
|
raise ValueError('Unreviewed extra-attack family/cost/equipment')
|
|
for v in src['visuals']: integer(v, 0, 0x7fffffff, 'extra-attack visual')
|
|
if src['visuals'][1]: raise ValueError('Secondary extra-attack visual requires review')
|
|
levels = src.get('levels')
|
|
if not isinstance(levels, dict) or set(levels) != {'spellLevel', 'baseLevel', 'maxLevel'}:
|
|
raise ValueError('Complete extra-attack levels required')
|
|
for v in levels.values(): integer(v, 0, 65535, 'extra-attack level')
|
|
conditions = src.get('conditions')
|
|
if not isinstance(conditions, dict) or set(conditions) != set(CONDITIONS):
|
|
raise ValueError('Complete extra-attack conditions required')
|
|
for k, v in conditions.items(): integer(v, 0, 101 if k == 'procChance' else 0, 'extra-attack condition')
|
|
if conditions['procChance'] not in (0, 101): raise ValueError('Unreviewed extra-attack chance')
|
|
timing = src.get('timing')
|
|
if not isinstance(timing, dict) or set(timing) != {'recoveryTime', 'categoryRecoveryTime', 'startRecoveryCategory', 'startRecoveryTime'}:
|
|
raise ValueError('Complete extra-attack timing required')
|
|
for v in timing.values(): integer(v, 0, 0, 'extra-attack cooldown')
|
|
for k in ('name', 'nameSubtext', 'description', 'auraDescription'):
|
|
if not isinstance(src.get(k), str) or '\0' in src[k] or len(src[k].encode()) > 4096:
|
|
raise ValueError('Extra-attack text bound')
|
|
effects = src.get('effects'); indices = []
|
|
if not src['name'] or not isinstance(effects, list) or len(effects) != 3:
|
|
raise ValueError('Complete extra-attack name/effects required')
|
|
for i, e in enumerate(effects):
|
|
review_effect_shape(e)
|
|
if not e[0]:
|
|
if e != [0] * 11 + [-1]: raise ValueError('Unreviewed empty extra-attack effect')
|
|
continue
|
|
if e[:2] != [19, 0] or e[3:11] != [1, 1, 0, 0, 0, 1, 0, 0] or e[11] not in ((-1, 0, 1) if constant_coefficient else (-1, 0)):
|
|
raise ValueError('Unreviewed constant extra-attack effect/target')
|
|
integer(e[2] + 1, 1, 5, 'extra-attack count'); indices.append(i)
|
|
if len(indices) != 1: raise ValueError('One constant self extra-attack effect required')
|
|
return indices
|
|
|
|
|
|
def new_component(sources, native, schemas, maxima, registry, *, source_tables,
|
|
target_icon_names, new_icon_ids, icon_assets, read_icon,
|
|
visual_candidates=None):
|
|
if (not isinstance(sources, list) or not 1 <= len(sources) <= 4096 or
|
|
len({s['entry'] for s in sources}) != len(sources)):
|
|
raise ValueError('Bounded unique extra-attack sources required')
|
|
if any(t not in native for t in (*REQUIRED_REFERENCE_TABLES, 'SpellCastTimes', 'SpellRange')):
|
|
raise ValueError('Complete extra-attack references required')
|
|
if set(new_icon_ids) != {str(s['entry']) for s in sources}:
|
|
raise ValueError('Explicit extra-attack icons required')
|
|
visual_candidates = {} if visual_candidates is None else visual_candidates
|
|
if not isinstance(visual_candidates, dict) or set(visual_candidates) != {s['visuals'][0] for s in sources if s['visuals'][0]}:
|
|
raise ValueError('Complete source-owned visual dependencies required')
|
|
tables = NEW_DEFINITION_CHILD_TABLES + (('SpellXSpellVisual',) if visual_candidates else ())
|
|
for t in {'Spell', 'SpellName', *tables, *(['SpellVisual', 'SpellVisualEvent'] if visual_candidates else [])}:
|
|
if t not in schemas or canonical_sha256(schemas[t]) != (TABLES | SUPPLEMENTAL_TABLES)[t][2]:
|
|
raise ValueError('Reviewed extra-attack schema required')
|
|
review_new_timing(source_tables, native, 0)
|
|
registry = deepcopy(registry); available = available_index(icon_assets)
|
|
occupied = {t: {r['ID'] for r in native[t]} for t in NEW_DEFINITION_CHILD_TABLES}
|
|
if visual_candidates:
|
|
occupied['SpellXSpellVisual'] = {r['ID'] for r in native['SpellXSpellVisual']}
|
|
new_registry_values(registry, maxima, occupied, tables=tables)
|
|
links = registry.pop('SpellXSpellVisual', {}) if visual_candidates else {}
|
|
records = []; spells = []; visuals = {}
|
|
for visual, candidate in sorted(visual_candidates.items()):
|
|
reviewed = review_visual(candidate, schemas, {t: {r['ID'] for r in native[t]}
|
|
for t in ('SpellVisual', 'SpellVisualEvent')})
|
|
if reviewed['source_visual_id'] != visual: raise ValueError('Visual dependency namespace differs')
|
|
visuals[visual] = reviewed; records.extend(deepcopy(reviewed['records']))
|
|
for src in sorted(sources, key=lambda s: s['entry']):
|
|
indices = validate_source(src); ident = src['entry']
|
|
for t in REQUIRED_REFERENCE_TABLES:
|
|
if any((r.get('ID') if t in ('Spell', 'SpellName') else r.get('SpellID')) == ident for r in native[t]):
|
|
raise ValueError('Extra-attack candidate has positive native reference')
|
|
fid, asset = verified_spell_icon(src, new_icon_ids, source_tables['SpellIcon'], target_icon_names, available, read_icon)
|
|
effects = {i: dict(deepcopy(NEW_EFFECT_NEUTRAL), Effect=19, EffectAura=0,
|
|
EffectBasePointsF=src['effects'][i][2] + 1, EffectMiscValue=[0, 0]) for i in indices}
|
|
records.extend(new_definition_records(src, effects, fid, schemas, maxima, registry,
|
|
occupied, allocation_prefix='new-source-extra-attack-definition'))
|
|
if src['visuals'][0]:
|
|
key = str(ident)
|
|
if key not in links: links[key] = max([maxima['SpellXSpellVisual'], *links.values()]) + 1
|
|
row = dict(ID=links[key], DifficultyID=0, SpellVisualID=visuals[src['visuals'][0]]['native_visual_id'],
|
|
Probability=1, Flags2=0, Priority=1, SpellIconFileID=0, ActiveIconFileID=0,
|
|
ViewerUnitConditionID=0, ViewerPlayerConditionID=0, CasterUnitConditionID=0,
|
|
CasterPlayerConditionID=0, SpellID=ident)
|
|
wire = encode(row, schemas['SpellXSpellVisual'])
|
|
records.append(dict(table_name='SpellXSpellVisual', table_hash=hex(SUPPLEMENTAL_TABLES['SpellXSpellVisual'][0]),
|
|
id=row['ID'], record=row, wire_hex=wire.hex(), sha256=hashlib.sha256(wire).hexdigest(),
|
|
source_spell_id=ident, baseline_record_sha256=None, allocation_policy='new-source-extra-attack-visual-link'))
|
|
spells.append(dict(spell_id=ident, source_definition=deepcopy(src), source_record_sha256=canonical_sha256(src),
|
|
class_family=deepcopy(src['class_family']), levels=deepcopy(src['levels']),
|
|
effect_indices=indices, extra_attack_count=src['effects'][indices[0]][2] + 1,
|
|
icon_asset=dict(file_data_id=fid, **asset), known_spells_modified=False, engine_accepted=False))
|
|
if visual_candidates: registry['SpellXSpellVisual'] = links
|
|
new_registry_values(registry, maxima, occupied, tables=tables)
|
|
return dict(kind='source-extra-attack-definition-candidates', build=BUILD, schema=SCHEMA,
|
|
definition_policy=POLICY, records=records, spells=spells, child_id_registry=registry,
|
|
visual_dependencies=visuals, installable=False, installed=False, dependency_complete=False,
|
|
engine_accepted=False, gameplay_verified=False,
|
|
limits=['Server owns extra-attack execution, caps, locks, proc rolls and damage.',
|
|
'Visual kit/asset parity, source-ID/API review and actual-engine acceptance remain required.',
|
|
'No learned spell, attack, proc or successful gameplay is synthesized.'])
|