Fix shuttles/gravity cannons, add comment describing patch

This commit is contained in:
Nick 2023-12-17 00:17:49 -05:00
parent 865327d79f
commit 9b435e3452
3 changed files with 8 additions and 61 deletions

View File

@ -1,5 +1,4 @@
using NewHorizons.Builder.Props.TranslatorText;
using NewHorizons.Components.Orbital;
using NewHorizons.External.Modules;
using NewHorizons.External.Modules.Props;
using NewHorizons.External.Modules.Props.Shuttle;
@ -18,7 +17,6 @@ namespace NewHorizons.Builder.Props
{
private static GameObject _interfacePrefab;
private static GameObject _detailedPlatformPrefab, _platformPrefab;
private static GameObject _orbPrefab;
internal static void InitPrefab()
{
@ -59,21 +57,13 @@ namespace NewHorizons.Builder.Props
GameObject.DestroyImmediate(_platformPrefab.FindChild("Structure_NOM_GravityCannon_Crystals"));
GameObject.DestroyImmediate(_platformPrefab.FindChild("Structure_NOM_GravityCannon_Geo"));
}
if (_orbPrefab == null)
{
_orbPrefab = SearchUtilities.Find("Prefab_NOM_InterfaceOrb")
.InstantiateInactive()
.Rename("Prefab_NOM_InterfaceOrb")
.DontDestroyOnLoad();
}
}
public static GameObject Make(GameObject planetGO, Sector sector, GravityCannonInfo info, IModBehaviour mod)
{
InitPrefab();
if (_interfacePrefab == null || planetGO == null || sector == null || _detailedPlatformPrefab == null || _platformPrefab == null || _orbPrefab == null) return null;
if (_interfacePrefab == null || planetGO == null || sector == null || _detailedPlatformPrefab == null || _platformPrefab == null) return null;
var detailInfo = new DetailInfo(info.controls) { keepLoaded = true };
var gravityCannonObject = DetailBuilder.Make(planetGO, sector, _interfacePrefab, detailInfo);
@ -102,56 +92,11 @@ namespace NewHorizons.Builder.Props
gravityCannonController._nomaiComputer = null;
}
CreateOrb(planetGO, gravityCannonController);
gravityCannonObject.SetActive(true);
return gravityCannonObject;
}
private static void CreateOrb(GameObject planetGO, GravityCannonController gravityCannonController)
{
var orb = _orbPrefab.InstantiateInactive().Rename(_orbPrefab.name);
orb.transform.parent = gravityCannonController.transform;
orb.transform.localPosition = new Vector3(0f, 0.9673f, 0f);
orb.transform.localScale = Vector3.one;
orb.SetActive(true);
var planetBody = planetGO.GetComponent<OWRigidbody>();
var orbBody = orb.GetComponent<OWRigidbody>();
var nomaiInterfaceOrb = orb.GetComponent<NomaiInterfaceOrb>();
nomaiInterfaceOrb._orbBody = orbBody;
nomaiInterfaceOrb._slotRoot = gravityCannonController.gameObject;
orbBody._origParent = planetGO.transform;
orbBody._origParentBody = planetBody;
nomaiInterfaceOrb._slots = nomaiInterfaceOrb._slotRoot.GetComponentsInChildren<NomaiInterfaceSlot>();
nomaiInterfaceOrb.SetParentBody(planetBody);
nomaiInterfaceOrb._safetyRails = new OWRail[0];
nomaiInterfaceOrb.RemoveAllLocks();
var spawnVelocity = planetBody.GetVelocity();
var spawnAngularVelocity = planetBody.GetPointTangentialVelocity(orbBody.transform.position);
var velocity = spawnVelocity + spawnAngularVelocity;
orbBody._lastVelocity = velocity;
orbBody._currentVelocity = velocity;
// detect planet gravity
// somehow Intervention has GetAttachedOWRigidbody as null sometimes, idk why
var gravityVolume = planetGO.GetAttachedOWRigidbody()?.GetAttachedGravityVolume();
orb.GetComponent<ConstantForceDetector>()._detectableFields = gravityVolume ? new ForceVolume[] { gravityVolume } : new ForceVolume[0];
Delay.RunWhenAndInNUpdates(() =>
{
foreach (var component in orb.GetComponents<MonoBehaviour>())
{
component.enabled = true;
}
nomaiInterfaceOrb.RemoveAllLocks();
}, () => Main.IsSystemReady, 10);
}
private static NomaiComputer CreateComputer(GameObject planetGO, Sector sector, GeneralPropInfo computerInfo, NomaiShuttleController.ShuttleID id)
{
// Load the position info from the GeneralPropInfo

View File

@ -11,7 +11,6 @@ namespace NewHorizons.Builder.Props
public static class ShuttleBuilder
{
private static GameObject _prefab;
private static GameObject _orbPrefab;
private static GameObject _bodyPrefab;
public static Dictionary<NomaiShuttleController.ShuttleID, NomaiShuttleController> Shuttles { get; } = new();
@ -52,9 +51,9 @@ namespace NewHorizons.Builder.Props
neutralSlot._attractive = true;
neutralSlot._muteAudio = true;
nhShuttleController._neutralSlot = neutralSlot;
// TODO: at some point delay rigidbody parenting so we dont have to find orb via references. mainly to fix orbs on existing details and rafts not rotating with planets
_orbPrefab = shuttleController._orb.gameObject?.InstantiateInactive()?.Rename("Prefab_QM_Shuttle_InterfaceOrbSmall")?.DontDestroyOnLoad();
nhShuttleController._orb = _orbPrefab.GetComponent<NomaiInterfaceOrb>();
var orb = shuttleController._orb.gameObject;
nhShuttleController._orb = orb.GetComponent<NomaiInterfaceOrb>();
nhShuttleController._orb._sector = nhShuttleController._interiorSector;
nhShuttleController._orb._slotRoot = slots;
nhShuttleController._orb._safetyRails = slots.GetComponentsInChildren<OWRail>();
@ -87,7 +86,7 @@ namespace NewHorizons.Builder.Props
shuttleController._cannon = Locator.GetGravityCannon(id);
GameObject slots = shuttleObject.FindChild("Sector_NomaiShuttleInterior/Interactibles_NomaiShuttleInterior/ControlPanel/Slots");
GameObject orbObject = _orbPrefab.InstantiateInactive().Rename("InterfaceOrbSmall");
GameObject orbObject = shuttleController._orb.gameObject;
orbObject.transform.SetParent(slots.transform, false);
orbObject.transform.localPosition = new Vector3(-0.0153f, -0.2386f, 0.0205f);
shuttleController._orb = orbObject.GetComponent<NomaiInterfaceOrb>();

View File

@ -7,6 +7,9 @@ namespace NewHorizons.Patches;
/// <summary>
/// From QSB
///
/// By delaying rigidbody stuff here we make copying objects with orbs work properly
/// Should also improve rafts
/// </summary>
[HarmonyPatch(typeof(OWRigidbody))]
public static class OWRigidbodyPatches