2021-03-26 20:56:57 +00:00
|
|
|
|
using OWML.Common;
|
|
|
|
|
using OWML.Utils;
|
|
|
|
|
using QSB.Utility;
|
2021-03-13 19:54:36 +00:00
|
|
|
|
using QSB.WorldSync;
|
2021-03-13 21:21:27 +00:00
|
|
|
|
using System.Linq;
|
2020-08-16 15:15:36 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2020-12-31 12:10:55 +00:00
|
|
|
|
namespace QSB.SectorSync.WorldObjects
|
2020-08-16 15:15:36 +00:00
|
|
|
|
{
|
2020-12-23 22:43:05 +00:00
|
|
|
|
public class QSBSector : WorldObject<Sector>
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2020-12-23 22:43:05 +00:00
|
|
|
|
public Sector.Name Type => AttachedObject.GetName();
|
|
|
|
|
public Transform Transform => AttachedObject.transform;
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public Vector3 Position => Transform.position;
|
2021-03-11 20:02:23 +00:00
|
|
|
|
public bool IsFakeSector => AttachedObject.GetType() == typeof(FakeSector);
|
2020-08-20 18:31:10 +00:00
|
|
|
|
|
2020-12-23 22:43:05 +00:00
|
|
|
|
public override void Init(Sector sector, int id)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
|
|
|
|
ObjectId = id;
|
2020-12-23 22:43:05 +00:00
|
|
|
|
AttachedObject = sector;
|
2021-03-11 20:02:23 +00:00
|
|
|
|
if (IsFakeSector)
|
|
|
|
|
{
|
|
|
|
|
QSBSectorManager.Instance.FakeSectors.Add(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnRemoval()
|
|
|
|
|
{
|
|
|
|
|
if (IsFakeSector)
|
|
|
|
|
{
|
|
|
|
|
QSBSectorManager.Instance.FakeSectors.Remove(this);
|
|
|
|
|
}
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
2021-03-12 21:46:02 +00:00
|
|
|
|
|
|
|
|
|
public bool ShouldSyncTo()
|
|
|
|
|
{
|
2021-03-26 20:56:57 +00:00
|
|
|
|
if (AttachedObject == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Warning - AttachedObject for sector id:{ObjectId} is null!", MessageType.Warning);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-03-12 21:46:02 +00:00
|
|
|
|
if (Type == Sector.Name.Ship)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-03-13 19:54:36 +00:00
|
|
|
|
if (AttachedObject.name == "Sector_Shuttle" || AttachedObject.name == "Sector_NomaiShuttleInterior")
|
2021-03-12 21:46:02 +00:00
|
|
|
|
{
|
2021-03-13 19:54:36 +00:00
|
|
|
|
if (QSBSceneManager.CurrentScene == OWScene.SolarSystem)
|
|
|
|
|
{
|
2021-03-26 20:56:57 +00:00
|
|
|
|
var shuttleController = AttachedObject.gameObject.GetComponentInParent<NomaiShuttleController>();
|
|
|
|
|
if (shuttleController == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Warning - Expected to find a NomaiShuttleController for {AttachedObject.name}!", MessageType.Warning);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!shuttleController.IsPlayerInside())
|
2021-03-13 19:54:36 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse)
|
|
|
|
|
{
|
2021-03-26 20:56:57 +00:00
|
|
|
|
var shuttleController = Resources.FindObjectsOfTypeAll<EyeShuttleController>().First();
|
|
|
|
|
if (shuttleController == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Warning - Expected to find a EyeShuttleController for {AttachedObject.name}!", MessageType.Warning);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!shuttleController.GetValue<bool>("_isPlayerInside"))
|
2021-03-13 19:54:36 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-12 21:46:02 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|