extends SceneTree var checks := 0 var failures := 0 func expect(ok: bool, message: String) -> void: checks += 1 if not ok: failures += 1; push_error(message) func _initialize() -> void: call_deferred("run") func run() -> void: var runtime: Variant = load("res://autoload/simulation_runtime.gd").new() var clock: Variant = load("res://autoload/game_clock.gd").new() var state: Variant = load("res://autoload/game_state.gd").new() clock.reset(1,6,0); state.reset(); runtime.initialize(clock,state,42602); clock.set_paused(true) for row: Array in [[&"reception",Vector3i(-6,0,0)],[&"warehouse",Vector3i(-6,0,1)],[&"premium_room",Vector3i(-6,2,0)],[&"warehouse",Vector3i(-6,2,1)],[&"service_stairs",Vector3i(-7,1,1)],[&"service_stairs",Vector3i(-7,2,1)]]: var built: CommandResult = runtime.submit_command(&"build_facility",{&"definition_id":row[0],&"origin":row[1]}) expect(built.is_success(), "build floor-effect fixture %s: %s" % [row[0],built.message]) if not built.is_success(): runtime.free();clock.free();state.free();quit(failures);return clock.advance_minutes(runtime.definition_registry.get_facility(row[0]).build_minutes) var room: FacilityInstance var workplace: FacilityInstance for facility: FacilityInstance in runtime.facility_service.get_instances(): if facility.definition_id == &"premium_room": room=facility if facility.definition_id == &"warehouse" and facility.origin.y==2: workplace=facility expect(runtime.submit_command(&"hire_staff_candidate",{&"candidate_id":&"heroine_anri"}).is_success(), "recruit canonical free Anri") var assigned: CommandResult=runtime.submit_command(&"set_staff_work_assignment",{&"staff_id":&"heroine_anri",&"facility_id":workplace.instance_id,&"template_id":&"DAY"}) expect(assigned.is_success(), "manager placement uses real capacity and accessible path: %s" % assigned.message) expect(runtime.get_floor_price_multiplier(2)==12000 and runtime.get_floor_price_multiplier(0)==10000, "placement affects only assigned floor across layers") expect(runtime.get_facility_business_price(room)==264, "premium room on opposite layer quotes 220 plus20 percent") clock.advance_minutes(20) expect(workplace.active_staff_ids.is_empty(), "manager placement does not impersonate required warehouse porters") var rows: Array=runtime.get_business_management_report()[&"facilities"] for row: Dictionary in rows: if row[&"facility_id"]==room.instance_id: expect(row[&"price"]==264 and row[&"floor_price_multiplier_bp"]==12000, "business UI report matches charged price") expect(runtime.submit_command(&"register_guest_wallet",{&"guest_id":&"anri_payer",&"gold":1000}).is_success(), "fund controlled service wallet") expect(runtime.submit_command(&"create_service_request",{&"request_id":&"anri_stay",&"facility_id":room.instance_id,&"guest_ids":[&"anri_payer"],&"service_type":&"lodging"}).is_success(), "normal request captures floor-adjusted price") clock.advance_one_minute() var active: Array=runtime.facility_service.get_active_services(room.instance_id) expect(active.size()==1 and active[0].price_snapshot==264, "started stay freezes approved guest price") if active.is_empty(): runtime.free();clock.free();state.free();quit(failures);return var service_id: StringName=active[0].service_id var saved: Dictionary=runtime.create_snapshot() expect(runtime.restore_snapshot(saved), "save restores unique placement and frozen service together") expect(runtime.get_floor_price_multiplier(2)==12000, "restored placement derives multiplier without stacking") expect(runtime.submit_command(&"set_staff_work_assignment",{&"staff_id":&"heroine_anri",&"facility_id":&"",&"template_id":&"DAY"}).is_success(), "unassign manager while guest stay continues") expect(runtime.get_floor_price_multiplier(2)==10000 and runtime.get_facility_business_price(runtime.facility_service.get_instance(room.instance_id))==220, "new prices revert after unassignment") clock.advance_minutes(721) expect(runtime.facility_service.get_service(service_id).state==ServiceInstance.State.COMPLETED, "frozen-price service completes normally") expect(runtime.economy_service.get_balance(&"GUEST_WALLET:anri_payer")==736, "customer pays exactly264 once despite later unassignment") var revenue:=0 for entry: LedgerEntry in runtime.economy_service.get_entries(): if entry.source_entity_id==room.instance_id and entry.category==&"SERVICE_SALE": revenue+=entry.amount expect(revenue==264 and runtime.economy_service.validate_ledger()[&"ok"], "facility receives exactly the customer's payment") autonomous_flow(runtime,clock,room.instance_id,workplace.instance_id) placement_boundaries(runtime,room.instance_id,workplace.instance_id) runtime.free();clock.free();state.free() print("Anri floor pricing: %d checks, %d failures" % [checks,failures]);quit(failures) func autonomous_flow(runtime: Variant, clock: Variant, room_id: StringName, workplace_id: StringName) -> void: for floor_y in [1,2]: var built: CommandResult=runtime.submit_command(&"build_facility",{&"definition_id":&"guest_stairs",&"origin":Vector3i(-7,floor_y,0)}) expect(built.is_success(), "build public stairs for autonomous guest") if not built.is_success(): return clock.advance_minutes(runtime.definition_registry.get_facility(&"guest_stairs").build_minutes) expect(runtime.submit_command(&"set_staff_work_assignment",{&"staff_id":&"heroine_anri",&"facility_id":workplace_id,&"template_id":&"DAY"}).is_success(), "reassign manager for autonomous guest flow") expect(runtime.submit_command(&"spawn_guest",{&"guest_id":&"anri_walker",&"guest_type_id":&"traveler",&"gold":1000, &"options":{&"current_cell":Vector3i(-7,0,0),&"state":GuestRuntime.State.DECIDING,&"planned_exit_at":clock.absolute_minute+2000, &"needs":{&"sleep":100,&"hunger":0,&"hygiene":0,&"medical":0,&"leisure":0,&"intimacy":0}}}).is_success(), "spawn guest without forcing destination, route or price") var selected := false var moving_save: Dictionary={} var service_id: StringName=&"" for minute in 40: clock.advance_one_minute() var guest: GuestRuntime=runtime.guest_service.get_guest(&"anri_walker") if guest==null: break selected=selected or guest.target_facility_id==room_id if guest.current_cell==Vector3i(-7,1,0) and moving_save.is_empty(): moving_save=runtime.create_snapshot() if not guest.current_service_id.is_empty(): service_id=guest.current_service_id;break expect(selected, "autonomous needs select Anri-adjusted premium lodging") expect(not moving_save.is_empty(), "guest physically traverses public stairs") expect(not service_id.is_empty(), "arrival automatically starts service") if service_id.is_empty() or moving_save.is_empty(): return var started: Dictionary=runtime.create_snapshot() expect(runtime.facility_service.get_service(service_id).price_snapshot==264, "autonomous service freezes same 264G price as management quote") expect(runtime.restore_snapshot(moving_save), "restore guest movement and Anri assignment together") for minute in 40: clock.advance_one_minute() if not runtime.guest_service.get_guest(&"anri_walker").current_service_id.is_empty(): break expect(runtime.create_snapshot()==started, "movement save replay reproduces adjusted service exactly") for minute in 721: clock.advance_one_minute() if runtime.facility_service.get_service(service_id).state==ServiceInstance.State.COMPLETED: break expect(runtime.facility_service.get_service(service_id).state==ServiceInstance.State.COMPLETED, "autonomous adjusted stay completes") expect(runtime.economy_service.get_balance(&"GUEST_WALLET:anri_walker")==736, "autonomous guest pays exactly264G once") var revenue:=0 for entry: LedgerEntry in runtime.economy_service.get_entries(): if entry.source_entity_id==room_id and entry.category==&"SERVICE_SALE": revenue+=entry.amount expect(revenue==528 and runtime.economy_service.validate_ledger()[&"ok"], "both264G payments equal facility revenue with balanced ledger") expect(runtime.restore_snapshot(runtime.create_snapshot()), "completed autonomous guest and adjusted ledger remain saveable") func placement_boundaries(runtime: Variant, room_id: StringName, upper_workplace_id: StringName) -> void: var ground_id: StringName=&"" for facility: FacilityInstance in runtime.facility_service.get_instances(): if facility.definition_id==&"warehouse" and facility.origin.y==0: ground_id=facility.instance_id var transfer: CommandResult=runtime.submit_command(&"set_staff_work_assignment",{&"staff_id":&"heroine_anri",&"facility_id":ground_id,&"template_id":&"NIGHT"}) expect(transfer.is_success(), "move manager to another floor with night shift") expect(runtime.get_floor_price_multiplier(0)==12000 and runtime.get_floor_price_multiplier(2)==10000, "floor transfer removes old bonus and applies new bonus exactly once") expect(runtime.get_facility_business_price(runtime.facility_service.get_instance(room_id))==220, "old floor quotes base lodging price after transfer") var assigned: Dictionary=runtime.staff_service.create_snapshot() var rejected: CommandResult=runtime.submit_command(&"set_staff_work_assignment",{&"staff_id":&"heroine_anri",&"facility_id":room_id,&"template_id":&"NIGHT"}) expect(not rejected.is_success() and rejected.details.get(&"reason")==&"FACILITY_UNSTAFFED", "manager cannot bypass zero staff capacity") expect(runtime.staff_service.create_snapshot()==assigned and runtime.get_floor_price_multiplier(0)==12000, "rejected placement preserves schedule and active floor bonus") var demolition: CommandResult=runtime.submit_command(&"demolish_facility",{&"instance_id":ground_id}) expect(not demolition.is_success() and demolition.details.get(&"reason")==&"STAFF_ASSIGNED", "assigned manager prevents workplace demolition") expect(runtime.facility_service.get_instance(ground_id)!=null and runtime.get_floor_price_multiplier(0)==12000, "failed demolition preserves workplace and bonus") var saved: Dictionary=runtime.create_snapshot() for repetition in 3: expect(runtime.restore_snapshot(saved) and runtime.create_snapshot()==saved and runtime.get_floor_price_multiplier(0)==12000 and runtime.get_floor_price_multiplier(2)==10000, "repeated night-assignment load preserves exact state without stacking") expect(runtime.submit_command(&"set_staff_work_assignment",{&"staff_id":&"heroine_anri",&"facility_id":upper_workplace_id,&"template_id":&"DAY"}).is_success(), "return manager to original floor") expect(runtime.get_floor_price_multiplier(0)==10000 and runtime.get_facility_business_price(runtime.facility_service.get_instance(room_id))==264, "return transfer restores only original floor bonus")