Adds a 5 second cooldown to warp transmitters after using return pad (#618)

<!-- Some improvement that requires no action on the part of add-on
creators i.e., improved star graphics -->
## Improvements
- Added a 5 second delay to warp transmitters after you come back
through the return pad. Means 360 degree alignment target actually works
when returning through it instead of sending you straight back.
(resolves #563)
This commit is contained in:
Nick 2023-07-03 10:43:16 -04:00 committed by GitHub
commit fcfe685c22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 0 deletions

View File

@ -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<BoxShape>().enabled = true;
// Prevents the transmitter from sending you straight back if you use the return function of the receiver #563
transmitterObject.AddComponent<NomaiWarpTransmitterCooldown>();
transmitterObject.SetActive(true);
}

View File

@ -0,0 +1,45 @@
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<NomaiWarpTransmitter>();
_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;
_reenabledTime = Time.time + 5f;
_receiver = _transmitter._targetReceiver;
_transmitter._targetReceiver = null;
}
public void FixedUpdate()
{
if (_cooldownActive && Time.time > _reenabledTime)
{
_cooldownActive = false;
_transmitter._targetReceiver = _receiver;
}
}
}
}