Files
aetherbound-guild/runtime/tests/p10_2/mid_contract_fixture.gd
T

100 lines
3.5 KiB
GDScript

class_name P102MidContractFixture
extends RefCounted
const P101Battle = preload("res://p10_1/first_crossing_battle_service.gd")
const P101Resolution = preload("res://p10_1/first_crossing_resolution_service.gd")
const P101Save = preload("res://p10_1/save_v7_service.gd")
const P101Fixture = preload("res://tests/p10_1/first_crossing_fixture.gd")
const BattleService = preload("res://p10_2/mid_contract_battle_service.gd")
const MarketService = preload("res://p10_2/market_service.gd")
const ResolutionService = preload("res://p10_2/mid_contract_resolution_service.gd")
const SaveV8 = preload("res://p10_2/save_v8_service.gd")
func p101_market_2_snapshot() -> Dictionary:
var prepared: Dictionary = P101Fixture.new().prepared_snapshot(2)
if prepared.is_empty():
return {}
var battle: Dictionary = P101Battle.new(prepared).run_to_terminal("follow_tide")
if not battle.ok or String(battle.snapshot.outcome) != "victory":
return {}
var resolution = P101Resolution.new(prepared)
var settled: Dictionary = resolution.settle(
"p102-fixture-first-crossing",
resolution.state.revision,
battle.snapshot
)
return resolution.state.snapshot() if settled.ok else {}
func encoded_v7(sequence: int = 7) -> Dictionary:
return P101Save.new().encode_snapshot(p101_market_2_snapshot(), sequence)
func migrated_snapshot(sequence: int = 7) -> Dictionary:
var source := encoded_v7(sequence)
if not source.ok:
return {}
var migrated := SaveV8.new().migrate_v7_text(String(source.text), sequence)
return migrated.snapshot if migrated.ok else {}
func market_service():
var snapshot_value := migrated_snapshot()
return MarketService.new(snapshot_value) if not snapshot_value.is_empty() else null
func market_service_at(market_index: int):
if market_index < 2 or market_index > 5:
return null
var service = market_service()
if service == null:
return null
while int(service.state.current_run.market_index) < market_index:
if String(service.state.current_run.phase) == "market_5":
break
var route: Dictionary = service.state.current_run.market_board.battle_offers[0]
var prepared := service.commit_route(
"fixture-route-%d" % int(service.state.current_run.market_index),
service.state.revision,
String(route.offer_id),
String(service.state.current_run.market_board.board_hash)
)
if not prepared.ok:
return null
var battle := BattleService.new(service.state.snapshot()).run_to_terminal(
preferred_plan(String(route.route_id))
)
if not battle.ok or String(battle.snapshot.outcome) != "victory":
return null
var resolution = ResolutionService.new(service.state.snapshot())
var settled := resolution.settle(
"fixture-settle-%d" % int(route.round_index),
resolution.state.revision,
battle.snapshot
)
if not settled.ok:
return null
service = MarketService.new(resolution.state.snapshot())
return service
func prepared_service(market_index: int, risk: int):
if market_index < 2 or market_index > 4 or risk < 0 or risk > 2:
return null
var service = market_service_at(market_index)
if service == null or String(service.state.current_run.phase) != "market":
return null
var route: Dictionary = service.state.current_run.market_board.battle_offers[risk]
var prepared := service.commit_route(
"fixture-target-route-%d-%d" % [market_index, risk],
service.state.revision,
String(route.offer_id),
String(service.state.current_run.market_board.board_hash)
)
return service if prepared.ok else null
func preferred_plan(route_id: String) -> String:
return String(BattleService.PREFERRED_PLAN.get(route_id, ""))