Files
WoW-Hybrid-gateway/tests/spell_item_static_compat_test.py

346 lines
27 KiB
Python

"""Public real-source fixtures for item/set stat conversion; no client/server."""
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_item_static_compat as m
import spell_passive_compat as codec
from turtle_data import spell_layout
class ItemStatCompatibilityTest(unittest.TestCase):
def fixture(self):
f=json.loads((ROOT/'tests/fixtures/item-stat-source.json').read_text());strings={int(k):v for k,v in f['strings'].items()}
dbc=SimpleNamespace(by_id={int(k):v for k,v in f['disk_rows'].items()},string=strings.__getitem__)
src=[m.source_spell(dbc,r,spell_layout())for r in f['server_rows']]
dbd=ROOT.parent/'tools/WoWDBDefs/definitions';schemas={t:codec.fields(dbd/(t+'.dbd'),t)for t in('Spell','SpellEffect','SpellLevels')}
return f,dbc,src,f['native'],schemas,dict(Spell=1500000,SpellEffect=1500000,SpellLevels=1500000),dict(schema_version=1,build=codec.BUILD,SpellEffect={})
def component(self,v):return m.component(*v[2:])
def test_existing_real_armor_resistance_ap_and_block_are_noops(self):
v=self.fixture();before=copy.deepcopy(v[2:]);r=self.component(v)
self.assertEqual(v[2:],before);self.assertEqual(r['records'],[])
self.assertEqual([s['spell_id']for s in r['spells']],[13675,14049,14803,18679,23562,29092,30770])
self.assertTrue(all(not s['known_spells_modified']for s in r['spells']))
self.assertFalse(r['installable']);self.assertFalse(r['gameplay_verified'])
def test_batch_source_classification_keeps_unsupported_mechanics_explicit(self):
f,dbc,*_=self.fixture();raws=copy.deepcopy(f['server_rows']);before=copy.deepcopy(raws)
out=m.classify_sources(dbc,raws,spell_layout())
self.assertEqual(out['source_policies_validated'],len(raws));self.assertEqual(raws,before)
self.assertFalse(out['native_context_reviewed']);self.assertFalse(out['known_spells_modified'])
self.assertEqual(out,m.classify_sources(dbc,list(reversed(raws)),spell_layout()))
# A changed server effect cannot be hidden by trying another policy.
raws[0]['effectBasePoints1']+=1
blocked=m.classify_sources(dbc,raws,spell_layout())
row=next(r for r in blocked['spells']if r['spell_id']==raws[0]['entry'])
self.assertNotIn('validated_source',row)
expected={'flat-item-stat','skill-bonus','school-damage','spell-bonus','mana-regeneration',
'weapon-crit','weapon-hit','parry','dodge','swim-speed','spell-crit','spell-hit','all-crit','casting-mana-regen'}
self.assertEqual({failure['policy'] for failure in row['blocked_policies']},expected)
self.assertEqual(len(row['blocked_policies']),len(expected))
self.assertTrue(all(failure['reason'] for failure in row['blocked_policies']))
with self.assertRaisesRegex(ValueError,'Duplicate'):m.classify_sources(dbc,raws+raws,spell_layout())
def test_source_block_value_is_274_never_native_talent_swap_158(self):
v=self.fixture();row=next(r for r in self.component(v)['spells']if r['spell_id']==23562)
self.assertEqual(row['effects'],[dict(index=0,source_aura=158,target_aura=274,amount=30)])
next(e for e in v[3]['SpellEffect']if e['SpellID']==23562)['EffectAura']=158
with self.assertRaisesRegex(ValueError,'semantics'):self.component(v)
def test_modified_native_amounts_and_text_are_corrected_in_bulk(self):
v=self.fixture()
for row in v[3]['SpellEffect']:row['EffectBasePointsF']=0
for row in v[3]['Spell']:row['Description_lang']='Old destination description'
r=self.component(v);effects=[r for r in r['records']if r['table_name']=='SpellEffect'];texts=[r for r in r['records']if r['table_name']=='Spell']
self.assertEqual(len(effects),9);self.assertEqual(len(texts),7)
self.assertEqual({r['record']['EffectBasePointsF']for r in effects},{2,8,30,40,200})
self.assertTrue(all(r['baseline_record_sha256']and r['changed_fields']==['EffectBasePointsF']for r in effects))
for row in r['records']:self.assertEqual(bytes.fromhex(row['wire_hex']),codec.encode(row['record'],v[4][row['table_name']]))
def test_flat_permanent_duration_requires_explicit_exact_timing_review(self):
v=self.fixture();misc=next(r for r in v[3]['SpellMisc']if r['SpellID']==14803);misc['DurationIndex']=0
v[4]['SpellMisc']=codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions/SpellMisc.dbd','SpellMisc')
v[5]['SpellMisc']=max(r['ID']for r in v[3]['SpellMisc'])
before=copy.deepcopy(v[2:])
with self.assertRaisesRegex(ValueError,'DurationIndex'):self.component(v)
proof=dict(source_duration_id=21,target_duration_id=21,duration_ms=-1,max_duration_ms=-1,
source_duration_per_level=0,target_duration_per_resource=0,permanent=True)
result=m.component(*v[2:],duration_reference=proof)
self.assertEqual(v[2:],before);self.assertEqual(len(result['records']),1)
row=result['records'][0];self.assertEqual(row['table_name'],'SpellMisc')
self.assertEqual(row['source_spell_id'],14803);self.assertEqual(row['record']['DurationIndex'],21)
self.assertEqual(row['changed_fields'],['DurationIndex'])
for change in(dict(duration_ms=0),dict(permanent=1),dict(target_duration_id=1)):
with self.assertRaisesRegex(ValueError,'duration'):m.component(*v[2:],duration_reference=dict(proof,**change))
def test_missing_second_ap_slot_uses_shared_allocator_after_staged_max(self):
v=self.fixture();v[3]['SpellEffect'][:]=[r for r in v[3]['SpellEffect']if not(r['SpellID']==14049 and r['EffectIndex']==1)]
r=self.component(v);self.assertEqual(len(r['records']),1);row=r['records'][0]
self.assertEqual((row['id'],row['source_spell_id'],row['record']['EffectAura'],row['record']['EffectBasePointsF']),(1500001,14049,124,40))
self.assertIsNone(row['baseline_record_sha256']);self.assertEqual(r['child_id_registry']['SpellEffect'],{'14049:1':1500001})
v[-1].update(r['child_id_registry']);v[2].reverse();self.assertEqual(self.component(v),r)
def test_no_item_or_spell_id_allowlist(self):
v=self.fixture();s=next(s for s in v[2]if s['entry']==23562);s['entry']=600124;v[2][:]=[s]
for table,rows in v[3].items():
for row in rows:
if table in('Spell','SpellName')and row['ID']==23562:row['ID']=600124
elif row.get('SpellID')==23562:row['SpellID']=600124
r=self.component(v);self.assertEqual(r['spells'][0]['spell_id'],600124);self.assertEqual(r['records'],[])
def test_source_capture_drift_or_unreviewed_source_metadata_rejected(self):
for key,value in(('effectBasePoints1',999),('spellFamilyName',4),('procFlags',1),('spellLevel',1),('speed',1),('spellIconId',123),('effectRadiusIndex1',1)):
v=self.fixture();raw=v[0]['server_rows'][0];raw[key]=value
with self.assertRaises(ValueError,msg=key):m.source_spell(v[1],raw,spell_layout())
v=self.fixture();v[1].by_id[13675][spell_layout()['EffectChainAmplitude']]=0
with self.assertRaises(ValueError):m.source_spell(v[1],v[0]['server_rows'][0],spell_layout())
def test_normalized_conditions_scaling_and_unsupported_mechanics_rejected(self):
for mutation in('proc','stance','cost','mask','type','scale','target','bool','level','tooltip','empty','timing','attributes'):
v=self.fixture();s=v[2][0]
if mutation=='proc':s['conditions']['procFlags']=1
if mutation=='stance':s['conditions']['stances']=1
if mutation=='cost':s['power'][1]=1
if mutation=='mask':s['effects'][0][7]=1
if mutation=='type':s['effects'][0][1]=98
if mutation=='scale':s['effects'][0][6]=1
if mutation=='target':s['effects'][0][8]=6
if mutation=='bool':s['effects'][0][2]=True
if mutation=='level':s['levels']['baseLevel']=1
if mutation=='tooltip':s['description']='$s3'
if mutation=='empty':s['effects'][2][7]=1
if mutation=='timing':s['timing']['startRecoveryCategory']=133
if mutation=='attributes':s['attributes'][0]=80
with self.assertRaises(ValueError,msg=mutation):self.component(v)
def test_incomplete_ambiguous_or_conflicting_native_context_rejected(self):
for mutation in('missing-table','name','duplicate','radius','visual','attribute','extra','child','icon'):
v=self.fixture();n=v[3]
if mutation=='missing-table':del n['SpellPower']
if mutation=='name':n['SpellName'][0]['Name_lang']='Unrelated spell'
if mutation=='duplicate':n['SpellEffect'].append(copy.deepcopy(n['SpellEffect'][0]))
if mutation=='radius':n['SpellEffect'][0]['EffectRadiusIndex'][0]=1
if mutation=='visual':n['SpellMisc'][0]['SpellVisualScript']=1
if mutation=='attribute':n['SpellMisc'][0]['Attributes'][15]|=1
if mutation=='extra':n['SpellEffect'][0]['EffectIndex']=2
if mutation=='child':n['SpellPower'].append(dict(ID=123,SpellID=13675))
if mutation=='icon':n['SpellMisc'][0]['SpellIconFileDataID']=0
with self.assertRaises(ValueError,msg=mutation):self.component(v)
class ItemSchoolDamageCompatibilityTest(unittest.TestCase):
def fixture(self):
f=json.loads((ROOT/'tests/fixtures/item-school-damage-source.json').read_text())
dbc=SimpleNamespace(by_id={int(k):v for k,v in f['disk_rows'].items()},string={int(k):v for k,v in f['strings'].items()}.__getitem__)
sources=[m.source_spell(dbc,r,spell_layout(),school_damage=True)for r in f['server_rows']]
schemas={t:codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions'/(t+'.dbd'),t)for t in('SpellName','Spell','SpellMisc','SpellEffect','SpellLevels')}
return sources,f['native'],schemas,{t:1500000 for t in schemas},dict(schema_version=1,build=codec.BUILD,SpellEffect={})
def test_source_school_index_and_effect_school_mask_stay_distinct(self):
v=self.fixture();before=copy.deepcopy(v);result=m.component(*v,school_damage=True)
self.assertEqual(v,before);self.assertEqual({r['table_name']for r in result['records']},{'Spell'})
self.assertTrue(all('$s'not in r['record']['Description_lang']and '36'in r['record']['Description_lang']for r in result['records']))
self.assertEqual(result['definition_policy'],m.SCHOOL_DAMAGE_POLICY)
self.assertEqual({r['effects'][0]['amount']for r in result['spells']},{36})
self.assertEqual([s['school']for s in v[0]],[0,4])
self.assertEqual([s['effects'][0][7]for s in v[0]],[4,16])
self.assertFalse(result['gameplay_verified']);self.assertFalse(result['engine_accepted'])
with self.assertRaises(ValueError):m.component(*v)
def test_changed_source_amounts_correct_native_values_without_changing_masks(self):
v=self.fixture()
for row in v[1]['SpellEffect']:row['EffectBasePointsF']=9
result=m.component(*v,school_damage=True)
self.assertEqual(len(result['records']),4)
for row in result['records']:
if row['table_name']=='SpellEffect':
self.assertEqual(row['changed_fields'],['EffectBasePointsF'])
self.assertEqual(row['record']['EffectBasePointsF'],36)
else:self.assertIn('36',row['record']['Description_lang'])
self.assertEqual(bytes.fromhex(row['wire_hex']),codec.encode(row['record'],v[2][row['table_name']]))
def test_repeated_static_review_preserves_literal_text_and_is_idempotent(self):
v=self.fixture();first=m.component(*v,school_damage=True)
for row in first['records']:
old=next(r for r in v[1][row['table_name']]if r['ID']==row['id']);old.update(row['record'])
self.assertFalse(m.component(*v,school_damage=True)['records'])
def test_unreviewed_scaling_targeting_and_mask_contexts_reject(self):
for mutation in('school','mask','target','scale','rating','timing','flags','percent','typed'):
v=self.fixture();src=v[0][0]
if mutation=='school':src['school']=7
elif mutation=='mask':src['effects'][0][7]=0
elif mutation=='target':src['effects'][0][8]=6
elif mutation=='scale':src['effects'][0][6]=0.5
elif mutation=='rating':src['effects'][0][1]=189
elif mutation=='timing':src['timing']['recoveryTime']=1000
elif mutation=='flags':v[1]['SpellMisc'][0]['Attributes'][15]|=1
elif mutation=='percent':src['effects'][0][1]=79
else:src['effects'][0][7]=True
with self.assertRaises(ValueError,msg=mutation):m.component(*v,school_damage=True)
with self.assertRaises(ValueError):m.component(*self.fixture(),school_damage=True,percent_stat='weapon-crit')
def test_other_source_ids_work_without_item_or_spell_allowlist(self):
v=self.fixture();v[0][:]=v[0][:1];ident=v[0][0]['entry'];v[0][0]['entry']=600125
for table,rows in v[1].items():
rows[:]=[r for r in rows if r.get('SpellID',r.get('ID'))==ident]
for row in rows:
if table in('Spell','SpellName'):row['ID']=600125
else:row['SpellID']=600125
self.assertEqual(m.component(*v,school_damage=True)['spells'][0]['spell_id'],600125)
class ItemCasterBonusCompatibilityTest(unittest.TestCase):
def fixture(self):
f=json.loads((ROOT/'tests/fixtures/item-caster-bonus-source.json').read_text())
dbc=SimpleNamespace(by_id={int(k):v for k,v in f['disk_rows'].items()},string={int(k):v for k,v in f['strings'].items()}.__getitem__)
schemas={t:codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions'/(t+'.dbd'),t)for t in('SpellName','Spell','SpellMisc','SpellEffect','SpellLevels')}
return f,dbc,schemas
def source(self,ident,**kwargs):
f,dbc,schemas=self.fixture();raw=next(r for r in f['server_rows']if r['entry']==ident)
return m.source_spell(dbc,raw,spell_layout(),**kwargs),f,schemas
def convert(self,ident,**kwargs):
src,f,schemas=self.source(ident,**kwargs)
result=m.component([src],f['native'],schemas,{t:1500000 for t in schemas},dict(schema_version=1,build=codec.BUILD,SpellEffect={}),duration_reference=f['duration_reference'],**kwargs)
for row in result['records']:self.assertEqual(bytes.fromhex(row['wire_hex']),codec.encode(row['record'],schemas[row['table_name']]))
return src,result
def test_real_healing_retains_school_mask_and_mixed_damage_slots(self):
for ident,auras,amounts in ((7676,[135],[4]),(28152,[135,13],[300,150])):
src,result=self.convert(ident,spell_bonus=True)
self.assertEqual(result['definition_policy'],m.SPELL_BONUS_POLICY)
self.assertEqual([e['source_aura']for e in result['spells'][0]['effects']],auras)
self.assertEqual([e['target_aura']for e in result['spells'][0]['effects']],auras)
self.assertEqual([e['amount']for e in result['spells'][0]['effects']],amounts)
self.assertTrue(all(e[7]==126 for e in src['effects']if e[0]))
self.assertFalse(result['gameplay_verified'])
def test_real_spell_hit_and_crit_preserve_percentages_not_ratings(self):
for ident,policy,aura,amount in ((23727,'spell-hit',55,1),(23434,'spell-crit',57,50)):
_,result=self.convert(ident,percent_stat=policy)
self.assertEqual(result['spells'][0]['effects'],[dict(index=0,source_aura=aura,target_aura=aura,amount=amount)])
def test_real_combined_crit_source_requires_positive_native_parent(self):
src,f,schemas=self.source(41114,percent_stat='all-crit')
self.assertEqual([src['effects'][i][1]for i in m.validate_source(src,percent_stat='all-crit')],[52,57])
with self.assertRaisesRegex(ValueError,'positive item-stat name'):
m.component([src],f['native'],schemas,{t:1500000 for t in schemas},dict(schema_version=1,build=codec.BUILD,SpellEffect={}),percent_stat='all-crit',duration_reference=f['duration_reference'])
def test_source_school_crit71_is_not_native_teleport_return71(self):
f,dbc,_=self.fixture();raw=next(r for r in f['server_rows']if r['entry']==45427)
for policy in ('spell-crit','all-crit'):
with self.assertRaises(ValueError):m.source_spell(dbc,raw,spell_layout(),percent_stat=policy)
def test_healing_rejects_changed_masks_scaling_conditions_and_damage_only(self):
for change in ('mask','native-mask','aura','duration','proc','scale','no-healing'):
src,f,schemas=self.source(7676,spell_bonus=True)
if change=='mask':src['effects'][0][7]=0
elif change=='native-mask':next(r for r in f['native']['SpellEffect']if r['SpellID']==7676)['EffectMiscValue']=[1,0]
elif change=='aura':src['effects'][0][1]=118
elif change=='duration':src['durationIndex']=1
elif change=='proc':src['conditions']['procFlags']=1
elif change=='scale':src['effects'][0][6]=1
else:src['effects'][0][1]=13
with self.assertRaises(ValueError,msg=change):m.component([src],f['native'],schemas,{t:1500000 for t in schemas},dict(schema_version=1,build=codec.BUILD,SpellEffect={}),spell_bonus=True,duration_reference=f['duration_reference'])
class ItemSwimCompatibilityTest(unittest.TestCase):
def fixture(self):
f=json.loads((ROOT/'tests/fixtures/item-swim-speed-source.json').read_text())
dbc=SimpleNamespace(by_id={8747:f['disk']},string={int(k):v for k,v in f['strings'].items()}.__getitem__)
src=m.source_spell(dbc,f['source'],spell_layout(),percent_stat='swim-speed')
schemas={t:codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions'/(t+'.dbd'),t)for t in('SpellName','Spell','SpellMisc','SpellEffect','SpellLevels')}
return src,f['native'],schemas,{t:1500000 for t in schemas},dict(schema_version=1,build=codec.BUILD,SpellEffect={}),f['duration_reference']
def test_positive_swim_percent_retains_native_effect_and_corrects_duration(self):
src,native,schemas,maxima,reg,duration=self.fixture();before=copy.deepcopy(native)
result=m.component([src],native,schemas,maxima,reg,percent_stat='swim-speed',duration_reference=duration)
self.assertEqual(native,before);self.assertEqual(result['definition_policy'],m.PERCENT_SWIM_POLICY)
self.assertEqual(result['spells'][0]['effects'],[dict(index=0,source_aura=58,target_aura=58,amount=15)])
self.assertFalse(any(r['table_name']=='SpellEffect'for r in result['records']))
misc=next(r['record']for r in result['records']if r['table_name']=='SpellMisc')
self.assertEqual((misc['DurationIndex'],misc['SchoolMask'],misc['Attributes'][0]),(21,8,262208))
self.assertEqual(next(r['record']['Name_lang']for r in result['records']if r['table_name']=='SpellName'),'Swimming Speed')
self.assertFalse(result['gameplay_verified'])
def test_swim_policy_does_not_admit_haste_or_unreviewed_context(self):
for mutation in('aura','school','attribute','duration','target'):
src,native,schemas,maxima,reg,duration=self.fixture()
if mutation=='aura':native['SpellEffect'][0]['EffectAura']=138
if mutation=='school':native['SpellMisc'][0]['SchoolMask']=1
if mutation=='attribute':src['attributes'][0]|=1
if mutation=='duration':duration=dict(duration,duration_ms=10000)
if mutation=='target':src['effects'][0][8]=6
with self.assertRaises(ValueError,msg=mutation):m.component([src],native,schemas,maxima,reg,percent_stat='swim-speed',duration_reference=duration)
src,*_=self.fixture()
with self.assertRaises(ValueError):m.validate_source(src,percent_stat='weapon-crit')
with self.assertRaises(ValueError):m.validate_source(src)
class ItemPercentCritCompatibilityTest(unittest.TestCase):
def fixture(self):
f=json.loads((ROOT/'tests/fixtures/item-percent-crit-source.json').read_text())
self.duration_reference=f['duration_reference']
dbc=SimpleNamespace(by_id={7597:f['disk']},string={int(k):v for k,v in f['strings'].items()}.__getitem__)
src=m.source_spell(dbc,f['source'],spell_layout(),percent_stat='weapon-crit')
schemas={t:codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions'/(t+'.dbd'),t)for t in('Spell','SpellEffect','SpellLevels','SpellMisc')}
return src,f['native'],schemas,{t:1500000 for t in schemas},dict(schema_version=1,build=codec.BUILD,SpellEffect={})
def test_genuine_percent_is_not_converted_to_rating(self):
v=self.fixture();before=copy.deepcopy(v);r=m.component([v[0]],*v[1:],percent_stat='weapon-crit',duration_reference=self.duration_reference)
self.assertEqual(v,before);self.assertEqual(r['definition_policy'],m.PERCENT_CRIT_POLICY)
self.assertEqual(r['spells'][0]['effects'],[dict(index=0,source_aura=52,target_aura=52,amount=1)])
self.assertEqual({row['table_name']for row in r['records']},{'Spell','SpellMisc'})
misc=next(row['record']for row in r['records']if row['table_name']=='SpellMisc')
self.assertEqual(misc['Attributes'],[192]+[0]*14+[8192,0])
self.assertEqual(next(row['record']['Description_lang']for row in r['records']if row['table_name']=='Spell'),v[0]['description'])
for row in r['records']:self.assertEqual(bytes.fromhex(row['wire_hex']),codec.encode(row['record'],v[2][row['table_name']]))
self.assertFalse(r['engine_accepted']);self.assertFalse(r['gameplay_verified'])
def test_old_policy_does_not_accept_new_family_implicitly(self):
v=self.fixture()
with self.assertRaises(ValueError):m.component([v[0]],*v[1:])
def test_ratings_restrictions_and_unreviewed_flags_reject(self):
for mutation in('rating','amount','equipment','misc','flags','duration'):
v=self.fixture()
if mutation=='rating':v[0]['effects'][0][1]=189
if mutation=='amount':v[0]['effects'][0][2]=100
if mutation=='equipment':v[0]['equippedItem'][0]=2
if mutation=='misc':v[0]['effects'][0][7]=1
if mutation=='flags':v[1]['SpellMisc'][0]['Attributes'][1]|=1
if mutation=='duration':self.duration_reference['duration_ms']=5000
with self.assertRaises(ValueError,msg=mutation):m.component([v[0]],*v[1:],percent_stat='weapon-crit',duration_reference=self.duration_reference)
def test_no_spell_id_allowlist(self):
v=self.fixture();v[0]['entry']=600124
for table,rows in v[1].items():
for row in rows:
if table in('Spell','SpellName'):row['ID']=600124
elif 'SpellID'in row:row['SpellID']=600124
r=m.component([v[0]],*v[1:],percent_stat='weapon-crit',duration_reference=self.duration_reference)
self.assertEqual(r['spells'][0]['spell_id'],600124)
class ItemHitAndDefenseCompatibilityTest(unittest.TestCase):
def fixture(self):
f=json.loads((ROOT/'tests/fixtures/item-hit-and-defense-source.json').read_text())
dbc=SimpleNamespace(by_id={int(k):v for k,v in f['disk_rows'].items()},string={int(k):v for k,v in f['strings'].items()}.__getitem__)
schemas={t:codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions'/(t+'.dbd'),t)for t in('SpellName','Spell','SpellMisc','SpellEffect','SpellLevels')}
return f,dbc,schemas,{t:1500000 for t in schemas},dict(schema_version=1,build=codec.BUILD,SpellEffect={})
def test_genuine_weapon_hit_uses_percent_and_exact_source_name(self):
f,dbc,schemas,maxima,reg=self.fixture();raw=next(r for r in f['server_rows']if r['entry']==15464)
src=m.source_spell(dbc,raw,spell_layout(),percent_stat='weapon-hit')
r=m.component([src],f['native'],schemas,maxima,reg,percent_stat='weapon-hit',duration_reference=f['duration_reference'])
self.assertEqual(r['definition_policy'],m.PERCENT_HIT_POLICY)
self.assertEqual({(v['table_name'],v['id'])for v in r['records']},{('SpellName',15464),('Spell',15464),('SpellMisc',325725)})
self.assertEqual(r['spells'][0]['effects'],[dict(index=0,source_aura=54,target_aura=54,amount=1)])
self.assertEqual(next(v['record']['Name_lang']for v in r['records']if v['table_name']=='SpellName'),src['name'])
f['native']['SpellEffect'][-1]['EffectAura']=189
with self.assertRaises(ValueError):m.component([src],f['native'],schemas,maxima,reg,percent_stat='weapon-hit',duration_reference=f['duration_reference'])
def test_existing_genuine_defense_skill_is_unchanged_and_reference_required(self):
f,dbc,schemas,maxima,reg=self.fixture();raw=next(r for r in f['server_rows']if r['entry']==13383)
src=m.source_spell(dbc,raw,spell_layout(),skill_bonus=True)
r=m.component([src],f['native'],schemas,maxima,reg,skill_bonus=True,skill_rows=f['skill_rows'])
self.assertEqual(r['definition_policy'],m.POSITIVE_SKILL_POLICY);self.assertEqual(r['records'],[])
self.assertEqual(r['spells'][0]['effects'],[dict(index=0,source_aura=30,target_aura=30,amount=5)])
with self.assertRaises(ValueError):m.component([src],f['native'],schemas,maxima,reg,skill_bonus=True,skill_rows=[])
with self.assertRaises(ValueError):m.component([src],f['native'],schemas,maxima,reg)
class MightSetMechanicsTest(unittest.TestCase):
def test_all_genuine_might_equipment_mechanics_share_checked_policies(self):
f=json.loads((ROOT/'tests/fixtures/item-might-set-mechanics.json').read_text())
schemas={t:codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions'/(t+'.dbd'),t)for t in('SpellName','Spell','SpellMisc','SpellEffect','SpellLevels')}
modes={47:'parry',49:'dodge',54:'weapon-hit'}
for src in f['sources']:
with self.subTest(spell=src['entry']):
aura=src['effects'][0][1];kwargs={}
if aura==30:kwargs=dict(skill_bonus=True,skill_rows=f['skills'])
elif aura in modes:kwargs=dict(percent_stat=modes[aura],duration_reference=f['duration_reference'])
else:self.assertEqual(aura,51)
before=copy.deepcopy(f['native'])
r=m.component([src],f['native'],schemas,{t:1500000 for t in schemas},dict(schema_version=1,build=codec.BUILD,SpellEffect={}),**kwargs)
self.assertEqual(f['native'],before)
self.assertEqual(len(r['records']),3 if aura==54 else 0)
self.assertEqual(r['spells'][0]['effects'][0]['source_aura'],aura)
self.assertEqual(r['spells'][0]['effects'][0]['target_aura'],aura)
self.assertFalse(r['gameplay_verified'])
def test_dodge_and_parry_are_not_interchangeable(self):
f=json.loads((ROOT/'tests/fixtures/item-might-set-mechanics.json').read_text())
for src in f['sources']:
aura=src['effects'][0][1]
if aura in(47,49):
wrong='dodge'if aura==47 else'parry'
with self.assertRaises(ValueError):m.validate_source(src,percent_stat=wrong)
if __name__=='__main__':unittest.main()