Nomai Coordinates

This commit is contained in:
Noah Pilarski 2022-06-15 11:10:28 -04:00
parent 29f6fb8908
commit df1bdc7b85
4 changed files with 137 additions and 2 deletions

View File

@ -1,4 +1,6 @@
using System.ComponentModel;
using System.Linq;
using NewHorizons.Utility;
using Newtonsoft.Json;
namespace NewHorizons.External.Configs
@ -56,6 +58,11 @@ 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;
public class NomaiCoordinates
{
public int[] x;
@ -81,5 +88,12 @@ namespace NewHorizons.External.Configs
/// </summary>
public string path;
}
public void FixCoordinates()
{
coords.x = coords.x.Distinct().ToArray();
coords.y = coords.y.Distinct().ToArray();
coords.z = coords.z.Distinct().ToArray();
}
}
}

View File

@ -108,7 +108,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("SolarSystem", 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 }
}
}
};
@ -326,6 +344,7 @@ namespace NewHorizons
var relativePath = file.Replace(folder, "");
var starSystemConfig = mod.ModHelper.Storage.Load<StarSystemConfig>(relativePath);
starSystemConfig.FixCoordinates();
if (starSystemConfig.startHere)
{
@ -405,6 +424,7 @@ namespace NewHorizons
{
// 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?");

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;
}
}
}