Files
aetherbound-guild/runtime/tests/p9_4/second_cycle_adaptation_domain_test.gd
T

113 lines
4.7 KiB
GDScript

extends SceneTree
const Service = preload("res://p9_3/core_loop_service.gd")
const State = preload("res://p9_3/core_loop_state.gd")
const PATHS := {
"Wayrunner": {
"cost": 10,
"terminal_tick": 99,
"hearthguard_hp": 22,
"role_actions": 9,
"heals": 0,
"coin_after_reward": 22,
"remaining_offer": "Kindhand",
},
"Kindhand": {
"cost": 11,
"terminal_tick": 133,
"hearthguard_hp": 84,
"role_actions": 14,
"heals": 11,
"coin_after_reward": 21,
"remaining_offer": "Wayrunner",
},
}
var failures: Array[String] = []
func _initialize() -> void:
call_deferred("run_test")
func run_test() -> void:
for recruit_id in ["Wayrunner", "Kindhand"]:
verify_path(recruit_id)
if failures.is_empty():
print("ABG_P9_4_SECOND_CYCLE_DOMAIN_OK paths=2 ticks=99,133 hearthguard_hp=22,84 heals=0,11 coin=22,21 company=3/10 receipts_once=true")
quit(0)
else:
for failure in failures:
push_error(failure)
quit(1)
func verify_path(recruit_id: String) -> void:
var expected: Dictionary = PATHS[recruit_id]
var service = complete_first_cycle()
expect(service.state.phase == State.Phase.HALL, "%s starts from returned Hall" % recruit_id)
expect(service.state.coin == 20, "%s starts with 20 Coin" % recruit_id)
expect(service.state.company == ["Hearthguard", "Farstring"], "%s starts from the accepted 2/10 line" % recruit_id)
expect(service.state.available_offers.has(recruit_id), "%s remains a standing offer" % recruit_id)
expect(service.state.reward_receipts.size() == 1, "%s starts after one reward receipt" % recruit_id)
expect(service.focus_offer(recruit_id).ok, "%s focuses directly" % recruit_id)
var hired: Dictionary = service.hire(recruit_id)
expect(hired.ok and hired.code == "hire_committed", "%s hire commits" % recruit_id)
expect(service.state.company == ["Hearthguard", "Farstring", recruit_id], "%s joins the system-owned third position" % recruit_id)
expect(service.state.coin == 20 - int(expected.cost), "%s deducts exact cost" % recruit_id)
expect(service.state.available_offers == [String(expected.remaining_offer)], "%s leaves only the other offer" % recruit_id)
expect(service.state.hire_receipts.size() == 2, "%s creates one additional hire receipt" % recruit_id)
var committed: Dictionary = service.state.snapshot()
var duplicate_hire: Dictionary = service.hire(recruit_id)
expect(not duplicate_hire.ok and service.state.snapshot() == committed, "%s duplicate hire is inert" % recruit_id)
expect(service.select_encounter("crosswind").ok, "%s selects the visible Crosswind threat" % recruit_id)
expect(service.start_battle().ok, "%s starts Crosswind" % recruit_id)
var guard := 0
while service.state.phase == State.Phase.BATTLE and guard < 1000:
service.advance_battle_ticks(1)
guard += 1
expect(service.state.phase == State.Phase.RESULT and service.state.last_outcome == "victory", "%s reaches victory" % recruit_id)
expect(service.battle.state.tick == int(expected.terminal_tick), "%s has the exact terminal tick" % recruit_id)
expect(int(service.battle.state.member_hp.Hearthguard) == int(expected.hearthguard_hp), "%s has the exact Hearthguard consequence" % recruit_id)
var role_actions := 0
var heals := 0
for event in service.battle.state.event_log:
if String(event.get("kind", "")) != "member_action" or String(event.get("source_member_id", "")) != recruit_id:
continue
role_actions += 1
if String(event.get("qualifier_en", "")) == "healing":
heals += 1
expect(role_actions == int(expected.role_actions), "%s exposes exact role-action count" % recruit_id)
expect(heals == int(expected.heals), "%s exposes exact healing count" % recruit_id)
var returned: Dictionary = service.claim_and_return()
expect(returned.ok and service.state.phase == State.Phase.HALL, "%s returns to Hall" % recruit_id)
expect(service.state.coin == int(expected.coin_after_reward), "%s preserves spend plus 12 Coin reward" % recruit_id)
expect(service.state.company == ["Hearthguard", "Farstring", recruit_id], "%s preserves the 3/10 Company" % recruit_id)
expect(service.state.reward_receipts.size() == 2, "%s reward commits once" % recruit_id)
var settled: Dictionary = service.state.snapshot()
var duplicate_reward: Dictionary = service.claim_and_return()
expect(not duplicate_reward.ok and service.state.snapshot() == settled, "%s duplicate reward is inert" % recruit_id)
func complete_first_cycle():
var service = Service.new()
service.enter_hall()
service.focus_offer("Farstring")
service.hire("Farstring")
service.select_encounter("open_road")
service.start_battle()
while service.state.phase == State.Phase.BATTLE:
service.advance_battle_ticks(1)
service.claim_and_return()
return service
func expect(condition: bool, message: String) -> void:
if not condition:
failures.append("P9.4 second-cycle adaptation: %s" % message)