Merge pull request #195 from MegaPiggy/vessel

Add warping to solar systems using vessel
This commit is contained in:
Nick 2022-06-19 16:21:28 -04:00 committed by GitHub
commit 75916d2a31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 471 additions and 61 deletions

View File

@ -33,6 +33,7 @@ namespace NewHorizons.AchievementsPlus
// Register base NH achievements
NH.WarpDriveAchievement.Init();
NH.VesselWarpAchievement.Init();
NH.MultipleSystemAchievement.Init();
NH.EatenOutsideBrambleAchievement.Init();
NH.NewFrequencyAchievement.Init();

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewHorizons.AchievementsPlus.NH
{
public static class VesselWarpAchievement
{
public static readonly string UNIQUE_ID = "NH_VESSEL_WARP";
public static void Init()
{
AchievementHandler.Register(UNIQUE_ID, false, Main.Instance);
Main.Instance.OnChangeStarSystem.AddListener(OnChangeStarSystem);
}
private static void OnChangeStarSystem(string system)
{
if (Main.Instance.IsWarpingFromVessel) AchievementHandler.Earn(UNIQUE_ID);
}
}
}

View File

@ -18,7 +18,7 @@ namespace NewHorizons.AchievementsPlus.NH
private static void OnChangeStarSystem(string system)
{
if (Main.Instance.IsWarping) AchievementHandler.Earn(UNIQUE_ID);
if (Main.Instance.IsWarpingFromShip) AchievementHandler.Earn(UNIQUE_ID);
}
}
}

Binary file not shown.

View File

@ -43,7 +43,8 @@ namespace NewHorizons.Builder.General
owrb.SetAttachedReferenceFrameVolume(RFV);
rfGO.SetActive(!module.hideInMap);
if (!module.enabled) GameObject.Destroy(rfGO);
else rfGO.SetActive(!module.hideInMap);
}
}
}

View File

