Merge pull request #72 from xen-42/cloak

Cloak
This commit is contained in:
Nick 2022-03-20 21:37:29 -04:00 committed by GitHub
commit 9e05f5a49e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 136 additions and 4 deletions

1
.github/FUNDING.yml vendored
View File

@ -1 +1,2 @@
patreon: xen_42
custom: ["https://paypal.me/xen42"]

View File

@ -0,0 +1,44 @@
using NewHorizons.Components;
using NewHorizons.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Builder.Body
{
static class CloakBuilder
{
public static void Make(GameObject body, Sector sector, float radius)
{
var cloak = SearchUtilities.Find("RingWorld_Body/CloakingField_IP");
var newCloak = GameObject.Instantiate(cloak, body.transform);
newCloak.transform.localPosition = Vector3.zero;
newCloak.transform.name = "CloakingField";
newCloak.transform.localScale = Vector3.one * radius;
GameObject.Destroy(newCloak.GetComponent<PlayerCloakEntryRedirector>());
var cloakFieldController = newCloak.GetComponent<CloakFieldController>();
cloakFieldController._cloakScaleDist = radius * 2000 / 3000f;
cloakFieldController._farCloakRadius = radius * 500 / 3000f;
cloakFieldController._innerCloakRadius = radius * 900 / 3000f;
cloakFieldController._nearCloakRadius = radius * 800 / 3000f;
cloakFieldController._referenceFrameVolume = null;
cloakFieldController._exclusionSector = null;
var cloakSectorController = newCloak.AddComponent<CloakSectorController>();
cloakSectorController.Init(newCloak.GetComponent<CloakFieldController>(), body);
newCloak.SetActive(true);
cloakFieldController.enabled = true;
// To cloak from the start
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(cloakSectorController.OnPlayerExit);
}
}
}

View File

@ -211,9 +211,14 @@ namespace NewHorizons.Builder.General
HeavenlyBodyBuilder.Remove(ao);
}
public static void RemoveDistantProxyClones()
public static void RemoveAllProxies()
{
GameObject.Destroy(GameObject.FindObjectOfType<DistantProxyManager>().gameObject);
foreach(var name in _solarSystemBodies)
{
RemoveProxy(name.Replace(" ", "").Replace("'", ""));
}
}
private static void DisableBody(GameObject go, bool delete)
@ -233,6 +238,9 @@ namespace NewHorizons.Builder.General
if (distantProxy != null) GameObject.Destroy(distantProxy.gameObject);
if (distantProxyClone != null) GameObject.Destroy(distantProxyClone.gameObject);
if (distantProxy == null && distantProxyClone == null)
Logger.Log($"Couldn't find proxy for {name}");
}
}
}

View File

@ -18,7 +18,7 @@ namespace NewHorizons.Builder.Updater
public static void Update(NewHorizonsBody body, GameObject go)
{
var mapping = Planet.defaultMapping;
var heavenlyBody = CommonResourcesUtilities.HeavenlyBodyFromAstroObject(AstroObjectLocator.GetAstroObject(body.Config.Name));
var heavenlyBody = CommonResourcesUtilities.HeavenlyBodyFromAstroObject(go.GetComponent<AstroObject>());
Logger.Log($"Updating position of {body.Config.Name}/{heavenlyBody}");

View File

@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Components
{
public class CloakSectorController : MonoBehaviour
{
private CloakFieldController _cloak;
private GameObject _root;
private bool _isInitialized;
private List<Renderer> _renderers = null;
public void Init(CloakFieldController cloak, GameObject root)
{
_cloak = cloak;
_root = root;
// Lets just clear these off idc
_cloak.OnPlayerEnter = new OWEvent();
_cloak.OnPlayerExit = new OWEvent();
_cloak.OnPlayerEnter += OnPlayerEnter;
_cloak.OnPlayerExit += OnPlayerExit;
_isInitialized = true;
}
void OnDestroy()
{
if(_isInitialized)
{
_cloak.OnPlayerEnter -= OnPlayerEnter;
_cloak.OnPlayerExit -= OnPlayerExit;
}
}
private void SetUpList()
{
_renderers = _root.GetComponentsInChildren<Renderer>().ToList();
}
public void OnPlayerEnter()
{
SetUpList();
foreach (var renderer in _renderers)
{
renderer.forceRenderingOff = false;
}
}
public void OnPlayerExit()
{
SetUpList();
foreach (var renderer in _renderers)
{
renderer.forceRenderingOff = true;
}
}
}
}

View File

@ -21,6 +21,7 @@ namespace NewHorizons.External
public bool HasReferenceFrame { get; set; } = true;
public bool CenterOfSolarSystem { get; set; } = false;
public bool IsSatellite { get; set; }
public float CloakRadius { get; set; } = 0f;
// Old, see SingularityModule instead
public float BlackHoleSize { get; set; }

View File

@ -102,7 +102,7 @@ namespace NewHorizons.Handlers
Logger.Log("Done loading bodies");
// I don't know what these do but they look really weird from a distance
Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => PlanetDestroyer.RemoveDistantProxyClones(), 1);
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(PlanetDestroyer.RemoveAllProxies);
if (Main.Instance.CurrentStarSystem != "SolarSystem") PlanetDestroyer.RemoveSolarSystem();
}
@ -351,6 +351,10 @@ namespace NewHorizons.Handlers
if (body.Config.Funnel != null)
FunnelBuilder.Make(go, go.GetComponentInChildren<ConstantForceDetector>(), rb, body.Config.Funnel);
// Has to go last probably
if (body.Config.Base.CloakRadius != 0f)
CloakBuilder.Make(go, sector, body.Config.Base.CloakRadius);
return go;
}

View File

@ -13,6 +13,11 @@ namespace NewHorizons.Utility.CommonResources
{
public static HeavenlyBody HeavenlyBodyFromAstroObject(AstroObject obj)
{
if(obj == null)
{
Logger.LogError("Asking for a heavenly body from astro object but it is null");
}
switch (obj.GetAstroObjectName())
{
case AstroObject.Name.CustomString:

View File

@ -3,7 +3,7 @@
"author": "xen, Idiot, & Book",
"name": "New Horizons",
"uniqueName": "xen.NewHorizons",
"version": "0.9.5",
"version": "0.10.0",
"owmlVersion": "2.1.0",
"dependencies": [ "PacificEngine.OW_CommonResources" ],
"conflicts": [ "Raicuparta.QuantumSpaceBuddies", "Vesper.OuterWildsMMO", "Vesper.AutoResume" ],

View File

@ -2,6 +2,7 @@
[![Support me on Patreon](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Dxen_42%26type%3Dpatrons&style=flat)](https://patreon.com/xen_42)
[![Donate](https://img.shields.io/badge/Donate-PayPal-blue.svg)](https://www.paypal.com/paypalme/xen42)
![Current version](https://img.shields.io/github/manifest-json/v/xen-42/outer-wilds-new-horizons?color=gree&filename=NewHorizons%2Fmanifest.json)
![Downloads](https://img.shields.io/github/downloads/xen-42/outer-wilds-new-horizons/total)
![Downloads of newest version](https://img.shields.io/github/downloads/xen-42/outer-wilds-new-horizons/latest/total)