198 lines
6.9 KiB
GDScript
198 lines
6.9 KiB
GDScript
class_name P103DeepChannelsFixture
|
|
extends RefCounted
|
|
|
|
const P102Fixture = preload("res://tests/p10_2/mid_contract_fixture.gd")
|
|
const SaveV8 = preload("res://p10_2/save_v8_service.gd")
|
|
const BattleService = preload("res://p10_3/deep_channels_battle_service.gd")
|
|
const BoardService = preload("res://p10_3/market_board_service.gd")
|
|
const GrowthService = preload("res://p10_3/growth_service.gd")
|
|
const PreparationService = preload("res://p10_3/deep_channels_preparation_service.gd")
|
|
const ResolutionService = preload("res://p10_3/deep_channels_resolution_service.gd")
|
|
const SaveV9 = preload("res://p10_3/save_v9_service.gd")
|
|
const State = preload("res://p10_3/run_state.gd")
|
|
|
|
|
|
func p102_market_5_snapshot() -> Dictionary:
|
|
var service = P102Fixture.new().market_service_at(5)
|
|
return service.state.snapshot() if service != null else {}
|
|
|
|
|
|
func encoded_v8(sequence: int = 20) -> Dictionary:
|
|
return SaveV8.new().encode_snapshot(p102_market_5_snapshot(), sequence)
|
|
|
|
|
|
func migrated_snapshot(sequence: int = 20) -> Dictionary:
|
|
var source := encoded_v8(sequence)
|
|
if not source.ok:
|
|
return {}
|
|
var migrated := SaveV9.new().migrate_v8_text(String(source.text), sequence)
|
|
return migrated.snapshot if migrated.ok else {}
|
|
|
|
|
|
func market_7_snapshot(eligible: bool = true) -> Dictionary:
|
|
var raw := migrated_snapshot()
|
|
if raw.is_empty():
|
|
return {}
|
|
var generated := BoardService.new().generate(String(raw.current_run.run_seed), 7, 0)
|
|
if not generated.ok:
|
|
return {}
|
|
var run: Dictionary = raw.current_run
|
|
run.phase = "market"
|
|
run.market_index = 7
|
|
run.round_index = 7
|
|
run.cleared_rounds = 6
|
|
run.line_capacity = 7
|
|
run.refresh_count = 0
|
|
run.market_board = Dictionary(generated.board).duplicate(true)
|
|
run.available_recruit_offer_ids = _offer_ids(generated.board.recruit_offers, "source_offer_id")
|
|
run.available_equipment_offer_ids = _offer_ids(generated.board.equipment_offers, "offer_id")
|
|
run.available_battle_offer_ids = _offer_ids(generated.board.battle_offers, "offer_id")
|
|
run.locked_offer_ids = []
|
|
run.selected_route_id = ""
|
|
run.pending_encounter = {}
|
|
run.pre_battle_checkpoint_id = ""
|
|
run.recovery_required = false
|
|
run.recovery_cost = 0
|
|
for round_index in [5, 6]:
|
|
run.route_history.append({
|
|
"round_index": round_index,
|
|
"route_id": "RO-R2-M%02d-Q0" % round_index,
|
|
"plan_id": "fixture_only",
|
|
"outcome": "victory",
|
|
"battle_hash": "%s|%d" % [run.run_seed, round_index],
|
|
"reward_coin": 18 + 2 * round_index + 2,
|
|
})
|
|
run.artifact_draft = GrowthService.artifact_draft_for(String(run.run_seed))
|
|
run.active_artifact_ids = []
|
|
run.artifact_rule_state = {}
|
|
run.promotion_draft = {}
|
|
var candidate_id := ""
|
|
for recruit_id in run.company:
|
|
var record: Dictionary = run.recruit_records[recruit_id]
|
|
record.level = mini(int(record.level), 3)
|
|
record.survived_battles = mini(int(record.survived_battles), 2)
|
|
if String(record.profession_id) == "PF-B07" and candidate_id.is_empty():
|
|
candidate_id = String(recruit_id)
|
|
run.recruit_records[recruit_id] = record
|
|
if eligible:
|
|
if candidate_id.is_empty():
|
|
return {}
|
|
var candidate: Dictionary = run.recruit_records[candidate_id]
|
|
candidate.level = 4
|
|
candidate.xp = 8
|
|
candidate.survived_battles = 3
|
|
candidate.current_hp = maxi(1, int(floor(float(candidate.max_hp) * 0.5)))
|
|
candidate.custom_history_probe = ["round-1", "round-3", "round-6"]
|
|
run.recruit_records[candidate_id] = candidate
|
|
raw.current_run = run
|
|
var probe := State.new()
|
|
return probe.snapshot() if probe.restore_snapshot(raw) else {}
|
|
|
|
|
|
func growth_service(eligible: bool = true):
|
|
var snapshot_value := market_7_snapshot(eligible)
|
|
return GrowthService.new(snapshot_value) if not snapshot_value.is_empty() else null
|
|
|
|
|
|
func progressed_market_snapshot(market_index: int) -> Dictionary:
|
|
if market_index < 5 or market_index > 7:
|
|
return {}
|
|
var snapshot_value := migrated_snapshot()
|
|
while not snapshot_value.is_empty() and int(snapshot_value.current_run.market_index) < market_index:
|
|
var run: Dictionary = snapshot_value.current_run
|
|
var route: Dictionary = run.market_board.battle_offers[0]
|
|
var preparation := PreparationService.new(snapshot_value)
|
|
var prepared := preparation.commit_route(
|
|
"fixture-progress-route-%d" % int(run.market_index),
|
|
preparation.state.revision,
|
|
String(route.offer_id),
|
|
String(run.market_board.board_hash)
|
|
)
|
|
if not prepared.ok:
|
|
return {}
|
|
var plan_id := preferred_plan(String(route.route_id))
|
|
var battle := BattleService.new(preparation.state.snapshot()).run_to_terminal(plan_id)
|
|
if not battle.ok or String(battle.snapshot.outcome) != "victory":
|
|
return {}
|
|
var resolution := ResolutionService.new(preparation.state.snapshot())
|
|
var settled := resolution.settle(
|
|
"fixture-progress-settle-%d" % int(route.round_index),
|
|
resolution.state.revision,
|
|
battle.snapshot
|
|
)
|
|
if not settled.ok:
|
|
return {}
|
|
snapshot_value = resolution.state.snapshot()
|
|
return snapshot_value
|
|
|
|
|
|
func prepared_service(
|
|
market_index: int,
|
|
risk: int,
|
|
artifact_id: String = "",
|
|
promotion_id: String = "",
|
|
force_eligible: bool = false
|
|
):
|
|
if market_index < 5 or market_index > 7 or risk < 0 or risk > 2:
|
|
return null
|
|
var snapshot_value := (
|
|
market_7_snapshot(true)
|
|
if market_index == 7 and force_eligible
|
|
else progressed_market_snapshot(market_index)
|
|
)
|
|
if snapshot_value.is_empty():
|
|
return null
|
|
if market_index == 7:
|
|
var selected_artifact := artifact_id
|
|
if selected_artifact.is_empty():
|
|
selected_artifact = ["AR-015", "AR-011", "AR-012"][risk]
|
|
var growth := GrowthService.new(snapshot_value)
|
|
var artifact_hash := String(growth.state.current_run.artifact_draft.draft_hash)
|
|
var selected := growth.select_artifact(
|
|
"fixture-artifact-%s-%d" % [selected_artifact, risk],
|
|
growth.state.revision,
|
|
artifact_hash,
|
|
selected_artifact
|
|
)
|
|
if not selected.ok:
|
|
return null
|
|
if not promotion_id.is_empty():
|
|
var opened := growth.open_promotion_draft(
|
|
"fixture-promotion-open-%s" % promotion_id,
|
|
growth.state.revision
|
|
)
|
|
if not opened.ok:
|
|
return null
|
|
var draft: Dictionary = opened.receipt.draft
|
|
var promoted := growth.confirm_promotion(
|
|
"fixture-promotion-%s" % promotion_id,
|
|
growth.state.revision,
|
|
String(draft.draft_hash),
|
|
String(draft.recruit_id),
|
|
String(draft.current_profession_id),
|
|
promotion_id
|
|
)
|
|
if not promoted.ok:
|
|
return null
|
|
snapshot_value = growth.state.snapshot()
|
|
var preparation := PreparationService.new(snapshot_value)
|
|
var route: Dictionary = preparation.state.current_run.market_board.battle_offers[risk]
|
|
var prepared := preparation.commit_route(
|
|
"fixture-target-route-%d-%d-%s-%s" % [market_index, risk, artifact_id, promotion_id],
|
|
preparation.state.revision,
|
|
String(route.offer_id),
|
|
String(preparation.state.current_run.market_board.board_hash)
|
|
)
|
|
return preparation if prepared.ok else null
|
|
|
|
|
|
func preferred_plan(route_id: String) -> String:
|
|
return String(BattleService.PREFERRED_PLAN.get(route_id, ""))
|
|
|
|
|
|
func _offer_ids(offers: Array, field: String) -> Array[String]:
|
|
var result: Array[String] = []
|
|
for offer in offers:
|
|
result.append(String(offer.get(field, "")))
|
|
return result
|