Vessel spawning and parenting

This commit is contained in:
Joshua Thome 2023-03-18 19:54:52 -05:00
parent 8aa22a639f
commit d7b76718f8
3 changed files with 33 additions and 7 deletions

View File

@ -190,6 +190,16 @@ namespace NewHorizons.External.Configs
/// </summary>
public string promptFact;
/// <summary>
/// Whether the vessel should spawn in this system even if it wasn't used to warp to it.
/// </summary>
public bool alwaysPresent;
/// <summary>
/// Whether to always spawn the player on the vessel, even if it wasn't used to warp to the system.
/// </summary>
public bool spawnOnVessel;
/// <summary>
/// Whether the vessel should have physics enabled. This must be set to false for the vessel to stay attached to a parent body.
/// </summary>

View File

@ -29,13 +29,16 @@ namespace NewHorizons.Handlers
public static void LoadVessel()
{
var system = SystemDict[Instance.CurrentStarSystem];
if (Instance.CurrentStarSystem == "EyeOfTheUniverse")
{
_vesselSpawnPoint = SearchUtilities.Find("Vessel_Body/SPAWN_Vessel").GetComponent<EyeSpawnPoint>();
return;
}
if (Instance.IsWarpingFromVessel)
var vesselIsPresent = system.Config?.Vessel?.alwaysPresent ?? false;
if (Instance.IsWarpingFromVessel || vesselIsPresent)
_vesselSpawnPoint = Instance.CurrentStarSystem == "SolarSystem" ? UpdateVessel() : CreateVessel();
else
_vesselSpawnPoint = SearchUtilities.Find("DB_VesselDimension_Body/Sector_VesselDimension").GetComponentInChildren<SpawnPoint>();
@ -91,11 +94,7 @@ namespace NewHorizons.Handlers
VesselObject = vesselObject;
var vesselAO = vesselObject.AddComponent<EyeAstroObject>();
if (system.Config.Vessel?.hasPhysics ?? true)
{
vesselAO._owRigidbody = vesselObject.GetComponent<OWRigidbody>();
vesselObject.transform.parent = null;
}
vesselAO._owRigidbody = vesselObject.GetComponent<OWRigidbody>();
vesselAO._rootSector = vesselObject.GetComponentInChildren<Sector>(true);
vesselAO._customName = "Vessel";
vesselAO._name = AstroObject.Name.CustomString;
@ -159,6 +158,20 @@ namespace NewHorizons.Handlers
EyeSpawnPoint eyeSpawnPoint = vesselObject.GetComponentInChildren<EyeSpawnPoint>(true);
system.SpawnPoint = eyeSpawnPoint;
if (system.Config.Vessel?.hasPhysics ?? true)
{
vesselObject.transform.parent = null;
}
else
{
vesselAO._owRigidbody = null;
UnityEngine.Object.DestroyImmediate(vesselObject.GetComponent<KinematicRigidbody>());
UnityEngine.Object.DestroyImmediate(vesselObject.GetComponent<CenterOfTheUniverseOffsetApplier>());
UnityEngine.Object.DestroyImmediate(vesselObject.GetComponent<OWRigidbody>());
UnityEngine.Object.DestroyImmediate(vesselObject.GetComponent<Rigidbody>());
}
vesselWarpController._targetWarpPlatform._owRigidbody = warpExit.GetAttachedOWRigidbody();
vesselObject.SetActive(true);
Delay.FireOnNextUpdate(() => SetupWarpController(vesselWarpController));

View File

@ -400,8 +400,11 @@ namespace NewHorizons
}
if (HasWarpDrive == true) EnableWarpDrive();
var vesselIsPresent = SystemDict[CurrentStarSystem].Config?.Vessel?.alwaysPresent ?? false;
var shouldSpawnOnVessel = vesselIsPresent && (SystemDict[CurrentStarSystem].Config?.Vessel?.spawnOnVessel ?? false);
var shouldWarpInFromShip = IsWarpingFromShip && _shipWarpController != null;
var shouldWarpInFromVessel = IsWarpingFromVessel && VesselWarpHandler.VesselSpawnPoint != null;
var shouldWarpInFromVessel = (IsWarpingFromVessel || shouldSpawnOnVessel) && VesselWarpHandler.VesselSpawnPoint != null;
Delay.RunWhen(() => IsSystemReady, () => OnSystemReady(shouldWarpInFromShip, shouldWarpInFromVessel));
IsWarpingFromShip = false;