Files
aetherbound-guild/runtime/campaign/fg2_fixture.gd
T

101 lines
4.8 KiB
GDScript

class_name ABGFG2Fixture
extends RefCounted
const MarketService = preload("res://p10_0/market_service.gd")
const BattleService = preload("res://p10_0/wave_battle_service.gd")
const ResolutionService = preload("res://p10_0/resolution_service.gd")
static func canonical_market_state() -> Dictionary:
return _created_market().state.snapshot()
static func canonical_encounter_state() -> Dictionary:
var market = _created_market()
var offer_id := _route_id(market, 0)
assert(not offer_id.is_empty())
var route_result: Dictionary = market.commit_battle_offer("fg2-canonical-route", market.state.revision, offer_id, String(market.state.current_run.market_board.board_hash))
assert(route_result.ok)
return market.state.snapshot()
static func reward_market_state() -> Dictionary:
var encounter := canonical_encounter_state()
var terminal: Dictionary = BattleService.new(encounter).run_to_terminal().snapshot
assert(String(terminal.outcome) == "victory")
var resolver = ResolutionService.new(encounter)
var settlement: Dictionary = resolver.settle_battle("fg2-reward-settle", resolver.state.revision, String(terminal.snapshot_hash), terminal)
assert(settlement.ok)
return resolver.state.snapshot()
static func wounded_high_risk_market_state() -> Dictionary:
var market = _created_market()
var funded: Dictionary = market.state.snapshot()
funded.current_run.coin = 100
var funded_restored: bool = market.restore_snapshot(funded)
assert(funded_restored)
for index in range(3):
var offer: Dictionary = market.state.current_run.market_board.recruit_offers[index]
var hire_result: Dictionary = market.hire("fg2-wounded-hire-%d" % index, market.state.revision, String(offer.source_offer_id), int(offer.list_price), false)
assert(hire_result.ok)
var deployed: Array = Array(market.state.current_run.company).slice(0, 3)
var deployment: Dictionary = market.commit_deployment("fg2-wounded-line", market.state.revision, deployed)
assert(deployment.ok)
var wounded: Dictionary = market.state.snapshot()
wounded.current_run.coin = 12
for recruit_id in deployed:
wounded.current_run.recruit_records[recruit_id].current_hp = 1
wounded.current_run.recruit_records[recruit_id].original_list_price = 22
wounded.current_run.recruit_records[recruit_id].coin_price_paid = 18
for key in wounded.current_run.recruit_records[recruit_id].attribute_rolls:
wounded.current_run.recruit_records[recruit_id].attribute_rolls[key] = "D"
var wounded_restored: bool = market.restore_snapshot(wounded)
assert(wounded_restored)
return market.state.snapshot()
static func recovery_market_state() -> Dictionary:
var market = MarketService.new(wounded_high_risk_market_state())
var offer_id := _route_id(market, 2)
assert(not offer_id.is_empty())
var route_result: Dictionary = market.commit_battle_offer("fg2-recovery-route", market.state.revision, offer_id, String(market.state.current_run.market_board.board_hash))
assert(route_result.ok)
var terminal: Dictionary = BattleService.new(market.state.snapshot()).run_to_terminal().snapshot
assert(String(terminal.outcome) == "defeat")
assert(terminal.fallen_recruit_ids.size() == 3)
var resolver = ResolutionService.new(market.state.snapshot())
var settlement: Dictionary = resolver.settle_battle("fg2-recovery-settle", resolver.state.revision, String(terminal.snapshot_hash), terminal)
assert(settlement.ok)
assert(bool(resolver.state.current_run.recovery_required))
return resolver.state.snapshot()
static func route_id(snapshot_value: Dictionary, risk: int) -> String:
var market = MarketService.new(snapshot_value)
return _route_id(market, risk)
static func _created_market():
var market = MarketService.new()
var begun: Dictionary = market.begin_run_creation("fg2-fixture-begin", market.state.revision, "CTR-R1-01", "standard")
assert(begun.ok)
var draft_id := String(market.state.run_creation_draft.draft_id)
var materialized: Dictionary = market.materialize_opening_offers("fg2-fixture-materialize", market.state.revision, draft_id)
assert(materialized.ok)
var offer_ids: Array[String] = []
for offer in market.state.run_creation_draft.opening_offers:
offer_ids.append(String(offer.source_offer_id))
var selected: Dictionary = market.set_opening_selection("fg2-fixture-select", market.state.revision, [offer_ids[0], offer_ids[1]])
assert(selected.ok)
var committed: Dictionary = market.commit_run_creation("fg2-fixture-commit", market.state.revision, draft_id, int(market.state.run_creation_draft.selection_revision), Array(market.state.run_creation_draft.selected_offer_ids).duplicate(), String(market.state.run_creation_draft.opening_offer_set_hash))
assert(committed.ok)
return market
static func _route_id(market, risk: int) -> String:
for offer in market.state.current_run.market_board.battle_offers:
if int(offer.risk) == risk:
return String(offer.offer_id)
return ""