mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Player spawning cleanup, doesn't work in main system + kills player on first spawn sometimes
This commit is contained in:
parent
b46906aab8
commit
f354f99107
@ -6,6 +6,7 @@ using NewHorizons.Utility.OuterWilds;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using Steamworks;
|
||||
|
||||
namespace NewHorizons.Builder.General
|
||||
{
|
||||
@ -16,25 +17,37 @@ namespace NewHorizons.Builder.General
|
||||
{
|
||||
SpawnPoint playerSpawn = null;
|
||||
|
||||
if (!Main.Instance.IsWarpingFromVessel && !Main.Instance.IsWarpingFromShip && module.playerSpawn != null)
|
||||
// Make the spawn point even if it won't be used this loop
|
||||
if (module.playerSpawn != null)
|
||||
{
|
||||
GameObject spawnGO = GeneralPropBuilder.MakeNew("PlayerSpawnPoint", planetGO, null, module.playerSpawn);
|
||||
spawnGO.SetActive(false);
|
||||
spawnGO.layer = Layer.PlayerSafetyCollider;
|
||||
|
||||
playerSpawn = spawnGO.AddComponent<SpawnPoint>();
|
||||
playerSpawn._attachedBody = owRigidBody;
|
||||
playerSpawn._spawnLocation = SpawnLocation.None;
|
||||
// #601 we need to actually set the right trigger volumes here
|
||||
playerSpawn._triggerVolumes = new OWTriggerVolume[0];
|
||||
|
||||
spawnGO.transform.position += spawnGO.transform.up * 4f;
|
||||
spawnGO.SetActive(true);
|
||||
}
|
||||
|
||||
if (module.shipSpawn != null)
|
||||
{
|
||||
GameObject spawnGO = GeneralPropBuilder.MakeNew("ShipSpawnPoint", planetGO, null, module.shipSpawn);
|
||||
spawnGO.SetActive(false);
|
||||
spawnGO.layer = Layer.PlayerSafetyCollider;
|
||||
|
||||
var spawnPoint = spawnGO.AddComponent<SpawnPoint>();
|
||||
spawnPoint._isShipSpawn = true;
|
||||
spawnPoint._triggerVolumes = new OWTriggerVolume[0];
|
||||
var shipSpawn = spawnGO.AddComponent<SpawnPoint>();
|
||||
shipSpawn._isShipSpawn = true;
|
||||
shipSpawn._attachedBody = owRigidBody;
|
||||
shipSpawn._spawnLocation = SpawnLocation.None;
|
||||
|
||||
// #601 we need to actually set the right trigger volumes here
|
||||
shipSpawn._triggerVolumes = new OWTriggerVolume[0];
|
||||
|
||||
// TODO: this should happen elsewhere
|
||||
var ship = SearchUtilities.Find("Ship_Body");
|
||||
if (ship != null)
|
||||
{
|
||||
@ -48,27 +61,14 @@ namespace NewHorizons.Builder.General
|
||||
}
|
||||
|
||||
ship.GetRequiredComponent<MatchInitialMotion>().SetBodyToMatch(owRigidBody);
|
||||
|
||||
if (Main.Instance.IsWarpingFromShip)
|
||||
{
|
||||
NHLogger.LogVerbose("Overriding player spawn to be inside ship");
|
||||
GameObject playerSpawnGO = new GameObject("PlayerSpawnPoint");
|
||||
playerSpawnGO.transform.parent = ship.transform;
|
||||
playerSpawnGO.layer = Layer.PlayerSafetyCollider;
|
||||
|
||||
playerSpawnGO.transform.localPosition = new Vector3(0, 0, 0);
|
||||
|
||||
playerSpawn = playerSpawnGO.AddComponent<SpawnPoint>();
|
||||
playerSpawn._triggerVolumes = new OWTriggerVolume[0];
|
||||
playerSpawnGO.transform.localRotation = Quaternion.Euler(0, 0, 0);
|
||||
}
|
||||
}
|
||||
spawnGO.SetActive(true);
|
||||
}
|
||||
|
||||
if ((Main.Instance.IsWarpingFromVessel || (!Main.Instance.IsWarpingFromShip && (module.playerSpawn?.startWithSuit ?? false))) && !suitUpQueued)
|
||||
{
|
||||
suitUpQueued = true;
|
||||
Delay.RunWhen(() => Main.IsSystemReady, () => SuitUp());
|
||||
Delay.RunWhen(() => Main.IsSystemReady, SuitUp);
|
||||
}
|
||||
|
||||
NHLogger.Log($"Made spawnpoint on [{planetGO.name}]");
|
||||
|
||||
@ -134,7 +134,7 @@ namespace NewHorizons.Components.Ship
|
||||
{
|
||||
if (_isWarpingIn && LateInitializerManager.isDoneInitializing)
|
||||
{
|
||||
Delay.FireInNUpdates(() => StartWarpInEffect(), 1);
|
||||
Delay.FireOnNextUpdate(StartWarpInEffect);
|
||||
_isWarpingIn = false;
|
||||
}
|
||||
|
||||
@ -167,7 +167,7 @@ namespace NewHorizons.Components.Ship
|
||||
NHLogger.LogVerbose("Starting warp-in effect");
|
||||
_oneShotSource.PlayOneShot(AudioType.VesselSingularityCollapse, 1f);
|
||||
Locator.GetDeathManager()._invincible = true;
|
||||
if (Main.Instance.CurrentStarSystem.Equals("SolarSystem")) TeleportToShip();
|
||||
TeleportToShip();
|
||||
_whitehole.Create();
|
||||
_waitingToBeSeated = true;
|
||||
if (_wearingSuit && !Locator.GetPlayerController()._isWearingSuit)
|
||||
@ -179,6 +179,7 @@ namespace NewHorizons.Components.Ship
|
||||
private void TeleportToShip()
|
||||
{
|
||||
var playerSpawner = FindObjectOfType<PlayerSpawner>();
|
||||
NHLogger.LogVerbose("Debug warping into ship");
|
||||
playerSpawner.DebugWarp(playerSpawner.GetSpawnPoint(SpawnLocation.Ship));
|
||||
}
|
||||
|
||||
|
||||
@ -456,9 +456,12 @@ namespace NewHorizons.Handlers
|
||||
// Spawning on other planets is a bit hacky so we do it last
|
||||
if (body.Config.Spawn != null)
|
||||
{
|
||||
NHLogger.LogVerbose("Making spawn point");
|
||||
NHLogger.LogVerbose($"Making spawn point on {body.Config.name}");
|
||||
var spawnPoint = SpawnPointBuilder.Make(go, body.Config.Spawn, owRigidBody);
|
||||
if (Main.SystemDict[body.Config.starSystem].SpawnPoint == null || (body.Config.Spawn.playerSpawn?.isDefault ?? false))
|
||||
var isVanillaSystem = body.Config.starSystem == "SolarSystem" || body.Config.starSystem == "EyeOfTheUniverse";
|
||||
var needsSpawnPoint = Main.SystemDict[body.Config.starSystem].SpawnPoint == null || isVanillaSystem;
|
||||
var isDefaultSpawn = body.Config.Spawn.playerSpawn?.isDefault ?? true; // Backwards compat
|
||||
if (needsSpawnPoint || isDefaultSpawn)
|
||||
{
|
||||
Main.SystemDict[body.Config.starSystem].SpawnPoint = spawnPoint;
|
||||
}
|
||||
|
||||
@ -62,6 +62,7 @@ namespace NewHorizons.Handlers
|
||||
public static void TeleportToVessel()
|
||||
{
|
||||
var playerSpawner = Object.FindObjectOfType<PlayerSpawner>();
|
||||
NHLogger.LogVerbose("Debug warping into vessel");
|
||||
playerSpawner.DebugWarp(_vesselSpawnPoint);
|
||||
Builder.General.SpawnPointBuilder.SuitUp();
|
||||
|
||||
|
||||
@ -564,11 +564,27 @@ namespace NewHorizons
|
||||
Locator.GetPlayerBody().gameObject.AddComponent<DebugRaycaster>();
|
||||
Locator.GetPlayerBody().gameObject.AddComponent<DebugPropPlacer>();
|
||||
Locator.GetPlayerBody().gameObject.AddComponent<DebugMenu>();
|
||||
// DebugArrow.CreateArrow(Locator.GetPlayerBody().gameObject); // This is for NH devs mostly. It shouldn't be active in debug mode for now. Someone should make a dev tools submenu for it though.
|
||||
|
||||
if (shouldWarpInFromShip) _shipWarpController.WarpIn(WearingSuit);
|
||||
else if (shouldWarpInFromVessel) VesselWarpHandler.TeleportToVessel();
|
||||
else FindObjectOfType<PlayerSpawner>().DebugWarp(SystemDict[_currentStarSystem].SpawnPoint);
|
||||
if (shouldWarpInFromShip)
|
||||
{
|
||||
_shipWarpController.WarpIn(WearingSuit);
|
||||
}
|
||||
else if (shouldWarpInFromVessel)
|
||||
{
|
||||
VesselWarpHandler.TeleportToVessel();
|
||||
}
|
||||
else
|
||||
{
|
||||
var spawnPoint = SystemDict[CurrentStarSystem].SpawnPoint;
|
||||
if (spawnPoint != null)
|
||||
{
|
||||
Delay.FireOnNextUpdate(() => GameObject.FindObjectOfType<PlayerSpawner>().DebugWarp(spawnPoint));
|
||||
}
|
||||
else
|
||||
{
|
||||
NHLogger.Log($"No NH spawn point for {CurrentStarSystem}");
|
||||
}
|
||||
}
|
||||
|
||||
VesselCoordinatePromptHandler.RegisterPrompts(SystemDict.Where(system => system.Value.Config.Vessel?.coords != null).Select(x => x.Value).ToList());
|
||||
}
|
||||
|
||||
@ -11,19 +11,12 @@ namespace NewHorizons.Patches.PlayerPatches
|
||||
[HarmonyPatch(nameof(PlayerSpawner.SpawnPlayer))]
|
||||
public static bool PlayerSpawner_SpawnPlayer(PlayerSpawner __instance)
|
||||
{
|
||||
if (Main.Instance.IsWarpingFromVessel || Main.Instance.DidWarpFromVessel)
|
||||
if (Main.Instance.IsWarpingFromVessel || Main.Instance.DidWarpFromVessel || Main.Instance.IsWarpingFromShip)
|
||||
{
|
||||
NHLogger.LogWarning("Abort player spawn. Vessel will handle it.");
|
||||
NHLogger.LogWarning("Abort player spawn. Vessel/Ship will handle it.");
|
||||
return false;
|
||||
}
|
||||
else if (Main.SystemDict[Main.Instance.CurrentStarSystem].SpawnPoint != null)
|
||||
{
|
||||
NHLogger.LogVerbose($"Player spawning at {Main.SystemDict[Main.Instance.CurrentStarSystem].SpawnPoint.transform.GetPath()}");
|
||||
__instance.SetInitialSpawnPoint(Main.SystemDict[Main.Instance.CurrentStarSystem].SpawnPoint);
|
||||
} else if (Main.Instance.CurrentStarSystem != "SolarSystem" && Main.Instance.CurrentStarSystem != "EyeOfTheUniverse")
|
||||
{
|
||||
NHLogger.LogWarning("No player spawn point set.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user