Move all goofy signal stuff to patch (cloaks/qm signals)

Note that QM stuff will only work if u disable its signal probably
This commit is contained in:
Nick 2022-07-25 21:27:51 -04:00
parent 2e49a1df23
commit 17ae3585a7
3 changed files with 101 additions and 82 deletions

View File

@ -21,6 +21,9 @@ namespace NewHorizons.Builder.Props
private static int _nextCustomFrequencyName;
public static int NumberOfFrequencies;
public static List<SignalName> QMSignals { get; private set; }
public static List<SignalName> CloakedSignals { get; private set; }
public static void Init()
{
@ -70,7 +73,10 @@ namespace NewHorizons.Builder.Props
};
_nextCustomSignalName = 200;
_nextCustomFrequencyName = 256;
NumberOfFrequencies = 8;
NumberOfFrequencies = 8;
QMSignals = new List<SignalName>() { SignalName.Quantum_QM };
CloakedSignals = new List<SignalName>();
}
public static SignalFrequency AddFrequency(string str)
@ -135,11 +141,9 @@ namespace NewHorizons.Builder.Props
var source = signalGO.AddComponent<AudioSource>();
var owAudioSource = signalGO.AddComponent<OWAudioSource>();
owAudioSource._audioSource = source;
owAudioSource._audioSource = source;
AudioSignal audioSignal;
if (info.insideCloak) audioSignal = signalGO.AddComponent<CloakedAudioSignal>();
else audioSignal = signalGO.AddComponent<AudioSignal>();
var audioSignal = signalGO.AddComponent<AudioSignal>();
audioSignal._owAudioSource = owAudioSource;
var frequency = StringToFrequency(info.frequency);
@ -204,6 +208,10 @@ namespace NewHorizons.Builder.Props
signalGO.SetActive(true);
signalDetectionGO.SetActive(true);
// Track certain special signal things
if (planetGO.GetComponent<AstroObject>()?.GetAstroObjectName() == AstroObject.Name.QuantumMoon) QMSignals.Add(name);
if (info.insideCloak) CloakedSignals.Add(name);
return signalGO;
}

View File

@ -1,72 +0,0 @@
using UnityEngine;
namespace NewHorizons.Components
{
public class CloakedAudioSignal : AudioSignal
{
public new void UpdateSignalStrength(Signalscope scope, float distToClosestScopeObstruction)
{
this._canBePickedUpByScope = false;
if (!PlayerState.InCloakingField())
{
this._signalStrength = 0f;
this._degreesFromScope = 180f;
return;
}
if (this._sunController != null && this._sunController.IsPointInsideSupernova(base.transform.position))
{
this._signalStrength = 0f;
this._degreesFromScope = 180f;
return;
}
if (Locator.GetQuantumMoon() != null && Locator.GetQuantumMoon().IsPlayerInside() && this._name != SignalName.Quantum_QM)
{
this._signalStrength = 0f;
this._degreesFromScope = 180f;
return;
}
if (!this._active || !base.gameObject.activeInHierarchy || this._outerFogWarpVolume != PlayerState.GetOuterFogWarpVolume() || (scope.GetFrequencyFilter() & this._frequency) != this._frequency)
{
this._signalStrength = 0f;
this._degreesFromScope = 180f;
return;
}
this._scopeToSignal = base.transform.position - scope.transform.position;
this._distToScope = this._scopeToSignal.magnitude;
if (this._outerFogWarpVolume == null && distToClosestScopeObstruction < 1000f && this._distToScope > 1000f)
{
this._signalStrength = 0f;
this._degreesFromScope = 180f;
return;
}
this._canBePickedUpByScope = true;
if (this._distToScope < this._sourceRadius)
{
this._signalStrength = 1f;
}
else
{
this._degreesFromScope = Vector3.Angle(scope.GetScopeDirection(), this._scopeToSignal);
float t = Mathf.InverseLerp(2000f, 1000f, this._distToScope);
float a = Mathf.Lerp(45f, 90f, t);
float a2 = 57.29578f * Mathf.Atan2(this._sourceRadius, this._distToScope);
float b = Mathf.Lerp(Mathf.Max(a2, 5f), Mathf.Max(a2, 1f), scope.GetZoomFraction());
this._signalStrength = Mathf.Clamp01(Mathf.InverseLerp(a, b, this._degreesFromScope));
}
if (this._distToScope < this._identificationDistance + this._sourceRadius && this._signalStrength > 0.9f)
{
if (!PlayerData.KnowsFrequency(this._frequency) && !this._preventIdentification)
{
this.IdentifyFrequency();
}
if (!PlayerData.KnowsSignal(this._name) && !this._preventIdentification)
{
this.IdentifySignal();
}
if (this._revealFactID.Length > 0)
{
Locator.GetShipLogManager().RevealFact(this._revealFactID, true, true);
}
}
}
}
}

