# net_world_main_switch_test —— 40250 CNetworkActorManager::SetMainActorVID # 的主角色切换边界:旧 live actor、目标、悬停、HP/动作临时状态不能跨 VID 残留。 extends SceneTree const NetWorld = preload("res://net_world.gd") const FakeClient = preload("res://net_client_fake.gd") var _fail := 0 func _ck(ok: bool, message: String) -> void: if not ok: _fail += 1 printerr("FAIL: " + message) func _init() -> void: await _run() if _fail == 0: print("PASS: net_world_main_switch_test (SetMainActorVID cleanup)") quit(0) else: printerr("%d check(s) failed" % _fail) quit(1) func _run() -> void: var mount := Node3D.new() var client := FakeClient.new() var world: Node = NetWorld.new() get_root().add_child(mount) get_root().add_child(client) get_root().add_child(world) world.setup(client, mount) world.set_model_factory(func(_d: Dictionary) -> Node3D: return Node3D.new()) client.entities[1000] = {"vid": 1000, "name": "old-main", "race": 0, "kind": 0, "ch_type": 0, "pos": Vector3.ZERO, "pos_cm": Vector3.ZERO, "hp": 100, "max_hp": 100, "dead": false} client.entities[2000] = {"vid": 2000, "name": "old-remote", "race": 101, "kind": 2, "ch_type": 2, "pos": Vector3(1, 0, 0), "pos_cm": Vector3(100, 0, 0), "hp": 100, "max_hp": 100, "dead": false} client.main = 1000 world._main_vid = 1000 world._on_spawn(client.entities[2000]) _ck(world.node_for(2000) != null, "old main lifecycle has a visible remote actor") world.set_target_vid(2000) world.set_hover_vid(2000) world._sync_push[2000] = {"serial": 1} world._push[2000] = {"offset": Vector2.ONE} world._damage_queue.append({"vid": 2000, "amount": 1}) world._chat_tails[2000] = {"text": "old", "name_flag": false} world._on_main_set(3000) _ck(world._main_vid == 3000, "new main VID is registered") _ck(world._by_vid.is_empty(), "main switch clears old live actor nodes") _ck(world._target_vid == 0 and world._hover_vid == 0, "main switch clears target and hover references") _ck(world._sync_push.is_empty() and world._push.is_empty() and world._damage_queue.is_empty() and world._chat_tails.is_empty(), "main switch clears transient actor presentation state") world.free() client.free() mount.free() await process_frame