feat(m79-b): contract advancement opens region two with its band, boss, battlefield and music

This commit is contained in:
2026-09-15 06:59:21 +08:00
parent d47f96ce96
commit af712a63cd
11 changed files with 301 additions and 27 deletions
+148
View File
@@ -0,0 +1,148 @@
extends SceneTree
## M79-B gate: Contracts advance by ordinal, so the second region becomes
## reachable. Contract 1 and 2 are region one; contract 3 opens Siltwake Fens
## with its own equipment band, enemy pool and boss anchor.
const DraftService = preload("res://entry/initial_company_draft_service.gd")
const ContractService = preload("res://entry/guild_contract_service.gd")
const ContentRegistry = preload("res://p10_0/content_registry.gd")
const COMPANY_PATH := "user://aetherbound_region_advance_company.json"
const DRAFT_PATH := "user://aetherbound_region_advance_draft.json"
const OP_CREATE_1 := "11111111111111111111111111111111"
const OP_RETURN_1 := "22222222222222222222222222222222"
const OP_CREATE_2 := "33333333333333333333333333333333"
const OP_RETURN_2 := "44444444444444444444444444444444"
const OP_CREATE_3 := "55555555555555555555555555555555"
var failures: Array[String] = []
func _initialize() -> void:
call_deferred("_run")
func _run() -> void:
_cleanup()
var company := _create_company()
if company.is_empty():
push_error("region advance: company creation failed")
quit(1)
return
expect(String(company.active_contract.region_id) == "RG-01", "first contract opens region one")
expect(_equipment_band(company) == "EQ-001..EQ-040", "region one market draws EQ-001..EQ-040")
expect(int(company.active_contract.region_index) == 1, "region index starts at one")
var returned_1: Dictionary = _service().return_contract(OP_RETURN_1)
if not returned_1.ok:
push_error("region advance: contract one return failed: %s" % String(returned_1.get("code", "")))
quit(1)
return
var created_2: Dictionary = _service().create_contract(OP_CREATE_2, "CTR-R1-02", "standard")
if not created_2.ok:
push_error("region advance: second contract failed: %s" % String(created_2.get("code", "")))
quit(1)
return
expect(String(created_2.company.active_contract.region_id) == "RG-01", "second contract stays in region one")
expect(_equipment_band(created_2.company) == "EQ-001..EQ-040", "region one market band holds for contract two")
var returned_2: Dictionary = _service().return_contract(OP_RETURN_2)
if not returned_2.ok:
push_error("region advance: contract two return failed: %s" % String(returned_2.get("code", "")))
quit(1)
return
var created_3: Dictionary = _service().create_contract(OP_CREATE_3, "CTR-R2-01", "standard")
if not created_3.ok:
push_error("region advance: third contract failed: %s" % String(created_3.get("code", "")))
quit(1)
return
var contract: Dictionary = created_3.company.active_contract
expect(String(contract.region_id) == "RG-02", "third contract opens region two, got %s" % String(contract.region_id))
expect(int(contract.region_index) == 2, "region index advances to two")
expect(String(contract.boss_id) == "BO-R2-01", "region two contract anchors its first boss")
expect(_equipment_band(created_3.company) == "EQ-041..EQ-080", "region two market draws EQ-041..EQ-080")
var enemy_ids: Array[String] = []
for offer in Array(contract.market_board.battle_offers):
for enemy_id in Array(Dictionary(offer).get("enemy_ids", [])):
enemy_ids.append(String(enemy_id))
var off_region: Array[String] = []
for enemy_id in enemy_ids:
if not enemy_id.begins_with("EN-R2-") and not enemy_id.begins_with("BO-R2-"):
off_region.append(enemy_id)
expect(off_region.is_empty(), "region two battles field only region two identities, leaked %s" % str(off_region))
var boss_offer: Dictionary = Dictionary(Array(contract.market_board.battle_offers)[2])
expect(Array(boss_offer.get("enemy_ids", [])).has("BO-R2-01"), "highest-risk offer anchors the contract boss")
var content: Dictionary = ContentRegistry.snapshot()
expect(ContentRegistry.localized_name(content, "RG-02", "zh_CN") == "淤醒沼泽", "region two zh authority resolves")
expect(ContentRegistry.localized_name(content, "RG-02", "en") == "Siltwake Fens", "region two en authority resolves")
_cleanup()
if failures.is_empty():
print("ABG_M79_REGION_ADVANCE_OK contracts=3 region=RG-02 equipment=%s enemies=%d boss=%s" % [
_equipment_band(created_3.company), enemy_ids.size(), String(contract.boss_id)])
quit(0)
return
for failure in failures:
push_error("M79-B region advance: %s" % failure)
quit(1)
func _equipment_band(company: Dictionary) -> String:
# The market draws four identities from the region band; the gate checks that
# every drawn identity stays inside the band rather than the band's extremes.
var ids: Array[String] = []
for offer in Array(Dictionary(company.get("active_contract", {})).get("market_board", {}).get("equipment_offers", [])):
ids.append(String(Dictionary(offer).get("catalog_id", "")))
if ids.is_empty():
return "none"
var low := 9999
var high := 0
for catalog_id in ids:
var ordinal := int(catalog_id.split("-")[1])
low = mini(low, ordinal)
high = maxi(high, ordinal)
var expected_low := 1 + (int(Dictionary(company.get("active_contract", {})).get("region_index", 1)) - 1) * 40
var expected_high := expected_low + 39
if low >= expected_low and high <= expected_high:
return "EQ-%03d..EQ-%03d" % [expected_low, expected_high]
return "out_of_band:%d..%d" % [low, high]
func _create_company() -> Dictionary:
var draft: Dictionary = _draft_service().begin_or_load("abcdef0123456789abcdef0123456789")
if not draft.ok:
return {}
var selected := [String(draft.draft.offers[0].offer_id), String(draft.draft.offers[1].offer_id)]
if not _draft_service().set_selection(selected).ok:
return {}
if not _draft_service().commit_company().ok:
return {}
var created: Dictionary = _service().create_contract(OP_CREATE_1, "CTR-R1-01", "standard")
return created.company if created.ok else {}
func _service() -> RefCounted:
var service := ContractService.new()
service.company_path = COMPANY_PATH
return service
func _draft_service() -> RefCounted:
var service := DraftService.new()
service.path = DRAFT_PATH
service.company_path = COMPANY_PATH
return service
func _cleanup() -> void:
for path in [COMPANY_PATH, DRAFT_PATH, "%s.bak" % COMPANY_PATH, "%s.candidate" % COMPANY_PATH]:
if FileAccess.file_exists(path):
DirAccess.remove_absolute(ProjectSettings.globalize_path(path))
func expect(condition: bool, message: String) -> void:
if not condition:
failures.append(message)