2022-01-28 20:49:07 -08:00
using Cysharp.Threading.Tasks ;
using OWML.Common ;
2021-03-26 20:56:57 +00:00
using QSB.Utility ;
2021-03-13 19:54:36 +00:00
using QSB.WorldSync ;
2021-10-25 10:42:25 +01:00
using System ;
2021-03-13 21:21:27 +00:00
using System.Linq ;
2022-01-28 20:49:07 -08:00
using System.Threading ;
2020-08-16 17:15:36 +02:00
using UnityEngine ;
2020-12-31 12:10:55 +00:00
namespace QSB.SectorSync.WorldObjects
2020-08-16 17:15:36 +02: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 ( ) ;
2021-10-25 10:42:25 +01:00
public Transform Transform
{
get
{
if ( AttachedObject = = null )
{
DebugLog . ToConsole ( $"Error - Tried to get Transform from QSBSector {ObjectId} with null AttachedObject!\r\n{Environment.StackTrace}" , MessageType . Error ) ;
return null ;
}
return AttachedObject . transform ;
}
}
2020-12-02 21:23:01 +00:00
public Vector3 Position = > Transform . position ;
2022-02-15 21:54:12 -08:00
2021-12-18 12:08:26 -08:00
public bool IsFakeSector = > AttachedObject is FakeSector ;
public FakeSector FakeSector = > ( FakeSector ) AttachedObject ;
2020-08-20 19:31:10 +01:00
2022-01-28 20:50:34 -08:00
public override async UniTask Init ( CancellationToken ct )
2020-12-02 21:23:01 +00:00
{
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
2022-01-25 23:40:38 -08:00
public override void SendInitialState ( uint to ) { }
2022-01-25 21:08:04 -08:00
2022-02-15 21:54:12 -08:00
public bool ShouldSyncTo ( DynamicOccupant occupantType )
2021-03-12 21:46:02 +00:00
{
2021-03-31 15:43:55 +01:00
if ( AttachedObject = = null )
2021-03-31 15:16:03 +01:00
{
2021-03-31 15:43:55 +01:00
DebugLog . ToConsole ( $"Warning - AttachedObject for sector id:{ObjectId} is null!" , MessageType . Warning ) ;
2021-03-31 15:16:03 +01:00
return false ;
}
2021-03-31 15:43:55 +01:00
if ( ! AttachedObject . gameObject . activeInHierarchy )
2021-03-26 20:56:57 +00:00
{
return false ;
}
2021-03-31 15:43:55 +01:00
2022-02-15 21:54:12 -08:00
if ( occupantType = = DynamicOccupant . Ship & & Type = = Sector . Name . Ship )
2021-03-12 21:46:02 +00:00
{
return false ;
}
2021-04-20 08:36:07 +01:00
2021-11-20 19:49:50 +00:00
if ( AttachedObject . name is "Sector_Shuttle" or "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 ;
}
2021-06-18 22:38:32 +01:00
2021-03-26 20:56:57 +00:00
if ( ! shuttleController . IsPlayerInside ( ) )
2021-03-13 19:54:36 +00:00
{
return false ;
}
}
else if ( QSBSceneManager . CurrentScene = = OWScene . EyeOfTheUniverse )
{
2021-11-14 03:51:22 -08:00
var shuttleController = QSBWorldSync . GetUnityObjects < EyeShuttleController > ( ) . First ( ) ;
2021-03-26 20:56:57 +00:00
if ( shuttleController = = null )
{
DebugLog . ToConsole ( $"Warning - Expected to find a EyeShuttleController for {AttachedObject.name}!" , MessageType . Warning ) ;
return false ;
}
2021-06-18 22:38:32 +01:00
2021-12-18 10:33:18 +00:00
if ( ! shuttleController . _isPlayerInside )
2021-03-13 19:54:36 +00:00
{
return false ;
}
}
2021-03-12 21:46:02 +00:00
}
2021-06-18 22:38:32 +01:00
2021-03-12 21:46:02 +00:00
return true ;
}
2020-12-02 21:23:01 +00:00
}
2021-11-13 00:42:59 -08:00
}