Updated silver and item collection

This commit is contained in:
2026-10-10 12:10:06 -06:00
parent 59a9fa4098
commit 85a844208a
17 changed files with 615 additions and 33 deletions
+61
View File
@@ -165,9 +165,11 @@ def test_fragment_reassembly():
(1, 'Leave'),
(6, 'HealthUpdate'),
(29, 'NewCharacter'),
(32, 'ItemGained'),
(82, 'UpdateFame'),
(90, 'CharacterEquipmentChanged'),
(91, 'RegenerationHealthChanged'),
(153, 'SilverGained'),
(166, 'KnockedDown'),
(231, 'PartyJoined'),
(233, 'PartyPlayerJoined'),
@@ -290,6 +292,65 @@ def test_world_update_fame_delta_from_total():
assert events[0]['value']['value'] == pytest.approx(0.1)
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}))
assert events == [{
'name': 'ItemCollected',
'value': {
'item_id': 522,
'item_name': 'T4_MEAL_SALAD_FISH@3',
'quantity': 3,
'estimated_value': 10000000,
},
}]
def test_world_item_gained_waits_for_main_player_join():
world = World()
assert world.transform(game('ItemGained', {0: 293153, 1: 11898, 2: 1})) == []
world.transform(game('NewCharacter', {0: 10, 1: 'SomeoneElse'}))
assert world.transform(game('ItemGained', {0: 293153, 1: 11898, 2: 1})) == []
def test_world_item_gained_uses_display_name_and_deduplicates():
world = World()
world.transform(game('Join', {0: 63, 2: 'Alice'}))
first = world.transform(game('ItemGained', {0: 293153, 1: 11898, 2: 1}))
duplicate = world.transform(game('ItemGained', {0: 293153, 1: 11898, 2: 1}))
assert first == [{
'name': 'ItemCollected',
'value': {
'item_id': 11898,
'item_name': 'Keeper Memory - Shameless or Daring',
'quantity': 1,
},
}]
assert duplicate == []
def test_world_silver_gained_tracks_known_sources():
world = World()
world.transform(game('Join', {0: 63, 2: 'Alice'}))
looted = world.transform(game('SilverGained', {1: 54, 2: 45}))
other = world.transform(game('SilverGained', {1: 168, 2: 45}))
ignored = world.transform(game('SilverGained', {1: 126, 2: 81}))
assert looted == [{'name': 'SilverGained', 'value': {
'value': 45.0, 'silver_type': 'looted'}}]
assert other == []
assert ignored == []
def test_world_silver_gained_waits_for_main_player_join():
world = World()
assert world.transform(game('SilverGained', {1: 54, 2: 45})) == []
def test_world_unconsumed_equipment_replayed_on_new_character():
world = World()
# equipment arrives before the player is named -> buffered
+31
View File
@@ -0,0 +1,31 @@
import json
from src import environment
from src.decode import discovery
def test_qt_args_removes_app_specific_options():
assert environment.qt_args([
'aostats', '--verbose', '--log-path', '/tmp/capture.jsonl',
'--style', 'fusion']) == ['aostats', '--style', 'fusion']
assert environment.qt_args([
'aostats', '--log-path=/tmp/capture.jsonl']) == ['aostats']
def test_discovery_log_writes_jsonl_with_item_annotations(monkeypatch, tmp_path):
path = tmp_path / 'capture.jsonl'
monkeypatch.setattr(discovery, 'discovery_log_path', lambda: str(path))
monkeypatch.setattr(discovery, '_initialized', False)
monkeypatch.setattr(discovery.itemdb, 'get_db', lambda: {836: 'T6_STONEBLOCK'})
discovery.log('game_message', params={1: [836], 2: b'\x01'})
rows = [json.loads(line) for line in path.read_text().splitlines()]
assert rows[0]['type'] == 'session_start'
assert rows[1]['type'] == 'game_message'
assert discovery.item_candidates({1: [836]}) == [{
'path': '1[0]',
'id': 836,
'unique_name': 'T6_STONEBLOCK',
}]
+29
View File
@@ -0,0 +1,29 @@
from src.stats.economy_stats import EconomyStats
def test_economy_stats_accumulates_silver_and_items():
stats = EconomyStats()
stats.receive({'name': 'SilverGained', 'value': {
'value': 45.0, 'silver_type': 'looted'}})
stats.receive({'name': 'SilverGained', 'value': {
'value': 12.0, 'silver_type': 'other'}})
stats.receive({'name': 'ItemCollected', 'value': {
'item_id': 522,
'item_name': 'T4_MEAL_SALAD_FISH@3',
'quantity': 3,
}})
stats.receive({'name': 'ItemCollected', 'value': {
'item_id': 522,
'item_name': 'T4_MEAL_SALAD_FISH@3',
'quantity': 4,
}})
assert stats.stats() == {
'looted_silver': 45.0,
'other_silver': 12.0,
'total_silver': 57.0,
}
items = stats.item_list()
assert len(items) == 1
assert items[0].name == 'T4_MEAL_SALAD_FISH@3'
assert items[0].value == 7.0