using Cysharp.Threading.Tasks; using Mirror; using QSB.Utility; using QSB.WorldSync; using System.Collections.Generic; using System.Threading; namespace QSB.Syncs.Occasional; internal class OccasionalManager : WorldObjectManager { public override WorldObjectScene WorldObjectScene => WorldObjectScene.SolarSystem; public static readonly List<(OWRigidbody Body, OWRigidbody RefBody)> Bodies = new(); public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct) { var gdBody = Locator._giantsDeep.GetOWRigidbody(); var cannon = Locator._orbitalProbeCannon.GetRequiredComponent(); SpawnOccasional(cannon.GetAttachedOWRigidbody(), gdBody); foreach (var proxy in cannon._realDebrisSectorProxies) { SpawnOccasional(proxy.transform.root.GetAttachedOWRigidbody(), gdBody); } if (cannon._probeBody) { // probe is null on statue scene reload SpawnOccasional(cannon._probeBody, gdBody); } foreach (var island in QSBWorldSync.GetUnityObjects().SortDeterministic()) { SpawnOccasional(island._islandBody, gdBody); } } public static void SpawnOccasional(OWRigidbody body, OWRigidbody refBody) { Bodies.Add((body, refBody)); if (QSBCore.IsHost) { Instantiate(QSBNetworkManager.singleton.OccasionalPrefab).SpawnWithServerAuthority(); } } public override void UnbuildWorldObjects() { if (QSBCore.IsHost) { foreach (var transformSync in QSBWorldSync.GetUnityObjects()) { NetworkServer.Destroy(transformSync.gameObject); } } Bodies.Clear(); } }