108 lines
3.0 KiB
C#
Raw Normal View History

2021-04-12 10:37:20 +01:00
using OWML.Common;
2021-06-19 13:22:05 +01:00
using QSB.Player;
using QSB.ShipSync.TransformSync;
2021-04-12 10:37:20 +01:00
using QSB.Utility;
using QSB.WorldSync;
2021-04-16 11:40:13 +01:00
using QuantumUNET;
2021-06-18 16:40:05 +01:00
using System;
2021-06-19 13:22:05 +01:00
using System.Collections.Generic;
2021-04-12 10:37:20 +01:00
using System.Linq;
using UnityEngine;
namespace QSB.ShipSync
{
internal class ShipManager : WorldObjectManager
2021-04-12 10:37:20 +01:00
{
public static ShipManager Instance;
2021-04-13 18:50:15 +01:00
public InteractZone HatchInteractZone;
public HatchController HatchController;
public ShipTractorBeamSwitch ShipTractorBeam;
public ShipCockpitController CockpitController;
public bool HasAuthority
=> ShipTransformSync.LocalInstance.HasAuthority;
2021-04-12 10:37:20 +01: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);
}
2021-06-18 22:38:32 +01:00
2021-04-12 10:37:20 +01:00
_currentFlyer = value;
}
}
2021-04-13 17:25:00 +01:00
2021-06-19 13:22:05 +01:00
private List<PlayerInfo> _playersInShip = new List<PlayerInfo>();
private uint _currentFlyer = uint.MaxValue;
2021-04-13 17:25:00 +01:00
public void Start()
=> Instance = this;
2021-04-13 21:09:26 +01:00
protected override void RebuildWorldObjects(OWScene scene)
{
2021-04-13 21:09:26 +01:00
var shipTransform = GameObject.Find("Ship_Body");
HatchController = shipTransform.GetComponentInChildren<HatchController>();
HatchInteractZone = HatchController.GetComponent<InteractZone>();
ShipTractorBeam = Resources.FindObjectsOfTypeAll<ShipTractorBeamSwitch>().First();
CockpitController = Resources.FindObjectsOfTypeAll<ShipCockpitController>().First();
2021-04-13 17:25:00 +01:00
2021-04-13 18:50:15 +01:00
var sphereShape = HatchController.GetComponent<SphereShape>();
2021-04-13 17:25:00 +01:00
sphereShape.radius = 2.5f;
sphereShape.center = new Vector3(0, 0, 1);
2021-04-16 11:40:13 +01:00
if (QSBCore.IsServer)
{
if (ShipTransformSync.LocalInstance != null)
{
QNetworkServer.Destroy(ShipTransformSync.LocalInstance.gameObject);
}
2021-06-18 22:38:32 +01:00
2021-04-16 11:40:13 +01:00
QNetworkServer.Spawn(Instantiate(QSBNetworkManager.Instance.ShipPrefab));
}
2021-06-18 16:40:05 +01:00
var shipComponents = Resources.FindObjectsOfTypeAll<ShipComponent>();
var electricalComponents = Resources.FindObjectsOfTypeAll<ElectricalComponent>();
var electricalSystems = Resources.FindObjectsOfTypeAll<ElectricalSystem>();
var shipModules = Resources.FindObjectsOfTypeAll<ShipModule>();
var shipHulls = Resources.FindObjectsOfTypeAll<ShipHull>();
DebugLog.DebugWrite("ShipComponents : ");
PrintAll(shipComponents);
DebugLog.DebugWrite("Electrical Components : ");
PrintAll(electricalComponents);
DebugLog.DebugWrite("Electrical Systems : ");
PrintAll(electricalSystems);
DebugLog.DebugWrite("Ship Modules : ");
PrintAll(shipModules);
DebugLog.DebugWrite("Ship Hulls : ");
PrintAll(shipHulls);
}
2021-06-19 13:22:05 +01:00
public void AddPlayerToShip(PlayerInfo player)
{
_playersInShip.Add(player);
}
public void RemovePlayerFromShip(PlayerInfo player)
{
_playersInShip.Remove(player);
}
2021-06-18 16:40:05 +01:00
private void PrintAll(Array array)
{
2021-06-19 11:26:05 +01:00
foreach (var item in array)
2021-06-18 16:40:05 +01:00
{
DebugLog.DebugWrite($" - {(item as MonoBehaviour).name}");
}
2021-04-13 17:25:00 +01:00
}
2021-04-12 10:37:20 +01:00
}
}