LethalCompany/Lethal Company/ExportedProject/Assets/Scripts/Assembly-CSharp/RadarBoosterItem.cs

345 lines
10 KiB
C#
Raw Normal View History

2023-12-23 00:30:32 +00:00
using System;
using Unity.Netcode;
2023-12-22 22:51:17 +00:00
using UnityEngine;
public class RadarBoosterItem : GrabbableObject
{
public bool radarEnabled;
2023-12-23 00:30:32 +00:00
public Animator radarBoosterAnimator;
2023-12-22 22:51:17 +00:00
public GameObject radarDot;
2023-12-23 00:30:32 +00:00
public AudioSource pingAudio;
public AudioClip pingSFX;
2023-12-22 22:51:17 +00:00
public AudioSource radarBoosterAudio;
public AudioClip turnOnSFX;
public AudioClip turnOffSFX;
2023-12-23 00:55:14 +00:00
public AudioClip flashSFX;
2023-12-23 00:30:32 +00:00
public string radarBoosterName;
private bool setRandomBoosterName;
private int timesPlayingPingAudioInOneSpot;
private Vector3 pingAudioLastPosition;
private float timeSincePlayingPingAudio;
private int radarBoosterNameIndex = -1;
2023-12-23 00:55:14 +00:00
private float flashCooldown;
public Transform radarSpherePosition;
2023-12-22 22:51:17 +00:00
public override void Start()
{
base.Start();
}
2023-12-23 00:30:32 +00:00
private void OnEnable()
{
}
private void OnDisable()
{
if (radarEnabled)
{
RemoveBoosterFromRadar();
}
}
public override int GetItemDataToSave()
{
base.GetItemDataToSave();
return radarBoosterNameIndex;
}
public override void LoadItemSaveData(int saveData)
{
base.LoadItemSaveData(saveData);
radarBoosterNameIndex = saveData;
}
2023-12-23 00:55:14 +00:00
public void FlashAndSync()
{
Flash();
RadarBoosterFlashServerRpc();
}
[ServerRpc(RequireOwnership = false)]
public void RadarBoosterFlashServerRpc()
{
NetworkManager networkManager = base.NetworkManager;
if ((object)networkManager != null && networkManager.IsListening)
{
if (__rpc_exec_stage != __RpcExecStage.Server && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams serverRpcParams = default(ServerRpcParams);
FastBufferWriter bufferWriter = __beginSendServerRpc(3971038271u, serverRpcParams, RpcDelivery.Reliable);
__endSendServerRpc(ref bufferWriter, 3971038271u, serverRpcParams, RpcDelivery.Reliable);
}
if (__rpc_exec_stage == __RpcExecStage.Server && (networkManager.IsServer || networkManager.IsHost))
{
RadarBoosterFlashClientRpc();
}
}
}
[ClientRpc]
public void RadarBoosterFlashClientRpc()
{
NetworkManager networkManager = base.NetworkManager;
if ((object)networkManager != null && networkManager.IsListening)
{
if (__rpc_exec_stage != __RpcExecStage.Client && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams clientRpcParams = default(ClientRpcParams);
FastBufferWriter bufferWriter = __beginSendClientRpc(720948839u, clientRpcParams, RpcDelivery.Reliable);
__endSendClientRpc(ref bufferWriter, 720948839u, clientRpcParams, RpcDelivery.Reliable);
}
if (__rpc_exec_stage == __RpcExecStage.Client && (networkManager.IsClient || networkManager.IsHost) && !(flashCooldown >= 0f))
{
Flash();
}
}
}
public void Flash()
{
if (radarEnabled && !(flashCooldown >= 0f))
{
flashCooldown = 2.25f;
radarBoosterAnimator.SetTrigger("Flash");
radarBoosterAudio.PlayOneShot(flashSFX);
WalkieTalkie.TransmitOneShotAudio(radarBoosterAudio, flashSFX);
2023-12-23 02:13:19 +00:00
StunGrenadeItem.StunExplosion(radarSpherePosition.position, affectAudio: false, 0.8f, 1.75f, 2f, isHeldItem: false, null, null, 0.3f);
2023-12-23 00:55:14 +00:00
}
}
2023-12-23 00:30:32 +00:00
public void SetRadarBoosterNameLocal(string newName)
{
radarBoosterName = newName;
base.gameObject.GetComponentInChildren<ScanNodeProperties>().headerText = radarBoosterName;
StartOfRound.Instance.mapScreen.ChangeNameOfTargetTransform(base.transform, newName);
}
private void RemoveBoosterFromRadar()
{
StartOfRound.Instance.mapScreen.RemoveTargetFromRadar(base.transform);
}
private void AddBoosterToRadar()
{
if (!setRandomBoosterName)
{
setRandomBoosterName = true;
int num = (radarBoosterNameIndex = ((radarBoosterNameIndex != -1) ? radarBoosterNameIndex : new System.Random(Mathf.Min(StartOfRound.Instance.randomMapSeed + (int)base.NetworkObjectId, 99999999)).Next(0, StartOfRound.Instance.randomNames.Length)));
radarBoosterName = StartOfRound.Instance.randomNames[num];
base.gameObject.GetComponentInChildren<ScanNodeProperties>().headerText = radarBoosterName;
}
string text = StartOfRound.Instance.mapScreen.AddTransformAsTargetToRadar(base.transform, radarBoosterName, isNonPlayer: true);
if (!string.IsNullOrEmpty(text))
{
base.gameObject.GetComponentInChildren<ScanNodeProperties>().headerText = text;
}
StartOfRound.Instance.mapScreen.SyncOrderOfRadarBoostersInList();
}
2023-12-22 22:51:17 +00:00
public void EnableRadarBooster(bool enable)
{
radarBoosterAnimator.SetBool("on", enable);
radarDot.SetActive(enable);
if (enable)
{
2023-12-23 00:30:32 +00:00
AddBoosterToRadar();
radarBoosterAudio.Play();
2023-12-22 22:51:17 +00:00
radarBoosterAudio.PlayOneShot(turnOnSFX);
WalkieTalkie.TransmitOneShotAudio(radarBoosterAudio, turnOnSFX);
}
else
{
2023-12-23 00:30:32 +00:00
RemoveBoosterFromRadar();
if (radarBoosterAudio.isPlaying)
{
radarBoosterAudio.Stop();
radarBoosterAudio.PlayOneShot(turnOffSFX);
WalkieTalkie.TransmitOneShotAudio(radarBoosterAudio, turnOffSFX);
}
2023-12-22 22:51:17 +00:00
}
radarEnabled = enable;
}
2023-12-23 00:30:32 +00:00
public void PlayPingAudio()
{
timesPlayingPingAudioInOneSpot += 2;
timeSincePlayingPingAudio = 0f;
pingAudio.PlayOneShot(pingSFX);
WalkieTalkie.TransmitOneShotAudio(pingAudio, pingSFX);
RoundManager.Instance.PlayAudibleNoise(pingAudio.transform.position, 12f, 0.8f, timesPlayingPingAudioInOneSpot, isInShipRoom && StartOfRound.Instance.hangarDoorsClosed, 1015);
}
public void PlayPingAudioAndSync()
{
PlayPingAudio();
PingRadarBoosterServerRpc((int)GameNetworkManager.Instance.localPlayerController.playerClientId);
}
[ServerRpc(RequireOwnership = false)]
public void PingRadarBoosterServerRpc(int playerWhoPlayedPing)
{
NetworkManager networkManager = base.NetworkManager;
if ((object)networkManager != null && networkManager.IsListening)
{
if (__rpc_exec_stage != __RpcExecStage.Server && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams serverRpcParams = default(ServerRpcParams);
FastBufferWriter bufferWriter = __beginSendServerRpc(577640837u, serverRpcParams, RpcDelivery.Reliable);
BytePacker.WriteValueBitPacked(bufferWriter, playerWhoPlayedPing);
__endSendServerRpc(ref bufferWriter, 577640837u, serverRpcParams, RpcDelivery.Reliable);
}
if (__rpc_exec_stage == __RpcExecStage.Server && (networkManager.IsServer || networkManager.IsHost))
{
PingRadarBoosterClientRpc(playerWhoPlayedPing);
}
}
}
[ClientRpc]
public void PingRadarBoosterClientRpc(int playerWhoPlayedPing)
{
NetworkManager networkManager = base.NetworkManager;
if ((object)networkManager != null && networkManager.IsListening)
{
if (__rpc_exec_stage != __RpcExecStage.Client && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams clientRpcParams = default(ClientRpcParams);
FastBufferWriter bufferWriter = __beginSendClientRpc(3675855655u, clientRpcParams, RpcDelivery.Reliable);
BytePacker.WriteValueBitPacked(bufferWriter, playerWhoPlayedPing);
__endSendClientRpc(ref bufferWriter, 3675855655u, clientRpcParams, RpcDelivery.Reliable);
}
if (__rpc_exec_stage == __RpcExecStage.Client && (networkManager.IsClient || networkManager.IsHost) && !(GameNetworkManager.Instance.localPlayerController == null) && playerWhoPlayedPing != (int)GameNetworkManager.Instance.localPlayerController.playerClientId)
{
PlayPingAudio();
}
}
}
public override void EquipItem()
{
base.EquipItem();
pingAudioLastPosition = base.transform.position;
}
2023-12-22 22:51:17 +00:00
public override void ItemActivate(bool used, bool buttonDown = true)
{
base.ItemActivate(used, buttonDown);
2023-12-23 00:30:32 +00:00
EnableRadarBooster(used);
2023-12-22 22:51:17 +00:00
}
public override void PocketItem()
{
2023-12-23 00:30:32 +00:00
base.PocketItem();
isBeingUsed = false;
EnableRadarBooster(enable: false);
2023-12-22 22:51:17 +00:00
}
public override void DiscardItem()
{
2023-12-23 00:30:32 +00:00
if (Vector3.Distance(base.transform.position, pingAudioLastPosition) > 5f)
{
timesPlayingPingAudioInOneSpot = 0;
}
2023-12-22 22:51:17 +00:00
base.DiscardItem();
}
public override void Update()
{
base.Update();
2023-12-23 00:30:32 +00:00
if (timeSincePlayingPingAudio > 5f)
{
timeSincePlayingPingAudio = 0f;
timesPlayingPingAudioInOneSpot = Mathf.Max(timesPlayingPingAudioInOneSpot - 1, 0);
}
else
{
timeSincePlayingPingAudio += Time.deltaTime;
}
2023-12-23 00:55:14 +00:00
if (flashCooldown >= 0f)
{
flashCooldown -= Time.deltaTime;
}
2023-12-22 22:51:17 +00:00
}
protected override void __initializeVariables()
{
base.__initializeVariables();
}
2023-12-23 00:30:32 +00:00
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_RadarBoosterItem()
{
2023-12-23 00:55:14 +00:00
NetworkManager.__rpc_func_table.Add(3971038271u, __rpc_handler_3971038271);
NetworkManager.__rpc_func_table.Add(720948839u, __rpc_handler_720948839);
2023-12-23 00:30:32 +00:00
NetworkManager.__rpc_func_table.Add(577640837u, __rpc_handler_577640837);
NetworkManager.__rpc_func_table.Add(3675855655u, __rpc_handler_3675855655);
}
2023-12-23 00:55:14 +00:00
private static void __rpc_handler_3971038271(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
NetworkManager networkManager = target.NetworkManager;
if ((object)networkManager != null && networkManager.IsListening)
{
target.__rpc_exec_stage = __RpcExecStage.Server;
((RadarBoosterItem)target).RadarBoosterFlashServerRpc();
target.__rpc_exec_stage = __RpcExecStage.None;
}
}
private static void __rpc_handler_720948839(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
NetworkManager networkManager = target.NetworkManager;
if ((object)networkManager != null && networkManager.IsListening)
{
target.__rpc_exec_stage = __RpcExecStage.Client;
((RadarBoosterItem)target).RadarBoosterFlashClientRpc();
target.__rpc_exec_stage = __RpcExecStage.None;
}
}
2023-12-23 00:30:32 +00:00
private static void __rpc_handler_577640837(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
NetworkManager networkManager = target.NetworkManager;
if ((object)networkManager != null && networkManager.IsListening)
{
ByteUnpacker.ReadValueBitPacked(reader, out int value);
target.__rpc_exec_stage = __RpcExecStage.Server;
((RadarBoosterItem)target).PingRadarBoosterServerRpc(value);
target.__rpc_exec_stage = __RpcExecStage.None;
}
}
private static void __rpc_handler_3675855655(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
NetworkManager networkManager = target.NetworkManager;
if ((object)networkManager != null && networkManager.IsListening)
{
ByteUnpacker.ReadValueBitPacked(reader, out int value);
target.__rpc_exec_stage = __RpcExecStage.Client;
((RadarBoosterItem)target).PingRadarBoosterClientRpc(value);
target.__rpc_exec_stage = __RpcExecStage.None;
}
}
2023-12-22 22:51:17 +00:00
protected internal override string __getTypeName()
{
return "RadarBoosterItem";
}
}