@ -10,7 +10,7 @@ namespace NewHorizons.Builder.General
public static SpawnPoint Make(GameObject planetGO, SpawnModule module, OWRigidbody owRigidBody)
{
SpawnPoint playerSpawn = null;
if (!Main.Instance.IsWarping && module.playerSpawnPoint != null)
if (!Main.Instance.IsWarpingFromVessel && !Main.Instance.IsWarpingFromShip && module.playerSpawnPoint != null)
{
GameObject spawnGO = new GameObject("PlayerSpawnPoint");
spawnGO.transform.parent = planetGO.transform;
@ -46,8 +46,8 @@ namespace NewHorizons.Builder.General
var ship = SearchUtilities.Find("Ship_Body");
ship.transform.position = spawnPoint.transform.position;
if(module.shipSpawnRotation != null)
if (module.shipSpawnRotation != null)
{
ship.transform.rotation = Quaternion.Euler(module.shipSpawnRotation);
}
@ -60,7 +60,7 @@ namespace NewHorizons.Builder.General
ship.GetRequiredComponent<MatchInitialMotion>().SetBodyToMatch(owRigidBody);
if (Main.Instance.IsWarping)
if (Main.Instance.IsWarpingFromShip)
{
Logger.Log("Overriding player spawn to be inside ship");
GameObject playerSpawnGO = new GameObject("PlayerSpawnPoint");
@ -74,7 +74,8 @@ namespace NewHorizons.Builder.General
playerSpawnGO.transform.localRotation = Quaternion.Euler(0, 0, 0);
}
}
if (!Main.Instance.IsWarping && module.startWithSuit && !suitUpQueued)
if ((Main.Instance.IsWarpingFromVessel || (!Main.Instance.IsWarpingFromShip && module.startWithSuit)) && !suitUpQueued)
{
suitUpQueued = true;
Main.Instance.ModHelper.Events.Unity.RunWhen(() => Main.IsSystemReady, () => SuitUp());

View File

@ -59,6 +59,7 @@ namespace NewHorizons.Builder.Orbital
fakeMassConfig.name = config.name + "_FakeBarycenterMass";
fakeMassConfig.Base.soiOverride = 0;
fakeMassConfig.Base.hasMapMarker = false;
fakeMassConfig.ReferenceFrame.enabled = false;
fakeMassConfig.ReferenceFrame.hideInMap = true;
fakeMassConfig.Orbit = new OrbitModule();

View File

@ -119,7 +119,7 @@ namespace NewHorizons.Components
_cloak._cloakVisualsEnabled = false;
}
public void SetReferenceFrameVolumeActive(bool active) => _cloak._referenceFrameVolume.gameObject.SetActive(active);
public void SetReferenceFrameVolumeActive(bool active) => _cloak._referenceFrameVolume?.gameObject.SetActive(active);
public void EnableReferenceFrameVolume() => SetReferenceFrameVolumeActive(true);
public void DisableReferenceFrameVolume() => SetReferenceFrameVolumeActive(false);

View File

@ -0,0 +1,34 @@
using NewHorizons.Utility;
using System.Linq;
using UnityEngine;
namespace NewHorizons.Components
{
/// <summary>
/// Used by vessel asset bundle to change materials to the in-game ones.
/// </summary>
public class MaterialReplacer : MonoBehaviour
{
public string[] materialNames;
public void Start()
{
Renderer renderer = GetComponent<Renderer>();
NomaiNodeController nnc = GetComponent<NomaiNodeController>();
if (renderer != null)
{
var materials = materialNames.Select(name => SearchUtilities.FindResourceOfTypeAndName<Material>(name)).ToArray();
if (renderer is ParticleSystemRenderer psr)
psr.materials = materials;
else
renderer.sharedMaterials = materials;
}
else if (nnc != null)
{
var materials = materialNames.Select(name => SearchUtilities.FindResourceOfTypeAndName<Material>(name)).ToArray();
nnc._inactiveMaterial = materials[0];
nnc._activeMaterial = materials[1];
}
}
}
}

View File

@ -203,7 +203,7 @@ namespace NewHorizons.External.Configs
if (Base.isSatellite) Base.showMinimap = false;
if (!Base.hasReferenceFrame) ReferenceFrame.hideInMap = true;
if (!Base.hasReferenceFrame) ReferenceFrame.enabled = false;
if (childrenToDestroy != null) removeChildren = childrenToDestroy;

View File

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using NewHorizons.Utility;
using Newtonsoft.Json;
using static NewHorizons.External.Modules.ShipLogModule;
@ -59,6 +60,31 @@ namespace NewHorizons.External.Configs
/// </summary>
public string travelAudioFilePath;
/// <summary>
/// Coordinates that the vessel can use to warp to your solar system.
/// </summary>
public NomaiCoordinates coords;
/// <summary>
/// The position in the solar system the vessel will warp to.
/// </summary>
public MVector3 vesselPosition;
/// <summary>
/// Euler angles by which the vessel will be oriented.
/// </summary>
public MVector3 vesselRotation;
/// <summary>
/// The relative position to the vessel that you will be teleported to when you exit the vessel through the black hole.
/// </summary>
public MVector3 warpExitPosition;
/// <summary>
/// Euler angles by which the warp exit will be oriented.
/// </summary>
public MVector3 warpExitRotation;
/// <summary>
/// Manually layout ship log entries in detective mode
/// </summary>
@ -100,6 +126,13 @@ namespace NewHorizons.External.Configs
public string path;
}
public void FixCoordinates()
{
coords.x = coords.x.Distinct().ToArray();
coords.y = coords.y.Distinct().ToArray();
coords.z = coords.z.Distinct().ToArray();
}
public void Merge(StarSystemConfig otherConfig)
{
// Imagine if this used reflection

View File

@ -10,6 +10,11 @@ namespace NewHorizons.External.Modules
[JsonObject]
public class ReferenceFrameModule
{
/// <summary>
/// Allows the object to be targeted.
/// </summary>
[DefaultValue(true)] public bool enabled = true;
/// <summary>
/// Stop the object from being targeted on the map.
/// </summary>

View File

@ -26,9 +26,18 @@ namespace NewHorizons.Handlers
_entryIDsToNHBody = new Dictionary<string, NewHorizonsBody>();
_nhBodyToAstroIDs = new Dictionary<NewHorizonsBody, string>();
List<GameObject> gameObjects = SearchUtilities.GetAllChildren(SearchUtilities.Find(PAN_ROOT_PATH));
_vanillaBodies = gameObjects.ConvertAll(g => g.name).ToArray();
_vanillaBodyIDs = gameObjects.ConvertAll(g => g.GetComponent<ShipLogAstroObject>()?.GetID()).ToArray();
GameObject panRoot = SearchUtilities.Find(PAN_ROOT_PATH);
if (panRoot != null)
{
List<GameObject> gameObjects = SearchUtilities.GetAllChildren(panRoot);
_vanillaBodies = gameObjects.ConvertAll(g => g.name).ToArray();
_vanillaBodyIDs = gameObjects.ConvertAll(g => g.GetComponent<ShipLogAstroObject>()?.GetID()).ToArray();
}
else
{
_vanillaBodies = new string[0];
_vanillaBodyIDs = new string[0];
}
}
public static void CheckForModdedFacts(ShipLogManager manager)

View File

@ -0,0 +1,164 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using NewHorizons.Utility;
using Logger = NewHorizons.Utility.Logger;
using static NewHorizons.Main;
namespace NewHorizons.Handlers
{
public static class VesselWarpHandler
{
public static AssetBundle VesselBundle { get; private set; }
public static GameObject VesselPrefab { get; private set; }
internal static void Initialize()
{
VesselBundle = Main.Instance.ModHelper.Assets.LoadBundle("Assets/vessel.newhorizons");
VesselPrefab = VesselBundle.LoadAsset<GameObject>("Vessel_Body");
}
public static void OnReceiveWarpedBody(OWRigidbody warpedBody, NomaiWarpPlatform startPlatform, NomaiWarpPlatform targetPlatform)
{
bool isPlayer = warpedBody.CompareTag("Player");
if (isPlayer)
{
Transform player_body = Locator.GetPlayerTransform();
OWRigidbody s_rb = Locator.GetShipBody();
OWRigidbody p_rb = Locator.GetPlayerBody();
Vector3 newPos = player_body.position;
Vector3 offset = player_body.up * 10;
newPos += offset;
s_rb.SetPosition(newPos);
s_rb.SetRotation(player_body.transform.rotation);
s_rb.SetVelocity(p_rb.GetVelocity());
}
}
public static EyeSpawnPoint CreateVessel()
{
var system = SystemDict[Instance.CurrentStarSystem];
Logger.Log("Checking for Vessel Prefab");
if (VesselPrefab == null) return null;
Logger.Log("Creating Vessel");
var vesselObject = GameObject.Instantiate(VesselPrefab);
vesselObject.name = VesselPrefab.name;
vesselObject.transform.parent = null;
if (system.Config.vesselPosition != null)
vesselObject.transform.position += system.Config.vesselPosition;
if (system.Config.vesselRotation != null)
vesselObject.transform.eulerAngles = system.Config.vesselRotation;
VesselWarpController vesselWarpController = vesselObject.GetComponentInChildren<VesselWarpController>(true);
vesselWarpController._sourceWarpPlatform.transform.DestroyAllChildren();
vesselWarpController._targetWarpPlatform.transform.DestroyAllChildren();
GameObject.Destroy(vesselWarpController._blackHole.transform.parent.gameObject);
GameObject.Destroy(vesselWarpController._whiteHole.transform.parent.gameObject);
GameObject WarpPlatform = SearchUtilities.Find("DB_VesselDimension_Body/Sector_VesselDimension/Sector_VesselBridge/Interactibles_VesselBridge/WarpController/Prefab_NOM_WarpPlatform");
GameObject warpBH = WarpPlatform.transform.Find("BlackHole").gameObject;
GameObject warpWH = WarpPlatform.transform.Find("WhiteHole").gameObject;
GameObject sourceBH = GameObject.Instantiate(warpBH, vesselWarpController._sourceWarpPlatform.transform, false);
vesselWarpController._sourceWarpPlatform._blackHole = sourceBH.GetComponentInChildren<SingularityController>();
GameObject sourceWH = GameObject.Instantiate(warpWH, vesselWarpController._sourceWarpPlatform.transform, false);
vesselWarpController._sourceWarpPlatform._whiteHole = sourceWH.GetComponentInChildren<SingularityController>();
GameObject targetBH = GameObject.Instantiate(warpBH, vesselWarpController._targetWarpPlatform.transform, false);
vesselWarpController._targetWarpPlatform._blackHole = targetBH.GetComponentInChildren<SingularityController>();
GameObject targetWH = GameObject.Instantiate(warpWH, vesselWarpController._targetWarpPlatform.transform, false);
vesselWarpController._targetWarpPlatform._whiteHole = targetWH.GetComponentInChildren<SingularityController>();
GameObject blackHole = SearchUtilities.Find("DB_VesselDimension_Body/Sector_VesselDimension/Sector_VesselBridge/Interactibles_VesselBridge/BlackHole");
GameObject newBlackHole = GameObject.Instantiate(blackHole, vesselWarpController.transform.parent, false);
newBlackHole.name = "BlackHole";
vesselWarpController._blackHole = newBlackHole.GetComponentInChildren<SingularityController>();
vesselWarpController._blackHoleOneShot = vesselWarpController._blackHole.transform.parent.Find("BlackHoleAudio_OneShot").GetComponent<OWAudioSource>();
GameObject whiteHole = SearchUtilities.Find("DB_VesselDimension_Body/Sector_VesselDimension/Sector_VesselBridge/Interactibles_VesselBridge/WhiteHole");
GameObject newWhiteHole = GameObject.Instantiate(whiteHole, vesselWarpController.transform.parent, false);
newWhiteHole.name = "WhiteHole";
vesselWarpController._whiteHole = newWhiteHole.GetComponentInChildren<SingularityController>();
vesselWarpController._whiteHoleOneShot = vesselWarpController._whiteHole.transform.parent.Find("WhiteHoleAudio_OneShot").GetComponent<OWAudioSource>();
vesselObject.SetActive(true);
vesselWarpController._targetWarpPlatform.OnReceiveWarpedBody += OnReceiveWarpedBody;
if (system.Config.warpExitPosition != null)
vesselWarpController._targetWarpPlatform.transform.localPosition = system.Config.warpExitPosition;
if (system.Config.warpExitRotation != null)
vesselObject.transform.localEulerAngles = system.Config.warpExitRotation;
vesselObject.GetComponent<MapMarker>()._labelID = (UITextType)TranslationHandler.AddUI("Vessel");
EyeSpawnPoint eyeSpawnPoint = vesselObject.GetComponentInChildren<EyeSpawnPoint>(true);
system.SpawnPoint = eyeSpawnPoint;
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => SetupWarpController(vesselWarpController));
return eyeSpawnPoint;
}
public static SpawnPoint UpdateVessel()
{
var system = SystemDict[Instance.CurrentStarSystem];
var vectorSector = SearchUtilities.Find("DB_VesselDimension_Body/Sector_VesselDimension");
var spawnPoint = vectorSector.GetComponentInChildren<SpawnPoint>();
system.SpawnPoint = spawnPoint;
VesselWarpController vesselWarpController = vectorSector.GetComponentInChildren<VesselWarpController>(true);
if (vesselWarpController._targetWarpPlatform != null)
vesselWarpController._targetWarpPlatform.OnReceiveWarpedBody += OnReceiveWarpedBody;
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => SetupWarpController(vesselWarpController, true));
return spawnPoint;
}
public static void SetupWarpController(VesselWarpController vesselWarpController, bool db = false)
{
if (db)
{
//Make warp core
foreach (WarpCoreItem core in Resources.FindObjectsOfTypeAll<WarpCoreItem>())
{
if (core.GetWarpCoreType().Equals(WarpCoreType.Vessel))
{
var newCore = GameObject.Instantiate(core, AstroObjectLocator.GetAstroObject("Vessel Dimension")?.transform ?? Locator.GetPlayerBody()?.transform);
newCore._visible = true;
foreach (OWRenderer render in newCore._renderers)
{
if (render)
{
render.enabled = true;
render.SetActivation(true);
render.SetLODActivation(true);
if (render.GetRenderer()) render.GetRenderer().enabled = true;
}
}
foreach (ParticleSystem particleSystem in newCore._particleSystems)
{
if (particleSystem) particleSystem.Play(true);
}
foreach (OWLight2 light in newCore._lights)
{
if (light)
{
light.enabled = true;
light.SetActivation(true);
light.SetLODActivation(true);
if (light.GetLight()) light.GetLight().enabled = true;
}
}
vesselWarpController._coreSocket.PlaceIntoSocket(newCore);
break;
}
}
}
vesselWarpController.OnSlotDeactivated(vesselWarpController._coordinatePowerSlot);
if (!db) vesselWarpController.OnSlotActivated(vesselWarpController._coordinatePowerSlot);
vesselWarpController._gravityVolume.SetFieldMagnitude(vesselWarpController._origGravityMagnitude);
vesselWarpController._coreCable.SetPowered(true);
vesselWarpController._coordinateCable.SetPowered(!db);
vesselWarpController._warpPlatformCable.SetPowered(false);
vesselWarpController._cageClosed = true;
if (vesselWarpController._cageAnimator != null)
{
vesselWarpController._cageAnimator.TranslateToLocalPosition(new Vector3(0.0f, -8.1f, 0.0f), 0.1f);
vesselWarpController._cageAnimator.RotateToLocalEulerAngles(new Vector3(0.0f, 180f, 0.0f), 0.1f);
vesselWarpController._cageAnimator.OnTranslationComplete -= new TransformAnimator.AnimationEvent(vesselWarpController.OnCageAnimationComplete);
vesselWarpController._cageAnimator.OnTranslationComplete += new TransformAnimator.AnimationEvent(vesselWarpController.OnCageAnimationComplete);
}
if (vesselWarpController._cageLoopingAudio != null)
vesselWarpController._cageLoopingAudio.FadeIn(1f);
}
}
}

