Working advanced tracking code
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

This commit is contained in:
2026-10-13 09:08:38 -06:00
parent f3114b076a
commit 7279b3c207
23 changed files with 336893 additions and 7521 deletions
+121 -1
View File
@@ -308,6 +308,122 @@ def test_world_health_update_known_actor_unknown_target_emits_damage_done():
assert events[0]['value']['target'] is None
# --- Health update accessors ---------------------------------------------------
def test_health_update_accessors():
msg = game('HealthUpdate', {0: 10, 2: -80.0, 3: 420.0, 5: 3, 6: 20, 7: -1})
assert translate.msg_subject_id(msg) == 10 # param 0 is the victim
assert translate.msg_attacker_id(msg) == 20 # param 6 is the attacker
assert translate.msg_value(msg) == -80.0
assert translate.msg_health_after(msg) == 420.0
assert translate.msg_hit_type(msg) == 3
def test_health_update_accessors_tolerate_missing_params():
msg = game('HealthUpdate', {})
assert translate.msg_subject_id(msg) == 0
assert translate.msg_attacker_id(msg) == 0
assert translate.msg_value(msg) == 0.0
assert translate.msg_health_after(msg) is None
assert translate.msg_hit_type(msg) is None
def test_byte_list_unpacks_every_encoded_shape():
# Batched params arrive as raw bytes, as the discovery log's dict form, or
# as an already-decoded list depending on the decoder path.
assert translate._as_byte_list(b'\x01\x02') == [1, 2]
assert translate._as_byte_list({'bytes_hex': 'c5c5', 'len': 2}) == [197, 197]
assert translate._as_byte_list([3, 4]) == [3, 4]
assert translate._as_byte_list(None) == []
def test_batched_health_update_accessors():
msg = game('BatchedHealthUpdate', {
0: 76,
1: [11, 12],
2: [-41.0, -135.0],
3: [3416.0, 3281.0],
5: b'\x00\x02',
6: b'\xc5\x58',
})
assert translate.msg_batched_victim_id(msg) == 76
assert translate.msg_batched_ticks(msg) == [11, 12]
assert translate.msg_batched_values(msg) == [-41.0, -135.0]
assert translate.msg_batched_health_after(msg) == [3416.0, 3281.0]
assert translate.msg_batched_hit_types(msg) == [0, 2]
assert translate.msg_batched_attacker_ids(msg) == [197, 88]
# --- Batched health update -----------------------------------------------------
def test_world_batched_health_update_emits_one_event_per_hit():
world = World()
world.transform(game('NewCharacter', {0: 10, 1: 'Victim'}))
world.transform(game('NewCharacter', {0: 20, 1: 'Attacker'}))
world.transform(game('NewCharacter', {0: 30, 1: 'Other'}))
events = world.transform(game('BatchedHealthUpdate', {
0: 10,
2: [-41.0, -135.0],
3: [3416.0, 3281.0],
5: b'\x00\x02',
6: b'\x14\x1e',
}))
# two hits, each producing DamageDone and DamageTaken
assert len(events) == 4
assert [e['name'] for e in events] == [
'DamageDone', 'DamageTaken', 'DamageDone', 'DamageTaken']
assert [e['value']['value'] for e in events] == [41.0, 41.0, 135.0, 135.0]
# the attacker differs per hit and must be credited per hit, not per packet
assert events[0]['value']['source'] == 1 # attacker 20
assert events[2]['value']['source'] == 2 # attacker 30
assert [e['value']['hit_type'] for e in (events[0], events[2])] == [0, 2]
assert [e['value']['health_after'] for e in (events[0], events[2])] == [3416.0, 3281.0]
def test_world_batched_health_update_skips_zero_and_unknown():
world = World()
world.transform(game('NewCharacter', {0: 10, 1: 'Victim'}))
world.transform(game('NewCharacter', {0: 20, 1: 'Attacker'}))
events = world.transform(game('BatchedHealthUpdate', {
0: 10, 2: [0.0, -25.0], 3: [500.0, 475.0], 6: b'\x14\x14'}))
assert [e['name'] for e in events] == ['DamageDone', 'DamageTaken']
assert events[0]['value']['value'] == 25.0
# a victim nobody tracks, hit by nobody tracked, produces nothing
assert world.transform(game('BatchedHealthUpdate', {
0: 777, 2: [-10.0], 3: [90.0], 6: b'\x88'})) == []
def test_world_batched_health_update_tolerates_short_arrays():
"""A missing attacker list must not raise or misattribute the hit."""
world = World()
world.transform(game('NewCharacter', {0: 10, 1: 'Victim'}))
events = world.transform(game('BatchedHealthUpdate', {
0: 10, 2: [-25.0], 3: [475.0]}))
assert [e['name'] for e in events] == ['DamageTaken']
assert events[0]['value']['source'] == 0
def test_world_batched_health_update_empty_yields_nothing():
world = World()
world.transform(game('NewCharacter', {0: 10, 1: 'Victim'}))
assert world.transform(game('BatchedHealthUpdate', {0: 10, 2: []})) == []
def test_batched_health_update_opcode_is_translated():
from src.decode.pipeline import Pipeline
events = []
pipeline = Pipeline(events.append)
payload = enet_unreliable_packet(
0x07, event_payload(7, [(0, p18_short(76)), (2, p18_string('x'))]))
pipeline.on_udp(payload)
# recognised as a game message even though it carries no usable deltas
assert events == []
def test_world_regeneration_combat_states():
world = World()
world.transform(game('NewCharacter', {0: 10, 1: 'Alice'}))
@@ -360,11 +476,15 @@ def test_world_item_gained_emits_collected_item():
world = World()
world.transform(game('Join', {0: 63, 2: 'Alice'}))
events = world.transform(game('ItemGained', {1: 522, 2: 3, 4: 10000000}))
# Item 522 is T1_SILVERBAG_NONTRADABLE in the current game data. This test
# previously expected T4_MEAL_SALAD_FISH@3, which is what the stale item id
# table claimed; ids are reassigned between game builds, and that table
# resolved 0 of 8 slots on a real equipment array.
assert events == [{
'name': 'ItemCollected',
'value': {
'item_id': 522,
'item_name': 'T4_MEAL_SALAD_FISH@3',
'item_name': 'T1_SILVERBAG_NONTRADABLE',
'quantity': 3,
'estimated_value': 10000000,
},