Working on party stuff, mostly works

This commit is contained in:
2026-10-10 14:07:14 -06:00
parent 85a844208a
commit 60137a2de4
10 changed files with 400 additions and 21 deletions
+88
View File
@@ -3,11 +3,13 @@ import struct
import pytest
from src.decode import photon
from src.decode import party_memory
from src.decode import translate
from src.decode.photon import PhotonDecoder, decode_message18
from src.decode.translate import into_game_message
from src.decode.world import IdCache, World
from src.net.capture import _extract_udp_payload
from src.utils import platform_utils
# --- Protocol18 value builders -------------------------------------------------
@@ -194,6 +196,27 @@ def test_unknown_opcode_ignored():
assert into_game_message(message) is None
def test_party_roster_without_opcode_translates():
message = photon.PhotonMessage('Event', 1, {
0: 123,
9: ['bionicKatana', 'Sweetpea23042'],
}, None, None)
game = into_game_message(message)
assert game is not None
assert game.name == 'PartyRoster'
assert translate.msg_party_roster_names(game) == [
'bionicKatana', 'Sweetpea23042']
def test_unlock_response_string_lists_are_not_party_rosters():
message = photon.PhotonMessage('Response', 1, {
9: ['UNLOCKED_CLAIMABLE', 'UNLOCKED_CLAIMABLE'],
}, None, None)
assert into_game_message(message) is None
# --- world ----------------------------------------------------------------------
def game(name, params=None):
@@ -375,6 +398,71 @@ def test_party_events_from_structures():
assert left[0]['value']['player_names'] == ['Alice']
def test_party_roster_event_updates_party():
world = World()
events = world.transform(game('PartyRoster', {
9: ['bionicKatana', 'Sweetpea23042'],
}))
assert events == [{
'name': 'UpdateParty',
'value': {'player_names': ['bionicKatana', 'Sweetpea23042']},
}]
def test_remembered_party_reemits_on_join(monkeypatch, tmp_path):
monkeypatch.setattr(platform_utils, 'config_dir', lambda: str(tmp_path))
party_memory.save_last_party([
'bionicKatana', 'fatbrick', 'Froedrick712', 'rainbowShade'])
world = World(remember_last_party=True)
events = world.transform(game('Join', {0: 98, 2: 'bionicKatana'}))
assert events[-1] == {
'name': 'UpdateParty',
'value': {'player_names': [
'bionicKatana', 'fatbrick', 'Froedrick712', 'rainbowShade']},
}
def test_party_inference_grows_during_zone_load(monkeypatch, tmp_path):
monkeypatch.setattr(platform_utils, 'config_dir', lambda: str(tmp_path))
world = World(remember_last_party=True)
world.transform(game('NewCharacter', {0: 97, 1: 'rainbowShade'}))
join = world.transform(game('Join', {0: 98, 2: 'bionicKatana'}))
fatbrick = world.transform(game('NewCharacter', {0: 161, 1: 'fatbrick'}))
froedrick = world.transform(game('NewCharacter', {0: 211, 1: 'Froedrick712'}))
assert _last_party_names(join) == [
'rainbowShade', 'bionicKatana']
assert _last_party_names(fatbrick) == [
'rainbowShade', 'bionicKatana', 'fatbrick']
assert _last_party_names(froedrick) == [
'rainbowShade', 'bionicKatana', 'fatbrick', 'Froedrick712']
assert party_memory.load_last_party() == [
'rainbowShade', 'bionicKatana', 'fatbrick', 'Froedrick712']
def test_party_disband_clears_remembered_party(monkeypatch, tmp_path):
monkeypatch.setattr(platform_utils, 'config_dir', lambda: str(tmp_path))
world = World(remember_last_party=True)
world.transform(game('PartyRoster', {
9: ['bionicKatana', 'fatbrick'],
}))
assert party_memory.load_last_party() == ['bionicKatana', 'fatbrick']
world.transform(game('PartyDisbanded'))
assert party_memory.load_last_party() == []
def _last_party_names(events):
party_events = [e for e in events if e['name'] == 'UpdateParty']
return party_events[-1]['value']['player_names']
def test_party_main_player_left_disbands():
world = World()
world.party.set_main_player_name('Alice')