7279b3c207
Build / Build source distribution (push) Failing after 13s
Build / Execute unit tests (push) Failing after 8s
Build / Verify generated game data is current (push) Failing after 7s
Build / Upload Release Asset (push) Has been skipped
Build / upload_pypi (push) Has been skipped
313 lines
11 KiB
Python
313 lines
11 KiB
Python
"""Regression tests for the generated game data tables.
|
|
|
|
These assert facts established against real captures. Each one is anchored to a
|
|
specific observation, and the item-id assertions in particular fail against the
|
|
table this project used to ship -- which is the point: that table was silently
|
|
wrong, and nothing caught it.
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
|
|
import pytest
|
|
|
|
from src.decode import items as itemdb
|
|
|
|
_ARMOR_TYPES = ('physicalarmor', 'magicresistance')
|
|
|
|
_REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
STATIC = os.path.join(_REPO, 'src', 'static')
|
|
|
|
|
|
def _load(name):
|
|
with open(os.path.join(STATIC, name), encoding='utf-8') as handle:
|
|
return json.load(handle)
|
|
|
|
|
|
@pytest.fixture(scope='module')
|
|
def item_spells():
|
|
return _load('item_spells.json')
|
|
|
|
|
|
@pytest.fixture(scope='module')
|
|
def debuff_spells():
|
|
return _load('debuff_spells.json')
|
|
|
|
|
|
@pytest.fixture(scope='module')
|
|
def mob_armor():
|
|
return _load('mob_armor.json')
|
|
|
|
|
|
@pytest.fixture(scope='module')
|
|
def item_power():
|
|
return _load('item_power.json')
|
|
|
|
|
|
@pytest.fixture(scope='module')
|
|
def progression():
|
|
return _load('progression.json')
|
|
|
|
|
|
# --- item ids ----------------------------------------------------------------
|
|
|
|
def test_real_equipment_array_resolves_by_position():
|
|
"""Every slot of a real equipment array resolves to the matching item.
|
|
|
|
The array is the equipment payload from a capture in
|
|
/tmp/aostats-debuff-test03, in wire order: weapon, offhand, helmet, armor,
|
|
boots, bag, cape, mount. The table this replaces scored 0 of these 8; it
|
|
reported a helmet as a firestaff and armor as a backpack.
|
|
"""
|
|
array = [7739, 2372, 5054, 4168, 4648, 2888, 2600, 3030]
|
|
expected = [
|
|
'T5_MAIN_HOLYSTAFF_AVALON@1',
|
|
'T7_OFF_TORCH',
|
|
'T7_HEAD_CLOTH_HELL',
|
|
'T6_ARMOR_LEATHER_SET2',
|
|
'T7_SHOES_LEATHER_AVALON',
|
|
'T4_BAG',
|
|
'T7_CAPEITEM_FW_LYMHURST@1',
|
|
'T5_MOUNT_HORSE',
|
|
]
|
|
assert [itemdb.get_db()[i] for i in array] == expected
|
|
|
|
|
|
def test_cursed_staff_resolves_to_armor_piercer(item_spells):
|
|
"""The weapon that actually cast Armor Piercer in the capture.
|
|
|
|
The packet carries the enchanted variant, T6_MAIN_CURSEDSTAFF@1, but only
|
|
the base item exists in the dump -- so the table aliases the variants.
|
|
Without that alias a lookup straight from a packet id finds nothing.
|
|
"""
|
|
assert item_spells['T6_MAIN_CURSEDSTAFF@1'] == \
|
|
item_spells['T6_MAIN_CURSEDSTAFF']
|
|
by_slot = {}
|
|
for entry in item_spells['T6_MAIN_CURSEDSTAFF@1']:
|
|
by_slot.setdefault(entry['slot'], []).append(entry['spell'])
|
|
assert by_slot['2'] == ['ARMORPIERCER', 'CURSENOVA', 'CURSEDHANDS_STACKUP',
|
|
'CURSEDBEAM', 'DARKMATTER']
|
|
assert by_slot['3'] == ['DEATHCURSE2']
|
|
|
|
|
|
def test_enchantment_variants_have_distinct_ids():
|
|
"""Enchantment level is in the item id, not folded into the base."""
|
|
db = itemdb.get_db()
|
|
assert db[7738] == 'T5_MAIN_HOLYSTAFF_AVALON'
|
|
assert db[7739] == 'T5_MAIN_HOLYSTAFF_AVALON@1'
|
|
assert db[7740] == 'T5_MAIN_HOLYSTAFF_AVALON@2'
|
|
|
|
|
|
# --- item power --------------------------------------------------------------
|
|
|
|
def test_item_power_follows_enchantment(item_power):
|
|
"""Item power scales with enchantment, so it can anchor damage maths.
|
|
|
|
This is what keeps the model correct as a player levels their weapon,
|
|
rather than inferring a constant from observed hits.
|
|
"""
|
|
assert item_power['T5_MAIN_HOLYSTAFF_AVALON'] == 900
|
|
assert item_power['T5_MAIN_HOLYSTAFF_AVALON@1'] == 1000
|
|
assert item_power['T5_MAIN_HOLYSTAFF_AVALON@4'] == 1300
|
|
|
|
|
|
# --- item -> spell binding ---------------------------------------------------
|
|
|
|
def test_spell_binding_follows_reference_inheritance(item_spells):
|
|
"""T5_MAIN_HOLYSTAFF_AVALON has no craftingspelllist of its own.
|
|
|
|
It inherits through two levels of @reference, and only the base carries
|
|
the abilities. Unresolved, it would have no spells at all.
|
|
"""
|
|
spells = item_spells['T5_MAIN_HOLYSTAFF_AVALON']
|
|
assert spells, 'inherited spell list is empty'
|
|
by_slot = {}
|
|
for entry in spells:
|
|
by_slot.setdefault(entry['slot'], []).append(entry['spell'])
|
|
assert 'HEALINGBEAM' in by_slot['2']
|
|
assert 'DIVINE_JUMP' in by_slot['3']
|
|
|
|
|
|
def test_removespell_drops_inherited_ability(item_spells):
|
|
"""T4_MAIN_HOLYSTAFF_AVALON inherits the base but drops one spell."""
|
|
inherited = {e['spell'] for e in item_spells['T4_MAIN_HOLYSTAFF']}
|
|
avalon = {e['spell'] for e in item_spells['T4_MAIN_HOLYSTAFF_AVALON']}
|
|
assert 'HOLYDESPERATEPRAYER2' in inherited
|
|
assert 'HOLYDESPERATEPRAYER2' not in avalon
|
|
assert 'DIVINE_JUMP' in avalon
|
|
|
|
|
|
def test_every_spell_bearing_item_resolves(item_spells):
|
|
"""100% coverage: no item that has ability slots lacks its spell list.
|
|
|
|
Naively 471 weapons look empty until @reference is resolved.
|
|
"""
|
|
cache = os.path.join('.cache', 'gamedata', 'items.json')
|
|
if not os.path.exists(cache):
|
|
pytest.skip('game data cache absent; run scripts/fetch_gamedata.py')
|
|
|
|
with open(cache, encoding='utf-8') as handle:
|
|
items_root = json.load(handle)['items']
|
|
|
|
index = {}
|
|
for group, value in items_root.items():
|
|
if group.startswith('@') or group == 'shopcategories':
|
|
continue
|
|
entries = value if isinstance(value, list) else (
|
|
[value] if isinstance(value, dict) else [])
|
|
for entry in entries:
|
|
if isinstance(entry, dict) and entry.get('@uniquename'):
|
|
index[entry['@uniquename']] = entry
|
|
|
|
missing = []
|
|
for name, entry in index.items():
|
|
slots = entry.get('@activespellslots')
|
|
if not slots or str(slots) in ('0', ''):
|
|
continue
|
|
if not item_spells.get(name):
|
|
missing.append(name)
|
|
assert not missing, 'items with ability slots but no spells: {}'.format(
|
|
missing[:5])
|
|
|
|
|
|
# --- debuff resolution ------------------------------------------------------
|
|
|
|
def test_debuff_reached_through_spell_chain(debuff_spells):
|
|
"""ARMORPIERCER carries no buffovertime of its own.
|
|
|
|
The armour numbers live two hops away:
|
|
ARMORPIERCER -> spelleffectarea -> ARMORPIERCER_EFFECT
|
|
-> applyspell -> ARMORPIERCER_DEBUFF_EFFECT
|
|
Matching only an ability's own effects would find nothing at all.
|
|
"""
|
|
entry = debuff_spells['ARMORPIERCER_DEBUFF_EFFECT']
|
|
assert entry['abilities'] == ['ARMORPIERCER']
|
|
|
|
physical = [e for e in entry['effects'] if e['type'] == 'physicalarmor']
|
|
assert len(physical) == 1
|
|
assert physical[0]['value'] == pytest.approx(-0.17)
|
|
assert physical[0]['time'] == pytest.approx(4.0)
|
|
|
|
|
|
def test_debuff_magnitude_scaling_is_preserved(debuff_spells):
|
|
"""Armor Piercer is stronger against more targets.
|
|
|
|
The multiplier must be carried through, because attribution has to read the
|
|
magnitude off the observed effect rather than assume the base value.
|
|
"""
|
|
for effect in debuff_spells['ARMORPIERCER_DEBUFF_EFFECT']['effects']:
|
|
assert effect['targetcountvaluebonusfactor'] == pytest.approx(0.08)
|
|
|
|
|
|
def test_mob_and_player_variants_are_distinguished(debuff_spells):
|
|
"""SUNDERARMOR2 is weaker against players than against mobs."""
|
|
effects = debuff_spells['SUNDERARMOR2']['effects']
|
|
by_target = {}
|
|
for effect in effects:
|
|
if effect['type'] == 'physicalarmor':
|
|
by_target[effect.get('iftargettype')] = effect['value']
|
|
assert by_target['player'] == pytest.approx(-0.04)
|
|
assert by_target['mob'] == pytest.approx(-0.06)
|
|
assert debuff_spells['SUNDERARMOR2']['maxstack'] == 3
|
|
|
|
|
|
def test_every_debuff_is_attributable_to_an_ability(debuff_spells):
|
|
"""Each debuff effect names the ability that caused it.
|
|
|
|
That link is what turns an observed effect into a player, via the ability's
|
|
slot on the attacker's weapon.
|
|
"""
|
|
for name, entry in debuff_spells.items():
|
|
assert entry['abilities'], '{} has no producing ability'.format(name)
|
|
assert entry['effects'], '{} has no effects'.format(name)
|
|
|
|
|
|
def test_armour_debuffs_combine_additively(debuff_spells):
|
|
"""No armour debuff uses a stacking rule.
|
|
|
|
Absence of @stackingrule means same-type effects sum, which is what makes
|
|
the combined victim reduction a plain sum rather than a priority puzzle.
|
|
"""
|
|
cache = os.path.join('.cache', 'gamedata', 'spells.json')
|
|
if not os.path.exists(cache):
|
|
pytest.skip('game data cache absent; run scripts/fetch_gamedata.py')
|
|
|
|
with open(cache, encoding='utf-8') as handle:
|
|
spells_root = json.load(handle)['spells']
|
|
|
|
checked = 0
|
|
for group in ('activespell', 'passivespell', 'togglespell'):
|
|
for spell in spells_root.get(group) or []:
|
|
bot = spell.get('buffovertime')
|
|
entries = bot if isinstance(bot, list) else ([bot] if bot else [])
|
|
if not any(isinstance(e, dict)
|
|
and e.get('@type') in _ARMOR_TYPES
|
|
for e in entries):
|
|
continue
|
|
checked += 1
|
|
assert not spell.get('@stackingrule'), (
|
|
'armour debuff {} declares a stacking rule'.format(
|
|
spell.get('@uniquename')))
|
|
assert not spell.get('@stackinggroup'), (
|
|
'armour debuff {} declares a stacking group'.format(
|
|
spell.get('@uniquename')))
|
|
assert checked > 100
|
|
|
|
|
|
# --- mob templates ----------------------------------------------------------
|
|
|
|
def test_mob_template_resolves_to_known_mob(mob_armor):
|
|
"""Template 454 is the Giant Snake from the controlled capture.
|
|
|
|
Opcode 252/123 carries the template id in param 1 and max HP in param 13;
|
|
both were cross-checked against the packet.
|
|
"""
|
|
assert mob_armor['454'] == {
|
|
'name': 'T5_MOB_HIDE_SWAMP_GIANTSNAKE',
|
|
'tier': 5,
|
|
'armor': 136,
|
|
'resistance': 136,
|
|
'hitpointsmax': 1162,
|
|
'category': 'hidemob',
|
|
}
|
|
|
|
|
|
@pytest.mark.parametrize('template_id,expected_name,expected_hp', [
|
|
('448', 'T1_MOB_HIDE_SWAMP_TOAD', 20),
|
|
('2722', 'T5_MOB_CITY_SWAMP_GUARD', 1509),
|
|
('2724', 'T4_MOB_CITY_SWAMP_KNIGHT_ELITE', 11606),
|
|
('2725', 'T5_MOB_CITY_SWAMP_BOSS', 27795),
|
|
('2757', 'T6_MOB_GUARD_TOWER', 153572),
|
|
])
|
|
def test_mob_templates_match_observed_max_hp(
|
|
mob_armor, template_id, expected_name, expected_hp):
|
|
"""Each was seen in a capture alongside its max HP."""
|
|
entry = mob_armor[template_id]
|
|
assert entry['name'] == expected_name
|
|
assert entry['hitpointsmax'] == expected_hp
|
|
|
|
|
|
def test_mob_and_item_ids_are_separate_spaces(mob_armor):
|
|
"""Template 454 and item 454 are different things.
|
|
|
|
Worth pinning: the discovery logger walks every integer in every message
|
|
and labels it with the item table, so decoding opcode 123 naively would
|
|
report the Giant Snake as a gathering skillbook.
|
|
"""
|
|
assert mob_armor['454']['name'] == 'T5_MOB_HIDE_SWAMP_GIANTSNAKE'
|
|
assert itemdb.get_db()[454] == 'T5_SKILLBOOK_GATHER_FIBER'
|
|
|
|
|
|
# --- progression ------------------------------------------------------------
|
|
|
|
def test_progression_constants_present(progression):
|
|
"""Armour and damage scale off item power using these constants."""
|
|
slot = progression['slots']['mainhand_2h']
|
|
assert slot['armorbase'] == pytest.approx(100.0)
|
|
assert slot['armorprogression'] == pytest.approx(1.03)
|
|
assert slot['attackdamageprogression'] == pytest.approx(1.0918)
|
|
|
|
share = progression['shares']['armorshare']
|
|
assert float(share['@armor']) == pytest.approx(1.0)
|
|
assert float(share['@head']) == pytest.approx(0.0)
|