From f0f24b2777d120a2fe2072911064b271259a8fb0 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 1 Jul 2023 18:20:03 -0400 Subject: [PATCH 1/2] Adds a 5 second cooldown to warp transmitters after using return pad --- NewHorizons/Builder/Props/WarpPadBuilder.cs | 4 ++ .../NomaiWarpTransmitterCooldown.cs | 37 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 NewHorizons/Components/NomaiWarpTransmitterCooldown.cs diff --git a/NewHorizons/Builder/Props/WarpPadBuilder.cs b/NewHorizons/Builder/Props/WarpPadBuilder.cs index 07aa3e90..41bf6ed6 100644 --- a/NewHorizons/Builder/Props/WarpPadBuilder.cs +++ b/NewHorizons/Builder/Props/WarpPadBuilder.cs @@ -1,4 +1,5 @@ using NewHorizons.Builder.Props.TranslatorText; +using NewHorizons.Components; using NewHorizons.External.Modules.Props; using NewHorizons.External.Modules.WarpPad; using NewHorizons.Utility; @@ -137,6 +138,9 @@ namespace NewHorizons.Builder.Props transmitter.GetComponent().enabled = true; + // Prevents the transmitter from sending you straight back if you use the return function of the receiver #563 + transmitterObject.AddComponent(); + transmitterObject.SetActive(true); } diff --git a/NewHorizons/Components/NomaiWarpTransmitterCooldown.cs b/NewHorizons/Components/NomaiWarpTransmitterCooldown.cs new file mode 100644 index 00000000..bdf92fc9 --- /dev/null +++ b/NewHorizons/Components/NomaiWarpTransmitterCooldown.cs @@ -0,0 +1,37 @@ +using UnityEngine; + +namespace NewHorizons.Components +{ + public class NomaiWarpTransmitterCooldown : MonoBehaviour + { + private NomaiWarpTransmitter _transmitter; + private NomaiWarpReceiver _receiver; + + private float _reenabledTime = 0f; + private bool _cooldownActive; + + public void Start() + { + _transmitter = GetComponent(); + _transmitter.OnReceiveWarpedBody += _transmitter_OnReceiveWarpedBody; + } + + private void _transmitter_OnReceiveWarpedBody(OWRigidbody warpedBody, NomaiWarpPlatform startPlatform, NomaiWarpPlatform targetPlatform) + { + _cooldownActive = true; + + _reenabledTime = Time.time + 5f; + _receiver = _transmitter._targetReceiver; + _transmitter._targetReceiver = null; + } + + public void FixedUpdate() + { + if (_cooldownActive && Time.time > _reenabledTime) + { + _cooldownActive = false; + _transmitter._targetReceiver = _receiver; + } + } + } +} From 2509750c6b6fe763344e11d2fb80a662a8320177 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 3 Jul 2023 10:21:49 -0400 Subject: [PATCH 2/2] Disconnect transmitter OnReceiveWarpedBody event when destroyed --- NewHorizons/Components/NomaiWarpTransmitterCooldown.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/NewHorizons/Components/NomaiWarpTransmitterCooldown.cs b/NewHorizons/Components/NomaiWarpTransmitterCooldown.cs index bdf92fc9..f057b062 100644 --- a/NewHorizons/Components/NomaiWarpTransmitterCooldown.cs +++ b/NewHorizons/Components/NomaiWarpTransmitterCooldown.cs @@ -16,6 +16,14 @@ namespace NewHorizons.Components _transmitter.OnReceiveWarpedBody += _transmitter_OnReceiveWarpedBody; } + public void OnDestroy() + { + if (_transmitter != null) + { + _transmitter.OnReceiveWarpedBody -= _transmitter_OnReceiveWarpedBody; + } + } + private void _transmitter_OnReceiveWarpedBody(OWRigidbody warpedBody, NomaiWarpPlatform startPlatform, NomaiWarpPlatform targetPlatform) { _cooldownActive = true;