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
172 lines
5.6 KiB
Python
172 lines
5.6 KiB
Python
"""Protocol tests for the effect stack and mob spawn opcodes.
|
|
|
|
Both were identified from /tmp/aostats-party01.jsonl, a T5 Morgana dungeon run
|
|
in which one player applied Armor Piercer and a party mate finished the mobs.
|
|
Every assertion here is anchored to a specific observation in that capture.
|
|
"""
|
|
|
|
import json
|
|
|
|
import pytest
|
|
|
|
from src.decode.translate import (
|
|
EffectApplication,
|
|
GameMessage,
|
|
into_game_message,
|
|
msg_effect_stack_applications,
|
|
msg_mob_hitpoints_max,
|
|
msg_mob_template_id,
|
|
)
|
|
|
|
|
|
def effect_msg(victim, appliers, effect_ids, flags='00', values='00'):
|
|
"""Build the EffectStackUpdate shape seen on the wire."""
|
|
n = len(appliers)
|
|
return GameMessage('EffectStackUpdate', 22, {
|
|
0: victim,
|
|
1: list(appliers),
|
|
2: list(effect_ids),
|
|
3: {'bytes_hex': flags * n, 'len': n},
|
|
4: {'bytes_hex': values * n, 'len': n},
|
|
})
|
|
|
|
|
|
def mob_msg(entity, template, hitpoints_max):
|
|
return GameMessage('MobSpawned', 123, {
|
|
0: entity,
|
|
1: template,
|
|
2: 255,
|
|
13: float(hitpoints_max),
|
|
14: float(hitpoints_max),
|
|
})
|
|
|
|
|
|
# --- effect stack ------------------------------------------------------------
|
|
|
|
def test_effect_stack_pairs_applier_with_effect():
|
|
msg = effect_msg(78724, [90362, 90547, 90547], [3163, 3097, 3098])
|
|
assert msg_effect_stack_applications(msg) == [
|
|
EffectApplication(applier=90362, effect_id=3163),
|
|
EffectApplication(applier=90547, effect_id=3097),
|
|
EffectApplication(applier=90547, effect_id=3098),
|
|
]
|
|
|
|
|
|
def test_applier_is_sent_explicitly():
|
|
"""Attribution does not have to guess who applied a debuff.
|
|
|
|
This is the reason the game sends the applier per effect. The original
|
|
plan assumed it would have to be inferred from the attacker's equipped
|
|
weapon; the packets do not require that.
|
|
"""
|
|
msg = effect_msg(78724, [90547, 90547, 90547], [3097, 3098, 3099])
|
|
appliers = {a.applier for a in msg_effect_stack_applications(msg)}
|
|
assert appliers == {90547}
|
|
|
|
|
|
def test_one_applier_can_hold_several_effects():
|
|
"""Armor Piercer is a beam that hits several targets at once.
|
|
|
|
Observed at 16:49:54.256: bionicKatana's three effect ids landed on three
|
|
different victims within a millisecond of each other, which is the
|
|
multi-target shape of the spell.
|
|
"""
|
|
msg = effect_msg(78724,
|
|
[90547, 90547, 90547, 90547, 90547],
|
|
[3097, 3098, 3099, 3092, 3093])
|
|
apps = msg_effect_stack_applications(msg)
|
|
assert len(apps) == 5
|
|
assert all(a.applier == 90547 for a in apps)
|
|
assert {a.effect_id for a in apps} == {3092, 3093, 3097, 3098, 3099}
|
|
|
|
|
|
def test_ragged_arrays_are_truncated_not_guessed():
|
|
"""A mismatched pair drops the tail rather than pairing unrelated ids."""
|
|
msg = effect_msg(78724, [90547, 90547, 90547], [3097, 3098])
|
|
assert len(msg_effect_stack_applications(msg)) == 2
|
|
|
|
|
|
def test_effect_stack_opcode_is_named():
|
|
"""Opcode 22 resolves to a name instead of being dropped."""
|
|
raw = _photon(code=1, kind='Event',
|
|
params={0: 78724, 1: [90547], 2: [3097], 252: 22})
|
|
msg = into_game_message(raw)
|
|
assert msg is not None
|
|
assert msg.name == 'EffectStackUpdate'
|
|
|
|
|
|
# --- mob spawn ---------------------------------------------------------------
|
|
|
|
def test_mob_spawn_carries_template_and_max_hp():
|
|
"""Template 2501 is a T5 Keeper Giant Champion, and max HP agrees.
|
|
|
|
Both fields were cross-checked against the packet, which is what makes the
|
|
template id safe to trust.
|
|
"""
|
|
msg = mob_msg(78724, 2501, 3282.0)
|
|
assert msg_mob_template_id(msg) == 2501
|
|
assert msg_mob_hitpoints_max(msg) == pytest.approx(3282.0)
|
|
|
|
|
|
def test_mob_spawn_opcode_is_named():
|
|
raw = _photon(code=1, kind='Event',
|
|
params={0: 78724, 1: 2501, 13: 3282.0, 252: 123})
|
|
msg = into_game_message(raw)
|
|
assert msg is not None
|
|
assert msg.name == 'MobSpawned'
|
|
|
|
|
|
def test_mob_template_is_not_an_item_id():
|
|
"""Mob template ids and item ids are different id spaces.
|
|
|
|
The discovery logger labels every integer it sees using the item table, so
|
|
this separation has to hold or every spawned mob would be reported as
|
|
whatever item happens to share its number.
|
|
"""
|
|
from src.decode import items as itemdb
|
|
db = itemdb.get_db()
|
|
|
|
# 454 was observed as a mob template for a Giant Snake...
|
|
msg = mob_msg(1, 454, 1162.0)
|
|
assert msg_mob_template_id(msg) == 454
|
|
# ...while item 454 is something else entirely.
|
|
assert db[454] == 'T5_SKILLBOOK_GATHER_FIBER'
|
|
assert mob_armor_name(454) == 'T5_MOB_HIDE_SWAMP_GIANTSNAKE'
|
|
|
|
|
|
def mob_armor_name(template_id):
|
|
with open(_static_path('mob_armor.json'), encoding='utf-8') as handle:
|
|
return json.load(handle)[str(template_id)]['name']
|
|
|
|
|
|
def _static_path(name):
|
|
import os
|
|
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
return os.path.join(root, 'src', 'static', name)
|
|
|
|
|
|
# --- capture-derived findings ------------------------------------------------
|
|
|
|
@pytest.mark.parametrize('applier,effect_ids', [
|
|
(90547, [3097, 3098, 3099]),
|
|
(90547, [3092, 3093]),
|
|
(90362, [3163]),
|
|
])
|
|
def test_real_payload_shapes_decode(applier, effect_ids):
|
|
"""Shapes taken verbatim from the capture still decode cleanly."""
|
|
msg = effect_msg(78724, [applier] * len(effect_ids), effect_ids)
|
|
apps = msg_effect_stack_applications(msg)
|
|
assert [a.effect_id for a in apps] == effect_ids
|
|
assert all(a.applier == applier for a in apps)
|
|
|
|
|
|
def _photon(code, kind, params):
|
|
class Raw:
|
|
pass
|
|
raw = Raw()
|
|
raw.code = code
|
|
raw.kind = kind
|
|
raw.params = params
|
|
raw.debug_message = None
|
|
return raw
|