mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Fix dropping stuff, fix an annoying NRE when spawning, fix time loop in other systems when doing vessel warp shit
This commit is contained in:
parent
86f889fef8
commit
bfbf02a5c3
@ -17,7 +17,7 @@ public static class HeldItemHandler
|
||||
/// Dictionary of system name to item path
|
||||
/// If we travel to multiple systems within a single loop, this will hold the items we move between systems
|
||||
/// </summary>
|
||||
private static Dictionary<string, List<string>> _pathOfItemTakenFromSystem = new();
|
||||
private static Dictionary<string, HashSet<string>> _pathOfItemTakenFromSystem = new();
|
||||
|
||||
public static bool WasAWCTakenFromATP => _pathOfItemTakenFromSystem.TryGetValue("SolarSystem", out var list) && list.Contains(ADVANCED_WARP_CORE);
|
||||
|
||||
@ -45,16 +45,10 @@ public static class HeldItemHandler
|
||||
|
||||
_currentStarSystem = Main.Instance.CurrentStarSystem;
|
||||
|
||||
// If we took the AWC out of the main system make sure to disable time loop
|
||||
if (_currentStarSystem != "SolarSystem" && WasAWCTakenFromATP)
|
||||
{
|
||||
TimeLoop.SetTimeLoopEnabled(false);
|
||||
}
|
||||
|
||||
if (!_isInitialized)
|
||||
{
|
||||
_isInitialized = true;
|
||||
Main.Instance.StarSystemChanging += OnStarSystemChanging;
|
||||
Main.Instance.OnChangeStarSystem.AddListener(OnStarSystemChanging);
|
||||
Main.Instance.OnStarSystemLoaded.AddListener(OnSystemReady);
|
||||
GlobalMessenger<DeathType>.AddListener("PlayerDeath", OnPlayerDeath);
|
||||
}
|
||||
@ -71,8 +65,6 @@ public static class HeldItemHandler
|
||||
|
||||
private static GameObject MakePerfectCopy(GameObject go)
|
||||
{
|
||||
//go.SetActive(false);
|
||||
|
||||
var owItem = go.GetComponent<OWItem>();
|
||||
|
||||
var tempParent = new GameObject();
|
||||
@ -98,7 +90,7 @@ public static class HeldItemHandler
|
||||
_pathOfItemTakenFromSystem[Main.Instance.CurrentStarSystem].Add(path);
|
||||
}
|
||||
|
||||
private static void OnStarSystemChanging()
|
||||
private static void OnStarSystemChanging(string _)
|
||||
{
|
||||
if (_currentlyHeldItem != null)
|
||||
{
|
||||
@ -109,7 +101,7 @@ public static class HeldItemHandler
|
||||
}
|
||||
|
||||
NHLogger.Log($"Scene unloaded, preserved inactive held item {_currentlyHeldItem.name}");
|
||||
// For some reason, the original will get destroyed no matter what do we make a copy
|
||||
// For some reason, the original will get destroyed no matter what we do. To avoid, we make a copy
|
||||
_currentlyHeldItem = MakePerfectCopy(_currentlyHeldItem).DontDestroyOnLoad();
|
||||
}
|
||||
|
||||
@ -155,7 +147,7 @@ public static class HeldItemHandler
|
||||
}
|
||||
NHLogger.Log($"Unsocketed {item.name}");
|
||||
}
|
||||
GameObject.Destroy(item.gameObject);
|
||||
item.gameObject.SetActive(false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -219,4 +211,19 @@ public static class HeldItemHandler
|
||||
NHLogger.Log($"Player is now holding {item?.name ?? "nothing"}");
|
||||
_currentlyHeldItem = item?.gameObject;
|
||||
}
|
||||
|
||||
[HarmonyPostfix, HarmonyPatch(typeof(ItemTool))]
|
||||
[HarmonyPatch(nameof(ItemTool.SocketItem))]
|
||||
[HarmonyPatch(nameof(ItemTool.DropItem))]
|
||||
[HarmonyPatch(nameof(ItemTool.StartUnsocketItem))]
|
||||
private static void HeldItemChanged2(ItemTool __instance)
|
||||
{
|
||||
if (!_isSystemReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
NHLogger.Log($"Player is now holding nothing");
|
||||
_currentlyHeldItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,11 +51,21 @@ namespace NewHorizons.Handlers
|
||||
Delay.StartCoroutine(SpawnCoroutine(30));
|
||||
}
|
||||
|
||||
var cloak = GetDefaultSpawn()?.GetAttachedOWRigidbody()?.GetComponentInChildren<CloakFieldController>();
|
||||
if (cloak != null)
|
||||
|
||||
// It was NREing in here when it was all ?. so explicit null checks
|
||||
var spawn = GetDefaultSpawn();
|
||||
if (spawn != null)
|
||||
{
|
||||
// Ensures it has invoked everything and actually placed the player in the cloaking field #671
|
||||
cloak._firstUpdate = true;
|
||||
var attachedOWRigidBody = spawn.GetAttachedOWRigidbody();
|
||||
if (attachedOWRigidBody != null)
|
||||
{
|
||||
var cloak = attachedOWRigidBody.GetComponentInChildren<CloakFieldController>();
|
||||
if (cloak != null)
|
||||
{
|
||||
// Ensures it has invoked everything and actually placed the player in the cloaking field #671
|
||||
cloak._firstUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Spawn ship
|
||||
|
||||
@ -949,7 +949,6 @@ namespace NewHorizons
|
||||
#endregion Load
|
||||
|
||||
#region Change star system
|
||||
public Action StarSystemChanging { get; set; }
|
||||
public void ChangeCurrentStarSystem(string newStarSystem, bool warp = false, bool vessel = false)
|
||||
{
|
||||
// If we're just on the title screen set the system for later
|
||||
@ -978,8 +977,6 @@ namespace NewHorizons
|
||||
|
||||
if (LoadManager.GetCurrentScene() == OWScene.SolarSystem || LoadManager.GetCurrentScene() == OWScene.EyeOfTheUniverse)
|
||||
{
|
||||
StarSystemChanging?.Invoke();
|
||||
|
||||
IsWarpingFromShip = warp;
|
||||
IsWarpingFromVessel = vessel;
|
||||
DidWarpFromVessel = false;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using HarmonyLib;
|
||||
using NewHorizons.Handlers;
|
||||
|
||||
namespace NewHorizons.Patches
|
||||
{
|
||||
@ -14,5 +15,16 @@ namespace NewHorizons.Patches
|
||||
[HarmonyPatch(typeof(GlobalMusicController), nameof(GlobalMusicController.UpdateEndTimesMusic))]
|
||||
[HarmonyPatch(typeof(TimeLoop), nameof(TimeLoop.Update))]
|
||||
public static bool DisableWithoutTimeLoop() => Main.Instance.TimeLoopEnabled;
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(TimeLoop), nameof(TimeLoop.Start))]
|
||||
public static void TimeLoop_Start(TimeLoop __instance)
|
||||
{
|
||||
// If we took the AWC out of the main system make sure to disable time loop
|
||||
if (Main.Instance.CurrentStarSystem != "SolarSystem" && HeldItemHandler.WasAWCTakenFromATP)
|
||||
{
|
||||
TimeLoop.SetTimeLoopEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user