View File

@ -115,15 +115,98 @@ namespace NewHorizons.Patches
[HarmonyPrefix]
[HarmonyPatch(typeof(AudioSignal), nameof(AudioSignal.UpdateSignalStrength))]
public static bool AudioSignal_UpdateSignalStrength(AudioSignal __instance, Signalscope __0, float __1)
public static bool AudioSignal_UpdateSignalStrength(AudioSignal __instance, Signalscope scope, float distToClosestScopeObstruction)
{
// I hate this, just because I can't override the base method in CloakedAudioSignal
if (__instance is CloakedAudioSignal)
if (!SignalBuilder.CloakedSignals.Contains(__instance._name) && !SignalBuilder.QMSignals.Contains(__instance._name)) return true;
__instance._canBePickedUpByScope = false;
if (__instance._sunController != null && __instance._sunController.IsPointInsideSupernova(__instance.transform.position))
{
((CloakedAudioSignal)__instance).UpdateSignalStrength(__0, __1);
__instance._signalStrength = 0f;
__instance._degreesFromScope = 180f;
return false;
}
return true;
// This part is modified from the original to include all QM signals
if (Locator.GetQuantumMoon() != null && Locator.GetQuantumMoon().IsPlayerInside() && !SignalBuilder.QMSignals.Contains(__instance._name))
{
__instance._signalStrength = 0f;
__instance._degreesFromScope = 180f;
return false;
}
if (!__instance._active || !__instance.gameObject.activeInHierarchy || __instance._outerFogWarpVolume != PlayerState.GetOuterFogWarpVolume() || (scope.GetFrequencyFilter() & __instance._frequency) != __instance._frequency)
{
__instance._signalStrength = 0f;
__instance._degreesFromScope = 180f;
return false;
}
__instance._scopeToSignal = __instance.transform.position - scope.transform.position;
__instance._distToScope = __instance._scopeToSignal.magnitude;
if (__instance._outerFogWarpVolume == null && distToClosestScopeObstruction < 1000f && __instance._distToScope > 1000f)
{
__instance._signalStrength = 0f;
__instance._degreesFromScope = 180f;
return false;
}
__instance._canBePickedUpByScope = true;
if (__instance._distToScope < __instance._sourceRadius)
{
__instance._signalStrength = 1f;
}
else
{
__instance._degreesFromScope = Vector3.Angle(scope.GetScopeDirection(), __instance._scopeToSignal);
float t = Mathf.InverseLerp(2000f, 1000f, __instance._distToScope);
float a = Mathf.Lerp(45f, 90f, t);
float a2 = 57.29578f * Mathf.Atan2(__instance._sourceRadius, __instance._distToScope);
float b = Mathf.Lerp(Mathf.Max(a2, 5f), Mathf.Max(a2, 1f), scope.GetZoomFraction());
__instance._signalStrength = Mathf.Clamp01(Mathf.InverseLerp(a, b, __instance._degreesFromScope));
}
// If it's a cloaked signal we don't want to hear it outside the cloak field
if (SignalBuilder.CloakedSignals.Contains(__instance._name))
{
if (!PlayerState.InCloakingField())
{
__instance._signalStrength = 0f;
__instance._degreesFromScope = 180f;
return false;
}
}
else
{
// This part is taken from the regular method
if (Locator.GetCloakFieldController() != null)
{
float num = 1f - Locator.GetCloakFieldController().playerCloakFactor;
__instance._signalStrength *= num;
if (OWMath.ApproxEquals(num, 0f, 0.001f))
{
__instance._signalStrength = 0f;
__instance._degreesFromScope = 180f;
return false;
}
}
}
if (__instance._distToScope < __instance._identificationDistance + __instance._sourceRadius && __instance._signalStrength > 0.9f)
{
if (!PlayerData.KnowsFrequency(__instance._frequency) && !__instance._preventIdentification)
{
__instance.IdentifyFrequency();
}
if (!PlayerData.KnowsSignal(__instance._name) && !__instance._preventIdentification)
{
__instance.IdentifySignal();
}
if (__instance._revealFactID.Length > 0)
{
Locator.GetShipLogManager().RevealFact(__instance._revealFactID, true, true);
}
}
return false;
}
[HarmonyPrefix]