class_name P100RuntimeFixture 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") const ContractService = preload("res://p10_0/contract_service.gd") const BossBattleService = preload("res://p10_0/boss_battle_service.gd") static func market_state(contract_id := "CTR-R1-01") -> Dictionary: return _created_market(contract_id).state.snapshot() static func ordinary_battle_state(risk := 0) -> Dictionary: var market = _created_market("CTR-R1-01") _prepare_strong_company(market) var offer_id := _battle_offer_for_risk(market, risk) assert(not offer_id.is_empty()) assert(market.commit_battle_offer("fixture-battle-%d" % risk, market.state.revision, offer_id, String(market.state.current_run.market_board.board_hash)).ok) return market.state.snapshot() static func reward_state(risk := 0) -> Dictionary: var encounter := ordinary_battle_state(risk) var terminal: Dictionary = BattleService.new(encounter).run_to_terminal().snapshot assert(String(terminal.outcome) == "victory") var resolver := ResolutionService.new(encounter) assert(resolver.settle_battle("fixture-reward-%d" % risk, resolver.state.revision, String(terminal.snapshot_hash), terminal).ok) var roundtrip := MarketService.new() assert(roundtrip.restore_snapshot(resolver.state.snapshot())) return resolver.state.snapshot() static func boss_muster_state(contract_id := "CTR-R1-01") -> Dictionary: var market = _boss_ready_market(contract_id, true, false) var contract := ContractService.new(market.state.snapshot()) assert(contract.enter_boss_muster("fixture-muster-%s" % contract_id, contract.state.revision).ok) return contract.state.snapshot() static func boss_battle_state(contract_id := "CTR-R1-01") -> Dictionary: var contract := ContractService.new(boss_muster_state(contract_id)) var plan_id := String(contract.state.current_run.boss_muster.plans[0]) assert(contract.commit_boss_plan("fixture-plan-%s" % contract_id, contract.state.revision, String(contract.state.current_run.boss_muster.muster_hash), plan_id).ok) return contract.state.snapshot() static func recovery_market_state() -> Dictionary: var market = _boss_ready_market("CTR-R1-01", false, true) var contract := ContractService.new(market.state.snapshot()) assert(contract.enter_boss_muster("fixture-recovery-muster", contract.state.revision).ok) var plan_id := String(contract.state.current_run.boss_muster.plans[0]) assert(contract.commit_boss_plan("fixture-recovery-plan", contract.state.revision, String(contract.state.current_run.boss_muster.muster_hash), plan_id).ok) var terminal: Dictionary = BossBattleService.new(contract.state.snapshot()).run_to_terminal().snapshot assert(String(terminal.outcome) == "defeat") assert(contract.settle_boss("fixture-recovery-settle", contract.state.revision, String(terminal.snapshot_hash), terminal).ok) assert(bool(contract.state.current_run.recovery_required)) return contract.state.snapshot() static func contract_result_state(contract_id := "CTR-R1-01") -> Dictionary: var contract := ContractService.new(boss_battle_state(contract_id)) var terminal: Dictionary = BossBattleService.new(contract.state.snapshot()).run_to_terminal().snapshot assert(String(terminal.outcome) == "victory") assert(contract.settle_boss("fixture-boss-settle-%s" % contract_id, contract.state.revision, String(terminal.snapshot_hash), terminal).ok) return contract.state.snapshot() static func first_company_record_state() -> Dictionary: return _close_contract(contract_result_state("CTR-R1-01"), "first") static func rg02_state() -> Dictionary: var first := first_company_record_state() var second = MarketService.new(first) assert(second.begin_run_creation("fixture-second-begin", second.state.revision, "CTR-R1-02", "standard").ok) _finish_run_creation(second, "second") _prepare_boss_market(second, true, false) var second_contract := ContractService.new(second.state.snapshot()) assert(second_contract.enter_boss_muster("fixture-second-muster", second_contract.state.revision).ok) var plan_id := String(second_contract.state.current_run.boss_muster.plans[0]) assert(second_contract.commit_boss_plan("fixture-second-plan", second_contract.state.revision, String(second_contract.state.current_run.boss_muster.muster_hash), plan_id).ok) var terminal: Dictionary = BossBattleService.new(second_contract.state.snapshot()).run_to_terminal().snapshot assert(String(terminal.outcome) == "victory") assert(second_contract.settle_boss("fixture-second-settle", second_contract.state.revision, String(terminal.snapshot_hash), terminal).ok) return _close_contract(second_contract.state.snapshot(), "second") static func _created_market(contract_id: String): var market := MarketService.new() if contract_id == "CTR-R1-02": var unlocked := market.state.snapshot() unlocked.guild_profile.contract_clear_ids = ["CLEAR-RG01-C01"] assert(market.restore_snapshot(unlocked)) assert(market.begin_run_creation("fixture-begin-%s" % contract_id, market.state.revision, contract_id, "standard").ok) _finish_run_creation(market, contract_id) return market static func _finish_run_creation(market, label: String) -> void: var draft_id := String(market.state.run_creation_draft.draft_id) assert(market.materialize_opening_offers("fixture-materialize-%s" % label, market.state.revision, draft_id).ok) var ids: Array[String] = [] for offer in market.state.run_creation_draft.opening_offers: ids.append(String(offer.source_offer_id)) assert(market.set_opening_selection("fixture-select-%s" % label, market.state.revision, [ids[0], ids[1]]).ok) assert(market.commit_run_creation("fixture-commit-%s" % label, 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)).ok) static func _prepare_strong_company(market) -> void: var funded: Dictionary = market.state.snapshot() funded.current_run.coin = 300 assert(market.restore_snapshot(funded)) for index in range(3): var offer: Dictionary = market.state.current_run.market_board.recruit_offers[index] assert(market.hire("fixture-strong-hire-%d" % index, market.state.revision, String(offer.source_offer_id), int(offer.list_price), false).ok) var strong: Dictionary = market.state.snapshot() var deployed: Array = Array(strong.current_run.company).slice(0, int(strong.current_run.line_capacity)) strong.current_run.deployed_recruit_ids = deployed strong.current_run.reserve_recruit_ids = Array(strong.current_run.company).filter(func(recruit_id): return recruit_id not in deployed) strong.current_run.formation_proposal = deployed.duplicate() for recruit_id in strong.current_run.company: strong.current_run.recruit_records[recruit_id].level = 10 strong.current_run.recruit_records[recruit_id].xp = 0 strong.current_run.recruit_records[recruit_id].max_hp = 700 strong.current_run.recruit_records[recruit_id].current_hp = 700 for key in strong.current_run.recruit_records[recruit_id].attribute_rolls: strong.current_run.recruit_records[recruit_id].attribute_rolls[key] = "S" assert(market.restore_snapshot(strong)) static func _boss_ready_market(contract_id: String, strong: bool, fragile_three: bool): var market = _created_market(contract_id) var funded: Dictionary = market.state.snapshot() funded.current_run.coin = 300 assert(market.restore_snapshot(funded)) for index in range(3): var offer: Dictionary = market.state.current_run.market_board.recruit_offers[index] assert(market.hire("fixture-boss-hire-%s-%d" % [contract_id, index], market.state.revision, String(offer.source_offer_id), int(offer.list_price), false).ok) _prepare_boss_market(market, strong, fragile_three) return market static func _prepare_boss_market(market, strong: bool, fragile_three: bool) -> void: var generated: Dictionary = market.generator.market_board(String(market.state.current_run.run_seed), String(market.state.current_run.contract_id), 12, 0) var board: Dictionary = market._priced_board(generated.board) var raw: Dictionary = market.state.snapshot() raw.current_run.cleared_rounds = 12 raw.current_run.market_index = 12 raw.current_run.line_capacity = 10 raw.current_run.market_board = board raw.current_run.refresh_count = 0 raw.current_run.locks = {} raw.current_run.available_recruit_offer_ids = market._offer_ids(board.recruit_offers, "source_offer_id") raw.current_run.available_equipment_offer_ids = market._offer_ids(board.equipment_offers, "offer_id") raw.current_run.available_battle_offer_ids = market._offer_ids(board.battle_offers, "offer_id") var deployed: Array = Array(raw.current_run.company).duplicate() if fragile_three: deployed = deployed.slice(0, 3) raw.current_run.deployed_recruit_ids = deployed raw.current_run.reserve_recruit_ids = Array(raw.current_run.company).filter(func(recruit_id): return recruit_id not in deployed) raw.current_run.formation_proposal = deployed.duplicate() for recruit_id in raw.current_run.company: if strong: raw.current_run.recruit_records[recruit_id].level = 10 raw.current_run.recruit_records[recruit_id].xp = 0 raw.current_run.recruit_records[recruit_id].max_hp = 700 raw.current_run.recruit_records[recruit_id].current_hp = 700 for key in raw.current_run.recruit_records[recruit_id].attribute_rolls: raw.current_run.recruit_records[recruit_id].attribute_rolls[key] = "S" elif recruit_id in deployed: raw.current_run.recruit_records[recruit_id].current_hp = 1 raw.current_run.recruit_records[recruit_id].original_list_price = 22 raw.current_run.recruit_records[recruit_id].coin_price_paid = 18 assert(market.restore_snapshot(raw)) static func _battle_offer_for_risk(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 "" static func _close_contract(result_state: Dictionary, label: String) -> Dictionary: var contract := ContractService.new(result_state) var close_id := String(contract.state.current_run.pending_close.close_id) var closed: Dictionary = contract.close_contract("fixture-close-%s" % label, contract.state.revision, close_id) assert(closed.ok) return contract.state.snapshot()