Reorganize a bit and add more comments

This commit is contained in:
xen-42 2025-02-09 23:26:16 -05:00
parent 187bf415dc
commit ddb1d50816
4 changed files with 34 additions and 23 deletions

View File

@ -36,6 +36,8 @@ namespace NewHorizons.Handlers
[HarmonyPatch(typeof(PlayerImpactAudio), nameof(PlayerImpactAudio.OnImpact))] [HarmonyPatch(typeof(PlayerImpactAudio), nameof(PlayerImpactAudio.OnImpact))]
public static bool DeathManager_KillPlayer_Prefix() public static bool DeathManager_KillPlayer_Prefix()
{ {
// Base game _invincible is still overriden by high speed impacts
// We also are avoiding playing impact related effects by just skipping these methods
return !_invulnerable; return !_invulnerable;
} }

View File

@ -70,7 +70,14 @@ namespace NewHorizons.Handlers
// Spawn ship // Spawn ship
Delay.FireInNUpdates(SpawnShip, 30); Delay.FireInNUpdates(SpawnShip, 30);
Delay.FireInNUpdates(() =>
// Have had bug reports (#1034, #975) where sometimes after spawning via vessel warp or ship warp you die from impact velocity after being flung
// Something weird must be happening with velocity.
// Try to correct it here after the ship is done spawning
Delay.FireInNUpdates(() => FixVelocity(shouldWarpInFromVessel, shouldWarpInFromShip), 31);
}
private static void FixVelocity(bool shouldWarpInFromVessel, bool shouldWarpInFromShip)
{ {
var spawnOWRigidBody = GetDefaultSpawn().GetAttachedOWRigidbody(); var spawnOWRigidBody = GetDefaultSpawn().GetAttachedOWRigidbody();
if (shouldWarpInFromVessel) spawnOWRigidBody = VesselWarpHandler.VesselSpawnPoint.GetAttachedOWRigidbody(); if (shouldWarpInFromVessel) spawnOWRigidBody = VesselWarpHandler.VesselSpawnPoint.GetAttachedOWRigidbody();
@ -81,7 +88,6 @@ namespace NewHorizons.Handlers
var velocity = spawnVelocity + spawnAngularVelocity; var velocity = spawnVelocity + spawnAngularVelocity;
Locator.GetPlayerBody().SetVelocity(velocity); Locator.GetPlayerBody().SetVelocity(velocity);
}, 31);
} }
public static void SpawnShip() public static void SpawnShip()

View File

@ -56,7 +56,9 @@ namespace NewHorizons.Handlers
} }
if (IsVesselPresentAndActive()) if (IsVesselPresentAndActive())
{
_vesselSpawnPoint = Instance.CurrentStarSystem == "SolarSystem" ? UpdateVessel() : CreateVessel(); _vesselSpawnPoint = Instance.CurrentStarSystem == "SolarSystem" ? UpdateVessel() : CreateVessel();
}
else else
{ {
var vesselDimension = SearchUtilities.Find("DB_VesselDimension_Body/Sector_VesselDimension"); var vesselDimension = SearchUtilities.Find("DB_VesselDimension_Body/Sector_VesselDimension");
@ -84,9 +86,12 @@ namespace NewHorizons.Handlers
if (_vesselSpawnPoint is VesselSpawnPoint vesselSpawnPoint) if (_vesselSpawnPoint is VesselSpawnPoint vesselSpawnPoint)
{ {
NHLogger.LogVerbose("Relative warping into vessel"); NHLogger.LogVerbose("Relative warping into vessel");
vesselSpawnPoint.WarpPlayer();//Delay.FireOnNextUpdate(vesselSpawnPoint.WarpPlayer); vesselSpawnPoint.WarpPlayer();
//Delay.FireInNUpdates(() => InvulnerabilityHandler.MakeInvulnerable(false), 25);
Delay.StartCoroutine(RunEveryNFrames(25, vesselSpawnPoint)); // #1034 Vessel warp sometimes has the player get flung away into space and die
// We do what we do with regular spawns where we keep resetting their position to the right one while invincible until we're relatively certain
// that the spawning sequence is done
Delay.StartCoroutine(FixPlayerSpawning(25, vesselSpawnPoint));
} }
else else
{ {
@ -98,25 +103,23 @@ namespace NewHorizons.Handlers
LoadDB(); LoadDB();
} }
private static IEnumerator RunEveryNFrames(int frameInterval, VesselSpawnPoint vesselSpawn) private static IEnumerator FixPlayerSpawning(int frameInterval, VesselSpawnPoint vesselSpawn)
{ {
int frameCount = 0;
InvulnerabilityHandler.MakeInvulnerable(true); InvulnerabilityHandler.MakeInvulnerable(true);
var frameCount = 0;
while (frameCount <= frameInterval) while (frameCount <= frameInterval)
{ {
vesselSpawn.WarpPlayer(); vesselSpawn.WarpPlayer();
if (frameCount == frameInterval) frameCount++;
{ yield return null; // Wait for the next frame
}
InvulnerabilityHandler.MakeInvulnerable(false); InvulnerabilityHandler.MakeInvulnerable(false);
var playerBody = SearchUtilities.Find("Player_Body").GetAttachedOWRigidbody(); var playerBody = SearchUtilities.Find("Player_Body").GetAttachedOWRigidbody();
var resources = playerBody.GetComponent<PlayerResources>(); var resources = playerBody.GetComponent<PlayerResources>();
resources._currentHealth = 100f; resources._currentHealth = 100f;
} }
frameCount++;
yield return null; // Wait for the next frame
}
}
public static void LoadDB() public static void LoadDB()
{ {

View File

@ -613,7 +613,7 @@ namespace NewHorizons
{ {
IsSystemReady = true; IsSystemReady = true;
// ShipWarpController will handle the invulnerability otherwise // ShipWarpController or VesselWarpHandler will handle the invulnerability otherwise
if (!shouldWarpInFromShip && !shouldWarpInFromVessel) if (!shouldWarpInFromShip && !shouldWarpInFromVessel)
{ {
Delay.FireOnNextUpdate(() => InvulnerabilityHandler.MakeInvulnerable(false)); Delay.FireOnNextUpdate(() => InvulnerabilityHandler.MakeInvulnerable(false));