2021-04-12 09:37:20 +00:00
|
|
|
|
using OWML.Common;
|
2021-06-15 17:56:51 +00:00
|
|
|
|
using QSB.Player;
|
|
|
|
|
using QSB.Player.TransformSync;
|
|
|
|
|
using QSB.ShipSync.TransformSync;
|
2021-04-12 09:37:20 +00:00
|
|
|
|
using QSB.Utility;
|
2021-06-15 17:56:51 +00:00
|
|
|
|
using QSB.WorldSync;
|
2021-04-16 10:40:13 +00:00
|
|
|
|
using QuantumUNET;
|
2021-04-12 09:37:20 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace QSB.ShipSync
|
|
|
|
|
{
|
2021-06-15 17:56:51 +00:00
|
|
|
|
internal class ShipManager : WorldObjectManager
|
2021-04-12 09:37:20 +00:00
|
|
|
|
{
|
|
|
|
|
public static ShipManager Instance;
|
|
|
|
|
|
2021-04-13 17:50:15 +00:00
|
|
|
|
public InteractZone HatchInteractZone;
|
|
|
|
|
public HatchController HatchController;
|
|
|
|
|
public ShipTractorBeamSwitch ShipTractorBeam;
|
2021-06-15 17:56:51 +00:00
|
|
|
|
public ShipCockpitController CockpitController;
|
|
|
|
|
public bool HasAuthority
|
|
|
|
|
=> ShipTransformSync.LocalInstance.HasAuthority;
|
2021-04-12 09:37:20 +00:00
|
|
|
|
public uint CurrentFlyer
|
|
|
|
|
{
|
|
|
|
|
get => _currentFlyer;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_currentFlyer != uint.MaxValue && value != uint.MaxValue)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Warning - Trying to set current flyer while someone is still flying? Current:{_currentFlyer}, New:{value}", MessageType.Warning);
|
|
|
|
|
}
|
|
|
|
|
_currentFlyer = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-13 16:25:00 +00:00
|
|
|
|
|
2021-06-15 17:56:51 +00:00
|
|
|
|
private uint _currentFlyer = uint.MaxValue;
|
2021-04-13 16:25:00 +00:00
|
|
|
|
|
2021-06-15 17:56:51 +00:00
|
|
|
|
public void Start()
|
|
|
|
|
=> Instance = this;
|
2021-04-13 20:09:26 +00:00
|
|
|
|
|
2021-06-15 17:56:51 +00:00
|
|
|
|
protected override void RebuildWorldObjects(OWScene scene)
|
|
|
|
|
{
|
2021-04-13 20:09:26 +00:00
|
|
|
|
var shipTransform = GameObject.Find("Ship_Body");
|
|
|
|
|
HatchController = shipTransform.GetComponentInChildren<HatchController>();
|
|
|
|
|
HatchInteractZone = HatchController.GetComponent<InteractZone>();
|
|
|
|
|
ShipTractorBeam = Resources.FindObjectsOfTypeAll<ShipTractorBeamSwitch>().First();
|
2021-06-15 17:56:51 +00:00
|
|
|
|
CockpitController = Resources.FindObjectsOfTypeAll<ShipCockpitController>().First();
|
2021-04-13 16:25:00 +00:00
|
|
|
|
|
2021-04-13 17:50:15 +00:00
|
|
|
|
var sphereShape = HatchController.GetComponent<SphereShape>();
|
2021-04-13 16:25:00 +00:00
|
|
|
|
sphereShape.radius = 2.5f;
|
|
|
|
|
sphereShape.center = new Vector3(0, 0, 1);
|
2021-04-16 10:40:13 +00:00
|
|
|
|
|
|
|
|
|
if (QSBCore.IsServer)
|
|
|
|
|
{
|
2021-06-15 17:56:51 +00:00
|
|
|
|
if (ShipTransformSync.LocalInstance != null)
|
|
|
|
|
{
|
|
|
|
|
QNetworkServer.Destroy(ShipTransformSync.LocalInstance.gameObject);
|
|
|
|
|
}
|
2021-04-16 10:40:13 +00:00
|
|
|
|
QNetworkServer.Spawn(Instantiate(QSBNetworkManager.Instance.ShipPrefab));
|
|
|
|
|
}
|
2021-04-13 16:25:00 +00:00
|
|
|
|
}
|
2021-04-12 09:37:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|