View File

@ -1,10 +1,13 @@
using HarmonyLib;
using NewHorizons.AchievementsPlus;
using NewHorizons.Builder.Props;
using NewHorizons.Components;
using NewHorizons.External.Configs;
using NewHorizons.External;
using NewHorizons.External.Configs;
using NewHorizons.Handlers;
using NewHorizons.Utility;
using NewHorizons.Utility.DebugMenu;
using NewHorizons.Utility.DebugUtilities;
using OWML.Common;
using OWML.ModHelper;
using System;
@ -16,11 +19,7 @@ using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using Logger = NewHorizons.Utility.Logger;
using NewHorizons.Utility.DebugUtilities;
using Newtonsoft.Json;
using NewHorizons.Utility.DebugMenu;
using NewHorizons.AchievementsPlus;
namespace NewHorizons
{
@ -45,7 +44,8 @@ namespace NewHorizons
public static float FurthestOrbit { get; set; } = 50000f;
public string CurrentStarSystem { get { return Instance._currentStarSystem; } }
public bool IsWarping { get; private set; } = false;
public bool IsWarpingFromShip { get; private set; } = false;
public bool IsWarpingFromVessel { get; private set; } = false;
public bool WearingSuit { get; private set; } = false;
public bool IsChangingStarSystem { get; private set; } = false;
@ -57,6 +57,9 @@ namespace NewHorizons
private bool _firstLoad = true;
private ShipWarpController _shipWarpController;
// Vessel
private SpawnPoint _vesselSpawnPoint;
// API events
public class StarSystemEvent : UnityEvent<string> { }
public StarSystemEvent OnChangeStarSystem;
@ -110,7 +113,25 @@ namespace NewHorizons
{
Config =
{
destroyStockPlanets = false
destroyStockPlanets = false,
coords = new StarSystemConfig.NomaiCoordinates
{
x = new int[5]{ 0,3,2,1,5 },
y = new int[5]{ 4,5,3,2,1 },
z = new int[5]{ 4,1,2,5,0 }
}
}
};
SystemDict["EyeOfTheUniverse"] = new NewHorizonsSystem("EyeOfTheUniverse", new StarSystemConfig(), Instance)
{
Config =
{
coords = new StarSystemConfig.NomaiCoordinates
{
x = new int[3]{ 1,5,4 },
y = new int[4]{ 3,0,1,4 },
z = new int[6]{ 1,2,3,0,5,4 }
}
}
};
@ -135,6 +156,7 @@ namespace NewHorizons
GlobalMessenger.AddListener("WakeUp", OnWakeUp);
NHAssetBundle = ModHelper.Assets.LoadBundle("Assets/xen.newhorizons");
VesselWarpHandler.Initialize();
ResetConfigs(resetTranslation: false);
@ -161,8 +183,8 @@ namespace NewHorizons
Logger.Log($"Destroying NewHorizons");
SceneManager.sceneLoaded -= OnSceneLoaded;
GlobalMessenger<DeathType>.RemoveListener("PlayerDeath", OnDeath);
GlobalMessenger.RemoveListener("WakeUp", new Callback(OnWakeUp));
GlobalMessenger.RemoveListener("WakeUp", new Callback(OnWakeUp));
AchievementHandler.OnDestroy();
}
@ -171,6 +193,7 @@ namespace NewHorizons
IsSystemReady = true;
try
{
Logger.Log($"Star system loaded [{Instance.CurrentStarSystem}]");
Instance.OnStarSystemLoaded?.Invoke(Instance.CurrentStarSystem);
}
catch (Exception e)
@ -222,7 +245,7 @@ namespace NewHorizons
TitleSceneHandler.InitSubtitles();
}
if (scene.name == "EyeOfTheUniverse" && IsWarping)
if (scene.name == "EyeOfTheUniverse" && IsWarpingFromShip)
{
if (_ship != null) SceneManager.MoveGameObjectToScene(_ship, SceneManager.GetActiveScene());
_ship.transform.position = new Vector3(50, 0, 0);
@ -249,6 +272,10 @@ namespace NewHorizons
AstroObjectLocator.Init();
OWAssetHandler.Init();
PlanetCreationHandler.Init(BodyDict[CurrentStarSystem]);
if (IsWarpingFromVessel)
_vesselSpawnPoint = CurrentStarSystem == "SolarSystem" ? VesselWarpHandler.UpdateVessel() : VesselWarpHandler.CreateVessel();
else
_vesselSpawnPoint = SearchUtilities.Find("DB_VesselDimension_Body/Sector_VesselDimension").GetComponentInChildren<SpawnPoint>();
SystemCreationHandler.LoadSystem(SystemDict[CurrentStarSystem]);
LoadTranslations(ModHelper.Manifest.ModFolderPath + "Assets/", this);
@ -259,10 +286,12 @@ namespace NewHorizons
_shipWarpController.Init();
if (HasWarpDrive == true) EnableWarpDrive();
var shouldWarpIn = IsWarping && _shipWarpController != null;
Instance.ModHelper.Events.Unity.RunWhen(() => IsSystemReady, () => OnSystemReady(shouldWarpIn));
var shouldWarpInFromShip = IsWarpingFromShip && _shipWarpController != null;
var shouldWarpInFromVessel = IsWarpingFromVessel && _vesselSpawnPoint != null;
Instance.ModHelper.Events.Unity.RunWhen(() => IsSystemReady, () => OnSystemReady(shouldWarpInFromShip, shouldWarpInFromVessel));
IsWarping = false;
IsWarpingFromShip = false;
IsWarpingFromVessel = false;
var map = GameObject.FindObjectOfType<MapController>();
if (map != null) map._maxPanDistance = FurthestOrbit * 1.5f;
@ -277,7 +306,7 @@ namespace NewHorizons
if (SystemDict.Keys.Contains(_defaultSystemOverride))
{
_currentStarSystem = _defaultSystemOverride;
IsWarping = true; // always do this else sometimes the spawn gets messed up
IsWarpingFromShip = true; // always do this else sometimes the spawn gets messed up
}
else
{
@ -287,15 +316,20 @@ namespace NewHorizons
}
// Had a bunch of separate unity things firing stuff when the system is ready so I moved it all to here
private void OnSystemReady(bool shouldWarpIn)
private void OnSystemReady(bool shouldWarpInFromShip, bool shouldWarpInFromVessel)
{
Locator.GetPlayerBody().gameObject.AddComponent<DebugRaycaster>();
Locator.GetPlayerBody().gameObject.AddComponent<DebugPropPlacer>();
Locator.GetPlayerBody().gameObject.AddComponent<DebugPropPlacer>();
Locator.GetPlayerBody().gameObject.AddComponent<DebugNomaiTextPlacer>();
Locator.GetPlayerBody().gameObject.AddComponent<DebugMenu>();
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 (shouldWarpIn) _shipWarpController.WarpIn(WearingSuit);
if (shouldWarpInFromShip) _shipWarpController.WarpIn(WearingSuit);
else if (shouldWarpInFromVessel)
{
FindObjectOfType<PlayerSpawner>().DebugWarp(_vesselSpawnPoint);
Builder.General.SpawnPointBuilder.SuitUp();
}
else FindObjectOfType<PlayerSpawner>().DebugWarp(SystemDict[_currentStarSystem].SpawnPoint);
}
@ -329,20 +363,21 @@ namespace NewHorizons
var relativePath = file.Replace(folder, "");
var starSystemConfig = mod.ModHelper.Storage.Load<StarSystemConfig>(relativePath);
starSystemConfig.FixCoordinates();
if (starSystemConfig.startHere)
{
// We always want to allow mods to overwrite setting the main SolarSystem as default but not the other way around
if (name != "SolarSystem") SetDefaultSystem(name);
}
if (SystemDict.ContainsKey(name))
{
SystemDict[name].Config.Merge(starSystemConfig);
}
else
{
SystemDict[name] = new NewHorizonsSystem(name, starSystemConfig, mod);
if (SystemDict.ContainsKey(name))
{
SystemDict[name].Config.Merge(starSystemConfig);
}
else
{
SystemDict[name] = new NewHorizonsSystem(name, starSystemConfig, mod);
}
}
}
@ -363,18 +398,18 @@ namespace NewHorizons
BodyDict[body.Config.starSystem].Add(body);
}
}
}
// Has to go before translations for achievements
if (File.Exists(folder + "addon-manifest.json"))
{
var addonConfig = mod.ModHelper.Storage.Load<AddonConfig>("addon-manifest.json");
AchievementHandler.RegisterAddon(addonConfig, mod as ModBehaviour);
}
// Has to go before translations for achievements
if (File.Exists(folder + "addon-manifest.json"))
{
var addonConfig = mod.ModHelper.Storage.Load<AddonConfig>("addon-manifest.json");
AchievementHandler.RegisterAddon(addonConfig, mod as ModBehaviour);
}
if (Directory.Exists(folder + @"translations\"))
{
LoadTranslations(folder, mod);
}
}
}
catch (Exception ex)
@ -400,11 +435,11 @@ namespace NewHorizons
foundFile = true;
TranslationHandler.RegisterTranslation(language, config);
if (AchievementHandler.Enabled)
{
AchievementHandler.RegisterTranslationsFromFiles(mod as ModBehaviour, "translations");
TranslationHandler.RegisterTranslation(language, config);
if (AchievementHandler.Enabled)
{
AchievementHandler.RegisterTranslationsFromFiles(mod as ModBehaviour, "translations");
}
}
}
@ -418,15 +453,16 @@ namespace NewHorizons
{
var config = mod.ModHelper.Storage.Load<PlanetConfig>(relativeDirectory);
// var config = JsonConvert.DeserializeObject<PlanetConfig>(File.ReadAllText($"{mod.ModHelper.Manifest.ModFolderPath}/{relativeDirectory}"));
config.MigrateAndValidate();
Logger.Log($"Loaded {config.name}");
Logger.Log($"Loaded {config.name}");
if (!SystemDict.ContainsKey(config.starSystem))
{
// Since we didn't load it earlier there shouldn't be a star system config
var starSystemConfig = mod.ModHelper.Storage.Load<StarSystemConfig>($"systems/{config.starSystem}.json");
starSystemConfig.FixCoordinates();
if (starSystemConfig == null) starSystemConfig = new StarSystemConfig();
else Logger.LogWarning($"Loaded system config for {config.starSystem}. Why wasn't this loaded earlier?");
@ -456,11 +492,12 @@ namespace NewHorizons
#endregion Load
#region Change star system
public void ChangeCurrentStarSystem(string newStarSystem, bool warp = false)
public void ChangeCurrentStarSystem(string newStarSystem, bool warp = false, bool vessel = false)
{
if (IsChangingStarSystem) return;
IsWarping = warp;
IsWarpingFromShip = warp;
IsWarpingFromVessel = vessel;
OnChangeStarSystem?.Invoke(newStarSystem);
Logger.Log($"Warping to {newStarSystem}");
@ -488,7 +525,7 @@ namespace NewHorizons
_currentStarSystem = newStarSystem;
LoadManager.LoadSceneAsync(sceneToLoad, true, LoadManager.FadeType.ToBlack, 0.1f, true);
LoadManager.LoadSceneAsync(sceneToLoad, !vessel, LoadManager.FadeType.ToBlack, 0.1f, true);
}
void OnDeath(DeathType _)
@ -500,14 +537,14 @@ namespace NewHorizons
if (SystemDict.Keys.Contains(_defaultSystemOverride))
{
_currentStarSystem = _defaultSystemOverride;
IsWarping = true; // always do this else sometimes the spawn gets messed up
IsWarpingFromShip = true; // always do this else sometimes the spawn gets messed up
}
else
{
_currentStarSystem = _defaultStarSystem;
}
IsWarping = false;
IsWarpingFromShip = false;
}
}
#endregion Change star system

