367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
231 lines
15 KiB
Python
231 lines
15 KiB
Python
"""Positive self-food health regeneration, source-controlled timing/level metadata.
|
||
|
||
This distinct policy does not widen instant heal/energize or permanent mana
|
||
regeneration. Native-only effects, changed multipliers and missing parents hold.
|
||
"""
|
||
from copy import deepcopy
|
||
from pathlib import Path
|
||
import hashlib
|
||
import math
|
||
import re
|
||
|
||
import spell_crafting_compat as capture
|
||
import spell_passive_compat as codec
|
||
from spell_item_enchantment_compat import literal, method
|
||
from spell_definition_common import REQUIRED_REFERENCE_TABLES
|
||
from octo_client_data import canonical_sha256
|
||
from spell_shield_slam_compat import EXTRA_TABLES
|
||
|
||
TABLES = codec.TABLES | codec.SUPPLEMENTAL_TABLES | {'SpellCooldowns': EXTRA_TABLES['SpellCooldowns']}
|
||
|
||
POLICY = 'positive-self-food-health-regeneration-exact-effect-source-timing-v1'
|
||
KIND = 'source-existing-food-regeneration-corrections'
|
||
|
||
def contract():
|
||
return dict(policy=POLICY, source_aura=84, native_aura=84, self_target=1,
|
||
attributes=0x18000100, movement_interrupt=1,
|
||
water_and_standing_interrupt=0x40080, source_default_period_ms=5000,
|
||
source_health_tick_ms=2000, native_health_amount_multiplier=0.4,
|
||
source_category_ids=[0, 11], source_category_cooldowns_ms=[0, 60000],
|
||
source_effect_multiplier=1, native_effect_multiplier=1,
|
||
positive_parent_only=True, server_authoritative=True,
|
||
source_priority_context='existing-checked-constant-source-0-or-50')
|
||
|
||
def namespace(paths):
|
||
required = {'source_spells', 'target_spells', 'source_auras', 'target_auras',
|
||
'target_interrupts', 'source_aura_consumer', 'source_player',
|
||
'target_player', 'source_unit_defines'}
|
||
if set(paths) != required:
|
||
raise ValueError('Complete named food regeneration contract required')
|
||
texts = {k: Path(p).read_text() for k, p in paths.items()}
|
||
checks = [('source_auras', 'SPELL_AURA_MOD_REGEN', 84),
|
||
('target_auras', 'SPELL_AURA_MOD_REGEN', 84),
|
||
('source_spells', 'SPELL_ATTR_HIDE_IN_COMBAT_LOG', 256),
|
||
('target_spells', 'SPELL_ATTR0_DO_NOT_LOG', 256),
|
||
('source_spells', 'SPELL_ATTR_CASTABLE_WHILE_SITTING', 0x08000000),
|
||
('target_spells', 'SPELL_ATTR0_ALLOW_WHILE_SITTING', 0x08000000),
|
||
('source_spells', 'SPELL_ATTR_CANT_USED_IN_COMBAT', 0x10000000),
|
||
('target_spells', 'SPELL_ATTR0_NOT_IN_COMBAT_ONLY_PEACEFUL', 0x10000000),
|
||
('source_spells', 'SPELL_INTERRUPT_FLAG_MOVEMENT', 1),
|
||
('source_spells', 'AURA_INTERRUPT_FLAG_NOT_ABOVEWATER', 128),
|
||
('source_spells', 'AURA_INTERRUPT_FLAG_NOT_SEATED', 0x40000),
|
||
('target_interrupts', 'Movement', 1),
|
||
('target_interrupts', 'UnderWater', 128),
|
||
('target_interrupts', 'Standing', 0x40000)]
|
||
if any(literal(texts[key], name) != value for key, name, value in checks):
|
||
raise ValueError('Named food regen/flag semantics changed')
|
||
body = method(texts['source_aura_consumer'], 'void Aura::HandleModRegen(')
|
||
if ('m_modifier.periodictime == 0' not in body or 'm_modifier.periodictime = 5000' not in body
|
||
or not re.search(r'#define\s+REGEN_TIME_FULL\s+2000\b', texts['source_unit_defines'])
|
||
or 'float(REGEN_TIME_FULL) / float(i->GetModifier()->periodictime)' not in texts['source_player']
|
||
or 'GetTotalAuraModifier(SPELL_AURA_MOD_REGEN) * 0.4f' not in texts['target_player']):
|
||
raise ValueError('Food amount per5 regeneration contract changed')
|
||
return dict(contract=contract(), inputs={k: dict(path=str(p), sha256=hashlib.sha256(Path(p).read_bytes()).hexdigest()) for k, p in sorted(paths.items())}, source_consumer_sha256=hashlib.sha256(body.encode()).hexdigest())
|
||
|
||
def require_contract(semantics):
|
||
if not isinstance(semantics, dict) or semantics.get('contract') != contract():
|
||
raise ValueError('Reviewed named self-food contract required')
|
||
|
||
def source_columns():
|
||
return (set(capture.SCALARS) | {p + str(i + 1) for p, _, n, _ in capture.ARRAYS for i in range(n)}
|
||
| {p + str(i + 1) for p, _, _ in capture.EFFECTS for i in range(3)}
|
||
| {k for k, _ in capture.TAIL} | {k + s for k, _ in capture.TEXTS for s in ('', 'Flags')}
|
||
| {'equippedItemClass', 'equippedItemSubClassMask', 'equippedItemInventoryTypeMask',
|
||
'spellVisual1', 'spellVisual2', 'spellIconId', 'activeIconId', 'spellPriority',
|
||
'spellFamilyFlags', 'minTargetLevel', 'customFlags', 'script_name'}
|
||
| {f'effectBonusCoefficient{i}' for i in range(1, 4)})
|
||
|
||
def validate_source(source, *, semantics):
|
||
require_contract(semantics)
|
||
if not isinstance(source, dict) or set(source) != source_columns():
|
||
raise ValueError('Complete source food definition required')
|
||
text = {'name', 'nameSubtext', 'description', 'auraDescription'}
|
||
allowed = text | {k + 'Flags' for k in text} | {
|
||
'entry', 'attributes', 'category', 'categoryRecoveryTime', 'auraInterruptFlags',
|
||
'baseLevel', 'spellLevel', 'castingTimeIndex', 'rangeIndex', 'durationIndex',
|
||
'equippedItemClass', 'equippedItemSubClassMask', 'interruptFlags', 'procChance',
|
||
'spellIconId', 'spellVisual1', 'spellPriority', 'stanceBarOrder',
|
||
'effect1', 'effectBaseDice1', 'effectBasePoints1', 'effectDieSides1',
|
||
'effectImplicitTargetA1', 'effectApplyAuraName1', 'effectMultipleValue1',
|
||
*[f'effectBonusCoefficient{i}' for i in range(1, 4)],
|
||
*[f'dmgMultiplier{i}' for i in range(1, 4)]}
|
||
if any(v not in (0, '') for k, v in source.items() if k not in allowed):
|
||
raise ValueError('Unreviewed source food condition/extra effect')
|
||
for k, v in source.items():
|
||
if k in text or k == 'script_name':
|
||
if not isinstance(v, str) or '\0' in v or len(v.encode()) > 4096:
|
||
raise ValueError('Invalid source food text')
|
||
elif type(v) not in (int, float) or not math.isfinite(v):
|
||
raise ValueError('Invalid source food scalar')
|
||
expected = dict(attributes=0x18000100, auraInterruptFlags=0x40080,
|
||
castingTimeIndex=1, rangeIndex=1, interruptFlags=1, procChance=101,
|
||
equippedItemClass=-1, stanceBarOrder=-1, effect1=6,
|
||
effectApplyAuraName1=84, effectDieSides1=1, effectBaseDice1=1,
|
||
effectImplicitTargetA1=1, effectMultipleValue1=1,
|
||
effectBonusCoefficient1=0, effectBonusCoefficient2=-1,
|
||
effectBonusCoefficient3=-1, dmgMultiplier1=1, dmgMultiplier2=1, dmgMultiplier3=1)
|
||
if any(source[k] != v for k, v in expected.items()):
|
||
raise ValueError('Unreviewed source food effect/flags/multiplier')
|
||
if (source['equippedItemSubClassMask'] not in (-1, 0) or source['category'] not in (0, 11)
|
||
or source['categoryRecoveryTime'] not in (0, 60000) or source['spellPriority'] not in (0, 50)):
|
||
raise ValueError('Unreviewed food category/priority/equipment context')
|
||
for key, minimum, maximum in [('entry', 1, 0x7fffffff), ('baseLevel', 0, 255),
|
||
('spellLevel', 0, 255), ('durationIndex', 1, 0x7fffffff),
|
||
('effectBasePoints1', 0, 0xffffff)]:
|
||
codec.integer(source[key], minimum, maximum, 'source food ' + key)
|
||
return source['entry']
|
||
|
||
def source_spell(dbc, raw, offsets, *, semantics):
|
||
validate_source(raw, semantics=semantics)
|
||
# These coefficients are SQL-only. The capture helper's synthetic−1 default
|
||
# is not disk data: retain actual server0, then require native0 below.
|
||
adjusted = deepcopy(raw)
|
||
adjusted['effectBonusCoefficient1'] = -1
|
||
capture.source_spell(dbc, adjusted, offsets)
|
||
return deepcopy(raw)
|
||
|
||
def component(sources, native, schemas, *, semantics, durations):
|
||
require_contract(semantics)
|
||
if not isinstance(sources, list) or not 1 <= len(sources) <= 4096 or len({s['entry'] for s in sources}) != len(sources):
|
||
raise ValueError('Unique positive source food definitions required')
|
||
required_schemas = {'SpellCooldowns', 'SpellLevels'}
|
||
if set(schemas) != required_schemas or any(t not in native for t in REQUIRED_REFERENCE_TABLES):
|
||
raise ValueError('Complete positive food schema/context required')
|
||
for table, schema in schemas.items():
|
||
if canonical_sha256(schema) != TABLES[table][2]:
|
||
raise ValueError('Food schema changed: ' + table)
|
||
records = []
|
||
verified = []
|
||
for source in sorted(sources, key=lambda s: s['entry']):
|
||
ident = validate_source(source, semantics=semantics)
|
||
duration = durations.get(str(source['durationIndex']))
|
||
if (not isinstance(duration, dict) or duration.get('source_duration_id') != source['durationIndex']
|
||
or duration.get('target_duration_id') != source['durationIndex']
|
||
or duration.get('source_duration_per_level') != 0
|
||
or duration.get('target_duration_per_resource') != 0 or duration.get('permanent') is not False
|
||
or not 0 < duration.get('duration_ms', -1) <= duration.get('max_duration_ms', -1)):
|
||
raise ValueError('Exact finite unscaled food duration required')
|
||
selected = {table: [r for r in native[table] if (r['ID'] if table in ('Spell', 'SpellName') else r.get('SpellID')) == ident] for table in REQUIRED_REFERENCE_TABLES}
|
||
def one(table, required=False):
|
||
rows = selected[table]
|
||
if len(rows) > 1 or required and not rows:
|
||
raise ValueError('Missing/duplicate positive food context: ' + table)
|
||
return rows[0] if rows else None
|
||
name = one('SpellName', True)
|
||
text = one('Spell', True)
|
||
misc = one('SpellMisc', True)
|
||
effect = one('SpellEffect', True)
|
||
if name['Name_lang'] != source['name'] or any(text[k] != source[z] for k, z in [('NameSubtext_lang', 'nameSubtext'), ('Description_lang', 'description'), ('AuraDescription_lang', 'auraDescription')]):
|
||
raise ValueError('Positive food source/native text differs')
|
||
attrs = misc['Attributes']
|
||
if len(attrs) != 17 or attrs[:5] != [0x18000100, 0, 0, 0, 0] or any(v for i, v in enumerate(attrs[5:], 5) if i != 15) or attrs[15] & ~0x2000:
|
||
raise ValueError('Positive food native flags differ')
|
||
expected_misc = dict(codec.NEW_MISC_NEUTRAL, Attributes=attrs, DurationIndex=source['durationIndex'])
|
||
if set(misc) != set(expected_misc) | {'ID', 'SpellID', 'SpellIconFileDataID'} or any(misc[k] != v for k, v in expected_misc.items()):
|
||
raise ValueError('Positive food native timing/school differs')
|
||
codec.integer(misc['SpellIconFileDataID'], 1, 0x7fffffff, 'retained food icon')
|
||
expected_effect = dict(codec.NEW_EFFECT_NEUTRAL, Effect=6, EffectAura=84,
|
||
EffectIndex=0, EffectAmplitude=1, EffectBasePointsF=source['effectBasePoints1'] + 1,
|
||
ImplicitTarget=[1, 0], EffectMiscValue=[0, 0])
|
||
if set(effect) != set(expected_effect) | {'ID', 'SpellID'} or any(effect[k] != v for k, v in expected_effect.items()):
|
||
raise ValueError('Positive food native effect differs')
|
||
changes = []
|
||
for table in REQUIRED_REFERENCE_TABLES:
|
||
if table in ('SpellName', 'Spell', 'SpellMisc', 'SpellEffect'):
|
||
continue
|
||
old = one(table, table in ('SpellLevels', 'SpellInterrupts', 'SpellCooldowns', 'SpellXSpellVisual'))
|
||
if old is None:
|
||
if table == 'SpellCategories' and source['category']:
|
||
raise ValueError('Missing positive food category')
|
||
continue
|
||
values = {k: v for k, v in old.items() if k not in ('ID', 'SpellID')}
|
||
if table == 'SpellLevels':
|
||
expected = dict(codec.CHILD_NEUTRAL[table], SpellLevel=source['spellLevel'], BaseLevel=old['BaseLevel'])
|
||
if old['BaseLevel'] not in (0, source['baseLevel']):
|
||
raise ValueError('Unreviewed positive food baseline level')
|
||
new = dict(old, BaseLevel=source['baseLevel'])
|
||
elif table == 'SpellCooldowns':
|
||
expected = dict(codec.CHILD_NEUTRAL[table], CategoryRecoveryTime=old['CategoryRecoveryTime'])
|
||
if old['CategoryRecoveryTime'] not in (0, 1000, 60000):
|
||
raise ValueError('Unreviewed positive food cooldown')
|
||
new = dict(old, CategoryRecoveryTime=source['categoryRecoveryTime'])
|
||
elif table == 'SpellCategories':
|
||
expected = dict(codec.CHILD_NEUTRAL[table], Category=source['category'])
|
||
new = old
|
||
elif table == 'SpellInterrupts':
|
||
expected = dict(codec.CHILD_NEUTRAL[table], InterruptFlags=1, AuraInterruptFlags=[0x40080, 0])
|
||
new = old
|
||
elif table == 'SpellXSpellVisual':
|
||
expected = dict(DifficultyID=0, SpellVisualID=source['spellVisual1'], Probability=1, Priority=1,
|
||
Flags2=0, SpellIconFileID=0, ActiveIconFileID=0,
|
||
ViewerUnitConditionID=0, ViewerPlayerConditionID=0,
|
||
CasterUnitConditionID=0, CasterPlayerConditionID=0)
|
||
new = old
|
||
elif table in codec.CHILD_NEUTRAL:
|
||
expected = deepcopy(codec.CHILD_NEUTRAL[table])
|
||
if table == 'SpellAuraOptions':
|
||
expected['ProcChance'] = source['procChance']
|
||
new = old
|
||
else:
|
||
raise ValueError('Unreviewed food side dependency: ' + table)
|
||
if values != expected:
|
||
raise ValueError('Positive food side context differs: ' + table)
|
||
if new != old:
|
||
changes.append((table, old, new))
|
||
for table, old, new in changes:
|
||
wire = codec.encode(new, schemas[table])
|
||
codec.encode(old, schemas[table])
|
||
records.append(dict(table_name=table, table_hash=hex(TABLES[table][0]),
|
||
id=new['ID'], record=new, wire_hex=wire.hex(),
|
||
sha256=hashlib.sha256(wire).hexdigest(), source_spell_id=ident,
|
||
baseline_record=deepcopy(old), baseline_record_sha256=canonical_sha256(old),
|
||
changed_fields=sorted(k for k in old if old[k] != new[k]),
|
||
allocation_policy='same-ID-source-food-context-correction'))
|
||
verified.append(dict(spell_id=ident, source_record_sha256=canonical_sha256(source),
|
||
source_definition=deepcopy(source), retained_icon_file_id=misc['SpellIconFileDataID'],
|
||
engine_accepted=False, gameplay_verified=False))
|
||
return dict(kind=KIND, definition_policy=POLICY, build=codec.BUILD, schema=codec.SCHEMA,
|
||
records=records, spells=verified, inputs=dict(sources=deepcopy(sources), native=deepcopy(native),
|
||
schemas=deepcopy(schemas), semantics=deepcopy(semantics), durations=deepcopy(durations)),
|
||
installed=False, engine_accepted=False, gameplay_verified=False)
|