883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
201 lines
14 KiB
Python
201 lines
14 KiB
Python
#!/usr/bin/env python3
|
|
"""Experimental finite-buff boundary; actual source visual is not discarded."""
|
|
import unittest,json,sys,copy
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
ROOT=Path(__file__).resolve().parents[1];sys.path[:0]=[str(ROOT/'ops'),str(ROOT/'tests')]
|
|
import spell_timed_buff_compat as m
|
|
import spell_restore_compat_test as restore_tests
|
|
import spell_passive_compat as codec
|
|
from spell_definition_common import checked_constant_source
|
|
from turtle_data import spell_layout
|
|
class TimedBuffCompatibilityTest(unittest.TestCase):
|
|
def presentation(self):
|
|
return m.presentation_namespace(Path('/home/praxis/Servers/tortoise-wow/src/game/Spells/SpellDefines.h'),
|
|
ROOT.parent/'servers/trinity-forever/src/server/game/Miscellaneous/SharedDefines.h')
|
|
|
|
def test_named_no_sheath_namespace_and_flag_are_preserved(self):
|
|
v=self.fixture();source=v[0][0]
|
|
source['attributes']=[0x40000,0,0,0,0]
|
|
with self.assertRaises(ValueError):self.convert(v)
|
|
source['presentation_context']=self.presentation()
|
|
r=self.convert(v);misc=next(row['record']for row in r['records']if row['table_name']=='SpellMisc')
|
|
self.assertEqual(misc['Attributes'],[0x40000]+[0]*16)
|
|
self.assertEqual(r['spells'][0]['source_definition'],source)
|
|
self.assertFalse(r['gameplay_verified'])
|
|
self.assertEqual(source['effects'][0][1],138)
|
|
|
|
def test_real_source_set_haste_preserves_visual_duration_and_presentation(self):
|
|
from aura_visual_profile import new_link_candidate
|
|
from spell_family_compat import namespace
|
|
f=json.loads((ROOT/'tests/fixtures/no-sheath-haste-source.json').read_text())
|
|
dbc=SimpleNamespace(by_id={49367:f['disk_row']},string={int(k):v for k,v in f['strings'].items()}.__getitem__)
|
|
schema=codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions/SpellXSpellVisual.dbd','SpellXSpellVisual')
|
|
visual=new_link_candidate(f['server_row'],f['source_visual'],f['native_visual'],f['native_events'],
|
|
f['native_links'][0],schema,1500000,dict(schema_version=1,build=codec.BUILD,SpellXSpellVisual={}),
|
|
{r['ID']for r in f['native_links']})
|
|
family=namespace(Path('/home/praxis/Servers/tortoise-wow/src/game/Database/DBCEnums.h'),
|
|
ROOT.parent/'servers/trinity-forever/src/server/game/Miscellaneous/SharedDefines.h')
|
|
src=m.source_spell(dbc,f['server_row'],spell_layout(),family_namespace=family,
|
|
visual_link=visual,presentation_context=self.presentation())
|
|
self.assertEqual((src['entry'],src['durationIndex'],src['visuals']),(49367,32,[2759,0]))
|
|
self.assertEqual((src['attributes'],src['effects'][0][:3]),([0x40000,0,0,0,0],[6,138,9]))
|
|
with self.assertRaisesRegex(ValueError,'visual link'):
|
|
m.source_spell(dbc,f['server_row'],spell_layout(),family_namespace=family,presentation_context=self.presentation())
|
|
|
|
def test_presentation_context_does_not_admit_other_flags_or_mechanics(self):
|
|
for mode in ('missing-flag','extra-flag','different-word','wrong-proof','wrong-type','different-mechanic'):
|
|
v=self.fixture();source=v[0][0]
|
|
source['attributes']=[0x40000,0,0,0,0];source['presentation_context']=self.presentation()
|
|
if mode=='missing-flag':source['attributes'][0]=0
|
|
elif mode=='extra-flag':source['attributes'][0]|=16
|
|
elif mode=='different-word':source['attributes'][1]=0x40000
|
|
elif mode=='wrong-proof':source['presentation_context']['target_value']=1
|
|
elif mode=='wrong-type':source['presentation_context']['source_value']=262144.0
|
|
else:source['effects'][0][1]=13
|
|
with self.assertRaises(ValueError):self.convert(v)
|
|
|
|
def test_presentation_headers_must_match_pinned_definitions(self):
|
|
import tempfile
|
|
with tempfile.TemporaryDirectory()as temp:
|
|
path=Path(temp)/'SpellDefines.h';path.write_text('SPELL_ATTR_DONT_AFFECT_SHEATH_STATE = 0x00040000,')
|
|
with self.assertRaisesRegex(ValueError,'header changed'):
|
|
m.presentation_namespace(path,ROOT.parent/'servers/trinity-forever/src/server/game/Miscellaneous/SharedDefines.h')
|
|
|
|
def source(self):
|
|
f=json.loads((ROOT/'tests/fixtures/timed-buff-source.json').read_text());dbc=SimpleNamespace(by_id={53202:f['disk_row']},string={int(k):v for k,v in f['strings'].items()}.__getitem__);src=checked_constant_source(dbc,f['server_row'],spell_layout(),family_namespace=f['family_namespace'])
|
|
return f,dbc,src
|
|
def fixture(self):
|
|
# Deliberately synthetic neutral-visual source: never an import of53202.
|
|
f,dbc,source=self.source();source['entry']=600142;source['visuals']=[0,0];source['equippedItem']=[-1,0,0]
|
|
v=restore_tests.RestorationCompatibilityTest().new_fixture();v=list(v);v[0]=[source];v[5]['new_icon_ids']={'600142':136235};source['spellIconId']=1
|
|
v[1]['SpellDuration']=f['duration_rows'];v[5]['source_tables']['SpellDuration'].by_id[7]=[7,5000,0,5000]
|
|
return v
|
|
def convert(self,v):return m.new_component(*v[:5],**v[5])
|
|
def test_actual_source_is_blocked_instead_of_dropping_visual(self):
|
|
f,dbc,src=self.source();self.assertEqual(src['visuals'],[718,0]);self.assertEqual(src['equippedItem'],[-1,-1,0])
|
|
with self.assertRaisesRegex(ValueError,'visual link'):m.source_spell(dbc,f['server_row'],spell_layout(),family_namespace=f['family_namespace'])
|
|
def test_synthetic_fixed_buff_keeps_percent_duration_levels_and_family(self):
|
|
r=self.convert(self.fixture());rows={r['table_name']:r['record']for r in r['records']};self.assertEqual(len(rows),7)
|
|
self.assertEqual((rows['SpellEffect']['EffectAura'],rows['SpellEffect']['EffectBasePointsF']),(138,15))
|
|
self.assertEqual(rows['SpellMisc']['DurationIndex'],7);self.assertEqual(rows['SpellLevels']['BaseLevel'],60);self.assertEqual(rows['SpellClassOptions']['SpellClassSet'],4)
|
|
self.assertFalse(r['installable']);self.assertFalse(r['gameplay_verified'])
|
|
def test_nonfinite_scaled_missing_or_wrong_duration_rejects(self):
|
|
for mode in('infinite','scaled','missing','wrong'):
|
|
v=self.fixture()
|
|
if mode=='infinite':v[0][0]['durationIndex']=21
|
|
elif mode=='scaled':v[5]['source_tables']['SpellDuration'].by_id[7][2]=100
|
|
elif mode=='missing':v[1]['SpellDuration']=[]
|
|
else:v[1]['SpellDuration'][0]['Duration']=10000
|
|
with self.assertRaises(ValueError):self.convert(v)
|
|
def test_proc_target_cost_visual_and_unsupported_aura_reject(self):
|
|
for mode in('proc','target','cost','visual','aura','variance'):
|
|
v=self.fixture();s=v[0][0]
|
|
if mode=='proc':s['conditions']['procFlags']=16
|
|
elif mode=='target':s['effects'][0][8]=6
|
|
elif mode=='cost':s['power'][1]=1
|
|
elif mode=='visual':s['visuals'][0]=718
|
|
elif mode=='aura':s['effects'][0][1]=52
|
|
else:s['effects'][0][4]=10
|
|
with self.assertRaises(ValueError):self.convert(v)
|
|
def test_original_source_policy_not_broadened(self):
|
|
f,dbc,src=self.source()
|
|
f['server_row']['stanceBarOrder']=0;f['disk_row'][spell_layout()['StanceBarOrder']]=0
|
|
with self.assertRaisesRegex(ValueError,'stance-bar'):checked_constant_source(dbc,f['server_row'],spell_layout(),family_namespace=f['family_namespace'])
|
|
|
|
def actual_fixture(self):
|
|
import aura_visual_link_candidate_test as visual_fixture
|
|
from aura_visual_profile import new_link_candidate
|
|
inputs=visual_fixture.AuraVisualLinkCandidateTest().fixture();link=new_link_candidate(*inputs)
|
|
f,dbc,source=self.source();source=m.source_spell(dbc,f['server_row'],spell_layout(),family_namespace=f['family_namespace'],visual_link=link)
|
|
v=self.fixture();v[0]=[source];v[2]['SpellXSpellVisual']=inputs[5];o=v[5];path='interface/icons/spell_shadow_unholyfrenzy.blp';raw=b'BLP2'+bytes(20)
|
|
import hashlib
|
|
o.update(new_icon_ids={'53202':136224},target_icon_names={136224:[path]},icon_assets=[dict(path=path,bytes=len(raw),sha256=hashlib.sha256(raw).hexdigest(),magic_hex=raw[:4].hex())],read_icon=lambda p:raw,visual_links={53202:link})
|
|
o['source_tables']['SpellIcon']=SimpleNamespace(by_id={95:f['source_icon_row']},string=lambda index:f['source_icon_string'])
|
|
return v
|
|
def test_actual_source_preserves_visual_link_subclass_sentinel_and_ids(self):
|
|
v=self.actual_fixture();r=self.convert(v);rows={r['table_name']:r['record']for r in r['records']};self.assertEqual(len(rows),8)
|
|
self.assertEqual((rows['SpellXSpellVisual']['SpellID'],rows['SpellXSpellVisual']['SpellVisualID']),(53202,718))
|
|
self.assertEqual(rows['SpellEquippedItems']['EquippedItemSubclass'],-1)
|
|
self.assertEqual(rows['SpellMisc']['SpellIconFileDataID'],136224)
|
|
self.assertEqual(rows['SpellMisc']['DurationIndex'],7);self.assertEqual(rows['SpellEffect']['EffectBasePointsF'],15)
|
|
self.assertEqual(rows['SpellLevels']['SpellLevel'],60);self.assertFalse(r['installed']);self.assertFalse(r['gameplay_verified'])
|
|
def test_missing_link_identity_wire_or_conditions_reject(self):
|
|
for change in('missing','identity','wire','conditional','rowid'):
|
|
v=self.actual_fixture();o=v[5];link=o['visual_links'][53202];row=link['record']
|
|
if change=='missing':o['visual_links']={}
|
|
elif change=='identity':row['record']['SpellID']=3258
|
|
elif change=='wire':row['wire_hex']='00'
|
|
elif change=='conditional':row['record']['CasterUnitConditionID']=1
|
|
else:row['record']['ID']+=1
|
|
with self.assertRaises(ValueError):self.convert(v)
|
|
def test_boolean_or_nonfinite_normalized_effect_is_rejected(self):
|
|
for index,value in((2,True),(3,True),(5,False),(6,float('nan')),(11,float('inf'))):
|
|
v=self.fixture();v[0][0]['effects'][0][index]=value
|
|
with self.assertRaises(ValueError):self.convert(v)
|
|
|
|
def extra_source(self):
|
|
f=json.loads((ROOT/'tests/fixtures/extra-attack-physical-buff-source.json').read_text())
|
|
dbc=SimpleNamespace(by_id={49369:f['disk_row']},string={int(k):v for k,v in f['strings'].items()}.__getitem__)
|
|
src=checked_constant_source(dbc,f['server_row'],spell_layout(),family_namespace=f['family_namespace'],extra_damage_context=f['extra_damage_context'])
|
|
return f,dbc,src
|
|
|
|
def extra_fixture(self):
|
|
# Deliberately synthetic neutral visual/icon, not an install of49369.
|
|
f,dbc,src=self.extra_source();src.update(entry=600202,visuals=[0,0],spellIconId=1)
|
|
v=list(restore_tests.RestorationCompatibilityTest().new_fixture());v[0]=[src]
|
|
v[2]['SpellCategories']=codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions/SpellCategories.dbd','SpellCategories')
|
|
v[3]['SpellCategories']=1500000;v[1]['SpellCategories']=[]
|
|
v[1]['SpellDuration']=[dict(ID=31,Duration=8000,MaxDuration=8000,DurationPerResource=0)]
|
|
v[5]['source_tables']['SpellDuration']=SimpleNamespace(by_id={31:[31,8000,0,8000]})
|
|
v[5].update(new_icon_ids={'600202':136235},extra_damage=True)
|
|
return v
|
|
|
|
def test_actual_composite_capture_preserves_dispel_duration_both_effects_and_chain(self):
|
|
f,dbc,src=self.extra_source()
|
|
self.assertEqual(src['dispel_type'],1);self.assertEqual(src['durationIndex'],31)
|
|
self.assertEqual(src['effect_chain_amplitudes'],[1,0,0])
|
|
self.assertEqual([e[:3]for e in src['effects']],[[19,0,0],[6,13,11],[0,0,0]])
|
|
self.assertEqual(src['visuals'],[1508,0])
|
|
with self.assertRaisesRegex(ValueError,'visual link'):m.validate_source(src,extra_damage=True)
|
|
with self.assertRaisesRegex(ValueError,'dispel'):checked_constant_source(dbc,f['server_row'],spell_layout(),family_namespace=f['family_namespace'])
|
|
for mode in('dispel','chain'):
|
|
f,dbc,src=self.extra_source()
|
|
f['server_row']['dispel'if mode=='dispel'else'dmgMultiplier2']=0 if mode=='dispel'else 1
|
|
with self.assertRaises(ValueError):checked_constant_source(dbc,f['server_row'],spell_layout(),family_namespace=f['family_namespace'],extra_damage_context=f['extra_damage_context'])
|
|
|
|
def test_composite_preserves_distinct_extra_attack_and_timed_physical_buff(self):
|
|
v=self.extra_fixture();before=copy.deepcopy(v[:5]);r=self.convert(v);self.assertEqual(v[:5],before)
|
|
effects=[x['record']for x in r['records']if x['table_name']=='SpellEffect']
|
|
self.assertEqual([(x['Effect'],x['EffectAura'],x['EffectBasePointsF'],x['EffectMiscValue'],x['EffectChainAmplitude'])for x in effects],[(19,0,1,[0,0],1),(6,13,12,[1,0],0)])
|
|
rows={x['table_name']:x['record']for x in r['records']}
|
|
self.assertEqual(rows['SpellCategories']['DispelType'],1)
|
|
self.assertEqual(rows['SpellMisc']['DurationIndex'],31)
|
|
self.assertEqual(rows['SpellLevels']['BaseLevel'],50)
|
|
self.assertEqual(r['definition_policy'],m.EXTRA_DAMAGE_POLICY)
|
|
self.assertEqual(r['spells'][0]['source_definition'],v[0][0])
|
|
self.assertFalse(r['gameplay_verified']);self.assertFalse(r['installable'])
|
|
self.assertNotIn('SkillLineAbility',rows)
|
|
for row in r['records']:self.assertEqual(bytes.fromhex(row['wire_hex']),codec.encode(row['record'],v[2][row['table_name']]))
|
|
v[4].update(r['child_id_registry']);self.assertEqual(self.convert(v),r)
|
|
v=self.extra_fixture();s=copy.deepcopy(v[0][0]);s['entry']=600203;v[0].append(s);v[5]['new_icon_ids']['600203']=136235
|
|
r=self.convert(v);self.assertEqual(len([x for x in r['records']if x['table_name']=='SpellCategories']),2)
|
|
self.assertEqual({x['source_spell_id']for x in r['records']},{600202,600203})
|
|
|
|
def test_composite_scope_rejects_missing_role_wrong_mask_proc_cost_and_forged_proof(self):
|
|
for mode in('role','mask','proc','cost','dispel','proof','duration','coefficient','chain'):
|
|
v=self.extra_fixture();s=v[0][0]
|
|
if mode=='role':s['effects'][0]=[0]*11+[-1]
|
|
elif mode=='mask':s['effects'][1][7]=2
|
|
elif mode=='proc':s['conditions']['procFlags']=16
|
|
elif mode=='cost':s['power'][1]=1
|
|
elif mode=='dispel':s['dispel_type']=0
|
|
elif mode=='proof':s['extra_damage_context']['source_dispel']=True
|
|
elif mode=='duration':v[1]['SpellDuration'][0]['Duration']=12000
|
|
elif mode=='coefficient':s['effects'][1][11]=1
|
|
else:s['effect_chain_amplitudes'][0]=0
|
|
with self.assertRaises(ValueError,msg=mode):self.convert(v)
|
|
v=self.extra_fixture();v[5].pop('extra_damage')
|
|
with self.assertRaises(ValueError):self.convert(v)
|
|
if __name__=='__main__':unittest.main()
|