View File

@ -0,0 +1,74 @@
using HarmonyLib;
using NewHorizons.Utility;
using UnityEngine;
namespace NewHorizons.Patches
{
[HarmonyPatch]
public static class NomaiCoordinatePatches
{
[HarmonyPrefix]
[HarmonyPatch(typeof(NomaiCoordinateInterface), nameof(NomaiCoordinateInterface.SetPillarRaised), new System.Type[] { typeof(bool) })]
public static bool NomaiCoordinateInterface_SetPillarRaised(NomaiCoordinateInterface __instance, bool raised)
{
if (raised)
return !(!__instance._powered || (__instance.CheckEyeCoordinates() && Main.Instance.CurrentStarSystem != "EyeOfTheUniverse") || (__instance.CheckAllCoordinates(out string targetSystem) && Main.Instance.CurrentStarSystem != targetSystem));
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(VesselWarpController), nameof(VesselWarpController.WarpVessel))]
public static bool VesselWarpController_WarpVessel(VesselWarpController __instance, bool debugWarp)
{
if (!Main.Instance.IsWarpingFromVessel && TimeLoop.GetLoopCount() < 2)
Achievements.Earn(Achievements.Type.BEGINNERS_LUCK);
VesselWarpController.s_playerWarpLocation = new RelativeLocationData(Locator.GetPlayerBody(), __instance.transform);
VesselWarpController.s_relativeLocationSaved = !debugWarp;
if (!Main.Instance.IsWarpingFromVessel)
PlayerData.SaveWarpedToTheEye(TimeLoop.GetSecondsRemaining());
LoadManager.EnableAsyncLoadTransition();
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(VesselWarpController), nameof(VesselWarpController.CheckSystemActivation))]
public static void VesselWarpController_CheckSystemActivation(VesselWarpController __instance)
{
if (Locator.GetEyeStateManager() == null && Main.Instance.CurrentStarSystem != "EyeOfTheUniverse")
{
if (!__instance._sourceWarpPlatform.IsBlackHoleOpen() && __instance._hasPower && __instance._warpPlatformPowerSlot.IsActivated() && __instance._targetWarpPlatform != null)
__instance._sourceWarpPlatform.OpenBlackHole(__instance._targetWarpPlatform, true);
else if (__instance._sourceWarpPlatform.IsBlackHoleOpen() && (!__instance._hasPower || !__instance._warpPlatformPowerSlot.IsActivated()))
__instance._sourceWarpPlatform.CloseBlackHole();
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(VesselWarpController), nameof(VesselWarpController.OnSlotActivated))]
public static bool VesselWarpController_OnSlotActivated(VesselWarpController __instance, NomaiInterfaceSlot slot)
{
bool canWarpToEye = __instance._coordinateInterface.CheckEyeCoordinates();
bool canWarpToStarSystem = __instance._coordinateInterface.CheckAllCoordinates(out string targetSystem);
if (slot == __instance._warpVesselSlot && __instance._hasPower && (canWarpToEye || (canWarpToStarSystem && targetSystem != Main.Instance.CurrentStarSystem)) && __instance._blackHole.GetState() == SingularityController.State.Collapsed && LoadManager.GetCurrentScene() != OWScene.EyeOfTheUniverse)
{
__instance._blackHole.Create();
RumbleManager.StartVesselWarp();
__instance._openingBlackHole = true;
__instance.enabled = true;
Locator.GetPauseCommandListener().AddPauseCommandLock();
if (canWarpToEye || (canWarpToStarSystem && targetSystem == "EyeOfTheUniverse"))
LoadManager.LoadSceneAsync(OWScene.EyeOfTheUniverse, false, LoadManager.FadeType.ToWhite);
else if (canWarpToStarSystem)
Main.Instance.ChangeCurrentStarSystem(targetSystem, false, true);
__instance._blackHoleOneShot.PlayOneShot(AudioType.VesselSingularityCreate);
GlobalMessenger.FireEvent("StartVesselWarp");
}
else
{
if (slot == __instance._coordinatePowerSlot)
__instance._coordinateInterface.SetPillarRaised(true, true);
__instance.CheckSystemActivation();
}
return false;
}
}
}

