quantum-space-buddies/QSB/Syncs/Occasional/OccasionalManager.cs

64 lines
1.6 KiB
C#
Raw Normal View History

2022-02-01 09:05:37 +00:00
using Cysharp.Threading.Tasks;
using Mirror;
using QSB.Utility;
using QSB.Utility.Deterministic;
2022-02-01 09:05:37 +00:00
using QSB.WorldSync;
using System.Collections.Generic;
2022-12-12 22:08:42 +00:00
using System.Linq;
2022-02-01 09:05:37 +00:00
using System.Threading;
2022-03-03 03:46:33 +00:00
namespace QSB.Syncs.Occasional;
2022-02-01 09:05:37 +00:00
2023-07-28 18:30:57 +00:00
public class OccasionalManager : WorldObjectManager
2022-03-03 03:46:33 +00:00
{
public override WorldObjectScene WorldObjectScene => WorldObjectScene.SolarSystem;
2022-02-01 09:05:37 +00:00
2022-03-03 03:46:33 +00:00
public static readonly List<(OWRigidbody Body, OWRigidbody RefBody)> Bodies = new();
2022-02-01 09:05:37 +00:00
2022-03-03 03:46:33 +00:00
public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct)
{
var gdBody = Locator._giantsDeep.GetOWRigidbody();
var cannon = Locator._orbitalProbeCannon.GetRequiredComponent<OrbitalProbeLaunchController>();
2022-10-06 21:45:40 +00:00
SpawnOccasional(cannon.GetAttachedOWRigidbody(), gdBody);
2022-02-01 09:05:37 +00:00
2022-03-03 03:46:33 +00:00
foreach (var proxy in cannon._realDebrisSectorProxies)
{
SpawnOccasional(proxy.transform.root.GetAttachedOWRigidbody(), gdBody);
}
2022-03-03 03:46:33 +00:00
if (cannon._probeBody)
{
// probe is null on statue scene reload
SpawnOccasional(cannon._probeBody, gdBody);
2022-02-01 09:05:37 +00:00
}
2022-03-03 03:46:33 +00:00
foreach (var island in QSBWorldSync.GetUnityObjects<IslandController>().SortDeterministic())
2022-02-01 09:05:37 +00:00
{
2022-03-03 03:46:33 +00:00
SpawnOccasional(island._islandBody, gdBody);
}
}
2022-03-03 03:46:33 +00:00
public static void SpawnOccasional(OWRigidbody body, OWRigidbody refBody)
{
Bodies.Add((body, refBody));
if (QSBCore.IsHost)
{
Instantiate(QSBNetworkManager.singleton.OccasionalPrefab).SpawnWithServerOwnership();
2022-02-01 09:05:37 +00:00
}
2022-03-03 03:46:33 +00:00
}
2022-03-03 03:46:33 +00:00
public override void UnbuildWorldObjects()
{
if (QSBCore.IsHost)
{
2022-12-12 22:08:42 +00:00
foreach (var transformSync in OccasionalTransformSync.Instances.ToList())
{
2022-03-03 03:46:33 +00:00
NetworkServer.Destroy(transformSync.gameObject);
}
}
2022-03-03 03:46:33 +00:00
Bodies.Clear();
2022-02-01 09:05:37 +00:00
}
2022-08-30 04:37:30 +00:00
}