LethalCompany/Lethal Company/ExportedProject/Assets/Scripts/Assembly-CSharp/ShipTeleporter.cs
2023-12-22 18:30:10 -05:00

188 lines
5.9 KiB
C#

using System.Collections;
using GameNetcodeStuff;
using Unity.Netcode;
using UnityEngine;
public class ShipTeleporter : NetworkBehaviour
{
public Transform teleporterPosition;
public Animator teleporterAnimator;
public Animator buttonAnimator;
public AudioSource buttonAudio;
public AudioSource shipTeleporterAudio;
public AudioClip buttonPressSFX;
public AudioClip teleporterSpinSFX;
public AudioClip teleporterBeamUpSFX;
public AudioClip beamUpPlayerBodySFX;
private Coroutine beamUpPlayerCoroutine;
public void PressTeleportButtonOnLocalClient()
{
PressTeleportButtonServerRpc();
}
[ServerRpc(RequireOwnership = false)]
public void PressTeleportButtonServerRpc()
{
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(389447712u, serverRpcParams, RpcDelivery.Reliable);
__endSendServerRpc(ref bufferWriter, 389447712u, serverRpcParams, RpcDelivery.Reliable);
}
if (__rpc_exec_stage == __RpcExecStage.Server && (networkManager.IsServer || networkManager.IsHost))
{
PressTeleportButtonClientRpc();
}
}
}
[ClientRpc]
public void PressTeleportButtonClientRpc()
{
NetworkManager networkManager = base.NetworkManager;
if ((object)networkManager == null || !networkManager.IsListening)
{
return;
}
if (__rpc_exec_stage != __RpcExecStage.Client && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams clientRpcParams = default(ClientRpcParams);
FastBufferWriter bufferWriter = __beginSendClientRpc(2773756087u, clientRpcParams, RpcDelivery.Reliable);
__endSendClientRpc(ref bufferWriter, 2773756087u, clientRpcParams, RpcDelivery.Reliable);
}
if (__rpc_exec_stage == __RpcExecStage.Client && (networkManager.IsClient || networkManager.IsHost))
{
PressButtonEffects();
if (beamUpPlayerCoroutine != null)
{
StopCoroutine(beamUpPlayerCoroutine);
}
beamUpPlayerCoroutine = StartCoroutine(beamUpPlayer());
}
}
private void PressButtonEffects()
{
buttonAnimator.SetTrigger("press");
buttonAnimator.SetBool("GlassOpen", value: false);
buttonAnimator.GetComponentInChildren<AnimatedObjectTrigger>().boolValue = false;
teleporterAnimator.SetTrigger("useTeleporter");
buttonAudio.PlayOneShot(buttonPressSFX);
WalkieTalkie.TransmitOneShotAudio(buttonAudio, buttonPressSFX);
}
private IEnumerator beamUpPlayer()
{
shipTeleporterAudio.PlayOneShot(teleporterSpinSFX);
PlayerControllerB playerToBeamUp = StartOfRound.Instance.mapScreen.targetPlayer;
if (playerToBeamUp == null)
{
yield break;
}
if (playerToBeamUp.deadBody != null)
{
if (playerToBeamUp.deadBody.beamUpParticle == null)
{
yield break;
}
playerToBeamUp.deadBody.beamUpParticle.Play();
playerToBeamUp.deadBody.bodyAudio.PlayOneShot(beamUpPlayerBodySFX);
}
else
{
playerToBeamUp.beamUpParticle.Play();
playerToBeamUp.movementAudio.PlayOneShot(beamUpPlayerBodySFX);
}
yield return new WaitForSeconds(3f);
bool flag;
if (playerToBeamUp.deadBody != null)
{
flag = true;
playerToBeamUp.deadBody.attachedTo = null;
playerToBeamUp.deadBody.attachedLimb = null;
playerToBeamUp.deadBody.secondaryAttachedLimb = null;
playerToBeamUp.deadBody.secondaryAttachedTo = null;
playerToBeamUp.deadBody.SetRagdollPositionSafely(teleporterPosition.position, disableSpecialEffects: true);
playerToBeamUp.deadBody.transform.SetParent(StartOfRound.Instance.elevatorTransform, worldPositionStays: true);
if (playerToBeamUp.deadBody.grabBodyObject != null && playerToBeamUp.deadBody.grabBodyObject.isHeld && playerToBeamUp.deadBody.grabBodyObject.playerHeldBy != null)
{
playerToBeamUp.deadBody.grabBodyObject.playerHeldBy.DropAllHeldItems();
}
}
else
{
flag = true;
playerToBeamUp.DropAllHeldItems();
if (Object.FindObjectOfType<AudioReverbPresets>() != null)
{
playerToBeamUp.reverbPreset = Object.FindObjectOfType<AudioReverbPresets>().audioPresets[3].reverbPreset;
}
playerToBeamUp.isInElevator = true;
playerToBeamUp.isInHangarShipRoom = true;
playerToBeamUp.isInsideFactory = false;
playerToBeamUp.averageVelocity = 0f;
playerToBeamUp.velocityLastFrame = Vector3.zero;
playerToBeamUp.TeleportPlayer(teleporterPosition.position, withRotation: true, 160f);
}
if (flag)
{
shipTeleporterAudio.PlayOneShot(teleporterBeamUpSFX);
if (GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom)
{
HUDManager.Instance.ShakeCamera(ScreenShakeType.Big);
}
}
}
protected override void __initializeVariables()
{
base.__initializeVariables();
}
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_ShipTeleporter()
{
NetworkManager.__rpc_func_table.Add(389447712u, __rpc_handler_389447712);
NetworkManager.__rpc_func_table.Add(2773756087u, __rpc_handler_2773756087);
}
private static void __rpc_handler_389447712(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
NetworkManager networkManager = target.NetworkManager;
if ((object)networkManager != null && networkManager.IsListening)
{
target.__rpc_exec_stage = __RpcExecStage.Server;
((ShipTeleporter)target).PressTeleportButtonServerRpc();
target.__rpc_exec_stage = __RpcExecStage.None;
}
}
private static void __rpc_handler_2773756087(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
NetworkManager networkManager = target.NetworkManager;
if ((object)networkManager != null && networkManager.IsListening)
{
target.__rpc_exec_stage = __RpcExecStage.Client;
((ShipTeleporter)target).PressTeleportButtonClientRpc();
target.__rpc_exec_stage = __RpcExecStage.None;
}
}
protected internal override string __getTypeName()
{
return "ShipTeleporter";
}
}