883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
199 lines
16 KiB
Python
199 lines
16 KiB
Python
"""Data-driven compound healing/resource correction; no game client or SQL."""
|
|
import copy,json,sys,unittest
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT/'ops'))
|
|
import spell_restore_compat as m
|
|
import spell_passive_compat as codec
|
|
from turtle_data import spell_layout
|
|
|
|
class RestorationCompatibilityTest(unittest.TestCase):
|
|
def test_shared_existing_range_review_preserves_zero_and_resource_ranges(self):
|
|
for effect in (10,30):
|
|
row=dict(Effect=effect,EffectAura=0,EffectBasePointsF=100,Variance=.4);before=copy.deepcopy(row)
|
|
self.assertEqual(m.existing_restoration_range(79,41,row)['source_min'],80)
|
|
self.assertEqual(m.existing_restoration_range(79,41,row)['source_max'],120);self.assertEqual(row,before)
|
|
zero=dict(row,EffectBasePointsF=.5,Variance=2)
|
|
self.assertEqual(m.existing_restoration_range(-1,2,zero)['source_min'],0)
|
|
for patch in (dict(Variance=1),dict(EffectBasePointsF=float('nan')),dict(Variance=True),dict(Effect=2),dict(EffectAura=1)):
|
|
with self.assertRaisesRegex(ValueError,'range differs'):m.existing_restoration_range(79,41,dict(row,**patch))
|
|
def fixture(self):
|
|
r=json.loads((ROOT/'tests/fixtures/restoration-source.json').read_text());strings={int(k):v for k,v in r['strings'].items()}
|
|
dbc=SimpleNamespace(by_id={int(k):v for k,v in r['disk_rows'].items()},string=strings.__getitem__)
|
|
source=[m.source_spell(dbc,row,spell_layout())for row in r['server_rows']]
|
|
dbd=ROOT.parent/'tools/WoWDBDefs/definitions';schemas={name:codec.fields(dbd/(name+'.dbd'),name)for name in('Spell','SpellLevels','SpellEffect')}
|
|
maxima={name:1400000 for name in schemas}
|
|
reg=dict(schema_version=1,build=codec.BUILD,SpellEffect={})
|
|
return r,dbc,source,r['native'],schemas,maxima,reg
|
|
def run_component(self,value):
|
|
_,_,source,native,schemas,maxima,registry=value
|
|
return m.component(source,native,schemas,maxima,registry)
|
|
def test_actual_missing_energy_slot_preserves_heal_and_wire_identity(self):
|
|
value=self.fixture();before=copy.deepcopy(value[2:]);r=self.run_component(value)
|
|
self.assertEqual(value[2:],before)
|
|
self.assertEqual([(v['table_name'],v['source_spell_id'])for v in r['records']],[('Spell',27418),('SpellLevels',27418),('SpellEffect',27418)])
|
|
row=next(v for v in r['records']if v['table_name']=='SpellEffect');e=row['record']
|
|
self.assertEqual((row['id'],e['SpellID'],e['EffectIndex'],e['Effect'],e['EffectAura']),(1400001,27418,1,30,0))
|
|
self.assertEqual(e['EffectBasePointsF'],100);self.assertEqual(e['EffectMiscValue'],[1,0]);self.assertEqual(e['Variance'],0)
|
|
# The native variable heal is not cloned with its variance into energy,
|
|
# and it is not rewritten while adding the missing second effect.
|
|
self.assertFalse(any(v['id']==703985 for v in r['records']))
|
|
self.assertEqual(next(v for v in value[3]['SpellEffect']if v['ID']==703985)['Variance'],.4)
|
|
self.assertEqual(next(v for v in r['records']if v['table_name']=='SpellLevels')['record']['BaseLevel'],50)
|
|
text=next(v for v in r['records']if v['table_name']=='Spell')['record']['Description_lang'];self.assertIn('$/10;s2',text)
|
|
self.assertFalse(r['installable']);self.assertFalse(r['gameplay_verified'])
|
|
self.assertTrue(all(not s['known_spells_modified']for s in r['spells']))
|
|
def test_source_correct_second_spell_is_a_noop_without_racial_binding(self):
|
|
value=self.fixture();value[2][:]=[s for s in value[2]if s['entry']==29478]
|
|
r=self.run_component(value);self.assertEqual(r['records'],[]);self.assertEqual(r['child_id_registry']['SpellEffect'],{})
|
|
def warrior_existing_fixture(self):
|
|
value=self.fixture();source=next(s for s in value[2]if s['entry']==27418)
|
|
source['class_family']=copy.deepcopy(self.new_fixture()[0][0]['class_family'])
|
|
value[3]['SpellClassOptions'][:]=[r for r in value[3]['SpellClassOptions']if r['SpellID']!=27418]
|
|
value[3]['SpellClassOptions'].append(dict(copy.deepcopy(codec.CHILD_NEUTRAL['SpellClassOptions']),ID=991,SpellID=27418,SpellClassSet=4))
|
|
return value
|
|
def test_existing_warrior_zero_masks_use_the_same_reviewed_family_as_new_definitions(self):
|
|
value=self.warrior_existing_fixture();before=copy.deepcopy(value[2:]);r=self.run_component(value)
|
|
self.assertEqual(value[2:],before)
|
|
self.assertEqual(len(r['records']),3)
|
|
self.assertFalse(any(row['table_name']=='SpellClassOptions'for row in r['records']))
|
|
def test_existing_warrior_family_requires_exact_positive_native_binding(self):
|
|
for mode in ('missing','duplicate','wrong-family','native-mask','source-mask','unknown-family'):
|
|
value=self.warrior_existing_fixture();row=next(r for r in value[3]['SpellClassOptions']if r['SpellID']==27418)
|
|
if mode=='missing':value[3]['SpellClassOptions'].remove(row)
|
|
elif mode=='duplicate':value[3]['SpellClassOptions'].append(dict(row,ID=992))
|
|
elif mode=='wrong-family':row['SpellClassSet']=0
|
|
elif mode=='native-mask':row['SpellClassMask'][0]=1
|
|
elif mode=='source-mask':next(s for s in value[2]if s['entry']==27418)['class_family']['source_mask'][0]=1
|
|
else:next(s for s in value[2]if s['entry']==27418)['class_family']['name']='SPELLFAMILY_MAGE'
|
|
with self.assertRaises(ValueError,msg=mode):self.run_component(value)
|
|
def test_stable_registry_reversed_sources_and_no_input_mutation(self):
|
|
value=self.fixture();r=self.run_component(value)
|
|
value[2].reverse();value[-1].update(r['child_id_registry']);self.assertEqual(self.run_component(value),r)
|
|
self.assertEqual(r['child_id_registry']['SpellEffect'],{'27418:1':1400001})
|
|
def test_other_resource_and_constant_heal_slots_share_the_adapter(self):
|
|
for effect_type,resource,amount in((30,0,50),(30,3,25),(10,0,125)):
|
|
value=self.fixture();s=next(s for s in value[2]if s['entry']==27418);e=s['effects'][1];e[0]=effect_type;e[7]=resource;e[2]=amount-1
|
|
row=next(r for r in self.run_component(value)['records']if r['table_name']=='SpellEffect')['record']
|
|
self.assertEqual((row['Effect'],row['EffectMiscValue'],row['EffectBasePointsF']),(effect_type,[resource,0],amount))
|
|
def test_source_spell_identity_is_not_an_allowlist(self):
|
|
value=self.fixture();new_id=600123
|
|
next(s for s in value[2]if s['entry']==27418)['entry']=new_id
|
|
for table,rows in value[3].items():
|
|
for row in rows:
|
|
if table in('SpellName','Spell')and row['ID']==27418:row['ID']=new_id
|
|
elif row.get('SpellID')==27418:row['SpellID']=new_id
|
|
result=self.run_component(value)
|
|
self.assertTrue(all(row['source_spell_id']==new_id for row in result['records']))
|
|
effect=next(row['record']for row in result['records']if row['table_name']=='SpellEffect')
|
|
self.assertEqual(effect['SpellID'],new_id)
|
|
self.assertEqual(result['child_id_registry']['SpellEffect'],{'600123:1':1400001})
|
|
def test_normalized_mutations_cannot_bypass_family_validation(self):
|
|
for change in('proc','cost','gcd','resource','trigger','level','bool','empty','attribute'):
|
|
value=self.fixture();s=value[2][0]
|
|
if change=='proc':s['conditions']['procFlags']=1
|
|
if change=='cost':s['power'][1]=1
|
|
if change=='gcd':s['timing']['startRecoveryTime']=1500
|
|
if change=='resource':s['effects'][1][7]=4 # Legacy happiness is NOT modern combo points.
|
|
if change=='trigger':s['effects'][1][10]=123
|
|
if change=='level':s['levels']['baseLevel']=65536
|
|
if change=='bool':s['effects'][1][2]=True
|
|
if change=='empty':s['effects'][2][7]=1
|
|
if change=='attribute':s['attributes'][0]=80
|
|
with self.assertRaises(ValueError,msg=change):self.run_component(value)
|
|
def test_server_and_captured_definition_must_agree(self):
|
|
for change in('text','effect','condition','extra-server','extra-disk'):
|
|
raw,dbc,_,_,_,_,_=self.fixture();server=next(r for r in raw['server_rows']if r['entry']==27418)
|
|
if change=='text':server['description']='Fabricated restoration'
|
|
if change=='effect':server['effectBasePoints2']=199
|
|
if change=='condition':server['procFlags']=1
|
|
if change=='extra-server':server['spellFamilyName']=4
|
|
if change=='extra-disk':dbc.by_id[27418][spell_layout()['EffectRadiusIndex']]=2
|
|
with self.assertRaises(ValueError,msg=change):m.source_spell(dbc,server,spell_layout())
|
|
def test_native_conditions_ambiguity_and_bad_heal_range_reject(self):
|
|
for change in('missing-export','proc','range','wrong-name','extra-effect','duplicate-effect','cooldown','levels'):
|
|
value=self.fixture();n=value[3]
|
|
if change=='missing-export':del n['SpellPower']
|
|
if change=='proc':next(r for r in n['SpellAuraOptions']if r['SpellID']==27418)['ProcTypeMask'][0]=1
|
|
if change=='range':next(r for r in n['SpellEffect']if r['SpellID']==27418)['Variance']=1
|
|
if change=='wrong-name':next(r for r in n['SpellName']if r['ID']==27418)['Name_lang']='Unrelated spell'
|
|
if change=='extra-effect':n['SpellEffect'].append(dict(next(r for r in n['SpellEffect']if r['SpellID']==27418),ID=900000,EffectIndex=2))
|
|
if change=='duplicate-effect':n['SpellEffect'].append(copy.deepcopy(n['SpellEffect'][0]))
|
|
if change=='cooldown':n['SpellCooldowns']=[dict(codec.CHILD_NEUTRAL['SpellCooldowns'],ID=900000,SpellID=27418,RecoveryTime=1000)]
|
|
if change=='levels':next(r for r in n['SpellLevels']if r['SpellID']==27418)['MaxPassiveAuraLevel']=1
|
|
with self.assertRaises(ValueError,msg=change):self.run_component(value)
|
|
def test_new_variable_effects_and_registry_collisions_reject(self):
|
|
value=self.fixture();s=next(s for s in value[2]if s['entry']==27418);s['effects'][1][4]=20
|
|
with self.assertRaisesRegex(ValueError,'variable restore'):self.run_component(value)
|
|
value=self.fixture();value[-1]['SpellEffect']['27418:1']=700000
|
|
with self.assertRaises(ValueError):self.run_component(value)
|
|
|
|
def new_fixture(self):
|
|
from spell_family_compat import namespace
|
|
f=json.loads((ROOT/'tests/fixtures/new-restoration-source.json').read_text())
|
|
def table(rows,strings):
|
|
texts={int(k):v for k,v in strings.items()}
|
|
return SimpleNamespace(by_id={int(k):v for k,v in rows.items()},string=texts.__getitem__)
|
|
dbc=table(f['disk_rows'],f['strings']);proof=namespace(ROOT.parent.parent.parent/'Servers/tortoise-wow/src/game/Database/DBCEnums.h',ROOT.parent/'servers/trinity-forever/src/server/game/Miscellaneous/SharedDefines.h')
|
|
src=[m.source_spell(dbc,r,spell_layout(),family_namespace=proof)for r in f['server_rows']]
|
|
schemas={t:codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions'/(t+'.dbd'),t)for t in(codec.TABLES|{t:codec.SUPPLEMENTAL_TABLES[t]for t in('SpellClassOptions','SpellLevels')})}
|
|
raw=b'BLP2'+bytes(20)
|
|
import hashlib
|
|
options=dict(source_tables={t:table(v['rows'],v['strings'])for t,v in f['source_tables'].items()},target_icon_names={136235:['interface/icons/temp.blp']},new_icon_ids={'51898':136235},icon_assets=[dict(path='interface/icons/temp.blp',bytes=len(raw),sha256=hashlib.sha256(raw).hexdigest(),magic_hex=raw[:4].hex())],read_icon=lambda path:raw)
|
|
return src,f['native'],schemas,{t:1500000 for t in schemas},dict(schema_version=1,build=codec.BUILD,SpellEffect={}),options
|
|
def new_component(self,v):return m.new_component(*v[:5],**v[5])
|
|
def test_real_missing_restore_preserves_level_family_resource_and_instant_type(self):
|
|
v=self.new_fixture();before=copy.deepcopy(v[:5]);r=self.new_component(v);self.assertEqual(v[:5],before);self.assertEqual(len(r['records']),7)
|
|
rows={row['table_name']:row['record']for row in r['records']};self.assertNotIn('SkillLineAbility',rows)
|
|
self.assertEqual((rows['SpellLevels']['SpellLevel'],rows['SpellLevels']['BaseLevel'],rows['SpellClassOptions']['SpellClassSet']),(60,60,4))
|
|
self.assertEqual(rows['SpellClassOptions']['SpellClassMask'],[0]*4)
|
|
self.assertEqual((rows['SpellMisc']['DurationIndex'],rows['SpellMisc']['CastingTimeIndex'],rows['SpellMisc']['Attributes']),(0,1,[0]*17))
|
|
self.assertEqual((rows['SpellEffect']['Effect'],rows['SpellEffect']['EffectAura'],rows['SpellEffect']['EffectBasePointsF'],rows['SpellEffect']['EffectMiscValue']),(30,0,150,[1,0]))
|
|
self.assertEqual(rows['Spell']['Description_lang'],'Generates $/10;s1 rage.')
|
|
self.assertTrue(all(row['source_spell_id']==51898 for row in r['records']));self.assertFalse(r['installable']);self.assertFalse(r['gameplay_verified'])
|
|
self.assertFalse(r['spells'][0]['known_spells_modified'])
|
|
for row in r['records']:self.assertEqual(bytes.fromhex(row['wire_hex']),codec.encode(row['record'],v[2][row['table_name']]))
|
|
def test_new_constant_heal_mana_and_energy_use_same_builder(self):
|
|
for kind,resource,base,school in((10,0,99,1),(30,0,49,0),(30,3,24,6)):
|
|
v=self.new_fixture();s=v[0][0];s['school']=school;s['effects'][0][0]=kind;s['effects'][0][7]=resource;s['effects'][0][2]=base
|
|
rows={row['table_name']:row['record']for row in self.new_component(v)['records']}
|
|
self.assertEqual(rows['SpellMisc']['SchoolMask'],1<<school);self.assertEqual((rows['SpellEffect']['Effect'],rows['SpellEffect']['EffectBasePointsF'],rows['SpellEffect']['EffectMiscValue']),(kind,base+1,[resource,0]))
|
|
def test_new_restore_identity_registry_and_pending_allocation_bound(self):
|
|
v=self.new_fixture();v[3]['SpellEffect']=1600000;v[3]['SpellMisc']=1600000
|
|
r=self.new_component(v);self.assertEqual(r['child_id_registry']['SpellEffect'],{'51898:0':1600001});self.assertEqual(r['child_id_registry']['SpellMisc'],{'51898':1600001})
|
|
v[4].update(r['child_id_registry']);self.assertEqual(self.new_component(v),r)
|
|
v=self.new_fixture();v[0][0]['entry']=600128;v[5]['new_icon_ids']={'600128':136235}
|
|
r=self.new_component(v);self.assertTrue(all(row['source_spell_id']==600128 for row in r['records']))
|
|
def test_new_variable_cost_proc_visual_and_family_mutations_reject(self):
|
|
for mutation in('variable','cost','proc','visual','family-mask','missing-family','null-family','gcd','resource','level','trigger'):
|
|
v=self.new_fixture();s=v[0][0]
|
|
if mutation=='variable':s['effects'][0][0]=10;s['effects'][0][7]=0;s['effects'][0][4]=45
|
|
if mutation=='cost':s['power'][1]=1
|
|
if mutation=='proc':s['conditions']['procFlags']=1
|
|
if mutation=='visual':s['visuals'][0]=1714
|
|
if mutation=='family-mask':s['class_family']['target_mask'][0]=1
|
|
if mutation=='missing-family':del s['class_family']
|
|
if mutation=='null-family':s['class_family']=None
|
|
if mutation=='gcd':s['timing']['startRecoveryCategory']=133
|
|
if mutation=='resource':s['effects'][0][7]=4
|
|
if mutation=='level':s['levels']['baseLevel']=65536
|
|
if mutation=='trigger':s['effects'][0][10]=123
|
|
with self.assertRaises(ValueError,msg=mutation):self.new_component(v)
|
|
def test_new_restore_reference_icon_and_duplicate_failures(self):
|
|
for mutation in('positive','missing-table','range','icon','duplicate','registry'):
|
|
v=self.new_fixture()
|
|
if mutation=='positive':v[1]['SpellName'].append(dict(ID=51898,Name_lang='Existing native parent'))
|
|
if mutation=='missing-table':del v[1]['SpellPower']
|
|
if mutation=='range':v[1]['SpellRange'][0]['RangeMax']=[30,30]
|
|
if mutation=='icon':v[5]['read_icon']=lambda path:b'corrupt'
|
|
if mutation=='duplicate':v[0].append(copy.deepcopy(v[0][0]))
|
|
if mutation=='registry':v[4]['SkillLineAbility']={'51898':1500001}
|
|
with self.assertRaises(ValueError,msg=mutation):self.new_component(v)
|
|
def test_shared_builder_rejects_missing_or_extra_effect_slots(self):
|
|
from spell_definition_common import new_definition_records,NEW_DEFINITION_CHILD_TABLES
|
|
v=self.new_fixture();occupied={t:set()for t in NEW_DEFINITION_CHILD_TABLES}
|
|
for effects in({}, {1:dict(codec.NEW_EFFECT_NEUTRAL)}):
|
|
with self.assertRaises(ValueError):new_definition_records(v[0][0],effects,136235,v[2],v[3],v[4],occupied,allocation_prefix='fixture')
|
|
|
|
if __name__=='__main__':unittest.main()
|