View File

@ -1,9 +1,11 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using UnityEngine;
using NomaiCoordinates = NewHorizons.External.Configs.StarSystemConfig.NomaiCoordinates;
namespace NewHorizons.Utility
{
public static class NewHorizonsExtensions
@ -122,5 +124,30 @@ namespace NewHorizons.Utility
{
return transform.rotation * localRotation;
}
public static bool CheckAllCoordinates(this NomaiCoordinateInterface nomaiCoordinateInterface) => Main.SystemDict.Where(system => system.Value.Config.coords != null).Select(system => new KeyValuePair<string, NomaiCoordinates>(system.Key, system.Value.Config.coords)).Any(system => nomaiCoordinateInterface.CheckCoordinates(system.Key, system.Value));
public static bool CheckAllCoordinates(this NomaiCoordinateInterface nomaiCoordinateInterface, out string selectedSystem)
{
foreach (KeyValuePair<string, NomaiCoordinates> cbs in Main.SystemDict.Where(system => system.Value.Config.coords != null).Select(system => new KeyValuePair<string, NomaiCoordinates>(system.Key, system.Value.Config.coords)))
{
if (CheckCoordinates(nomaiCoordinateInterface, cbs.Key, cbs.Value))
{
selectedSystem = cbs.Key;
return true;
}
}
selectedSystem = null;
return false;
}
public static bool CheckCoordinates(this NomaiCoordinateInterface nomaiCoordinateInterface, string system, NomaiCoordinates coordinates)
{
bool xCorrect = nomaiCoordinateInterface._nodeControllers[0].CheckCoordinate(coordinates.x);
bool yCorrect = nomaiCoordinateInterface._nodeControllers[1].CheckCoordinate(coordinates.y);
bool zCorrect = nomaiCoordinateInterface._nodeControllers[2].CheckCoordinate(coordinates.z);
Utility.Logger.Log($"Coordinate Check for {system}: {xCorrect}, {yCorrect}, {zCorrect} [{string.Join("-", coordinates.x)}, {string.Join("-", coordinates.y)}, {string.Join("-", coordinates.z)}]");
return xCorrect && yCorrect && zCorrect;
}
}
}

View File

@ -51,7 +51,6 @@ namespace NewHorizons.Utility
public static T FindObjectOfTypeAndName<T>(string name) where T : Object
{
T[] firstList = GameObject.FindObjectsOfType<T>();
List<T> finalList = new List<T>();
for (var i = 0; i < firstList.Length; i++)
{