2023-12-22 22:51:17 +00:00
|
|
|
using System.Collections;
|
|
|
|
using GameNetcodeStuff;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class StunGrenadeItem : GrabbableObject
|
|
|
|
{
|
2023-12-23 00:55:14 +00:00
|
|
|
[Header("Stun grenade settings")]
|
|
|
|
public float TimeToExplode = 2.25f;
|
|
|
|
|
|
|
|
public bool DestroyGrenade;
|
|
|
|
|
|
|
|
public string playerAnimation = "PullGrenadePin";
|
|
|
|
|
|
|
|
[Space(3f)]
|
2023-12-22 22:51:17 +00:00
|
|
|
public bool pinPulled;
|
|
|
|
|
|
|
|
public bool inPullingPinAnimation;
|
|
|
|
|
|
|
|
private Coroutine pullPinCoroutine;
|
|
|
|
|
|
|
|
public Animator itemAnimator;
|
|
|
|
|
|
|
|
public AudioSource itemAudio;
|
|
|
|
|
|
|
|
public AudioClip pullPinSFX;
|
|
|
|
|
|
|
|
public AudioClip explodeSFX;
|
|
|
|
|
|
|
|
public AnimationCurve grenadeFallCurve;
|
|
|
|
|
|
|
|
public AnimationCurve grenadeVerticalFallCurve;
|
|
|
|
|
|
|
|
public AnimationCurve grenadeVerticalFallCurveNoBounce;
|
|
|
|
|
|
|
|
public RaycastHit grenadeHit;
|
|
|
|
|
|
|
|
public Ray grenadeThrowRay;
|
|
|
|
|
|
|
|
public float explodeTimer;
|
|
|
|
|
|
|
|
public bool hasExploded;
|
|
|
|
|
|
|
|
public GameObject stunGrenadeExplosion;
|
|
|
|
|
|
|
|
private PlayerControllerB playerThrownBy;
|
|
|
|
|
|
|
|
public override void ItemActivate(bool used, bool buttonDown = true)
|
|
|
|
{
|
|
|
|
base.ItemActivate(used, buttonDown);
|
|
|
|
if (inPullingPinAnimation)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!pinPulled)
|
|
|
|
{
|
|
|
|
if (pullPinCoroutine == null)
|
|
|
|
{
|
|
|
|
playerHeldBy.activatingItem = true;
|
|
|
|
pullPinCoroutine = StartCoroutine(pullPinAnimation());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (base.IsOwner)
|
|
|
|
{
|
|
|
|
playerHeldBy.DiscardHeldObject(placeObject: true, null, GetGrenadeThrowDestination());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-23 00:55:14 +00:00
|
|
|
public override void DiscardItem()
|
|
|
|
{
|
|
|
|
if (playerHeldBy != null)
|
|
|
|
{
|
|
|
|
playerHeldBy.activatingItem = false;
|
|
|
|
}
|
|
|
|
base.DiscardItem();
|
|
|
|
}
|
|
|
|
|
2023-12-22 22:51:17 +00:00
|
|
|
public override void EquipItem()
|
|
|
|
{
|
|
|
|
SetControlTipForGrenade();
|
|
|
|
EnableItemMeshes(enable: true);
|
|
|
|
isPocketed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetControlTipForGrenade()
|
|
|
|
{
|
|
|
|
string[] allLines = ((!pinPulled) ? new string[1] { "Pull pin: [RMB]" } : new string[1] { "Throw grenade: [RMB]" });
|
|
|
|
if (base.IsOwner)
|
|
|
|
{
|
|
|
|
HUDManager.Instance.ChangeControlTipMultiple(allLines, holdingItem: true, itemProperties);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void FallWithCurve()
|
|
|
|
{
|
|
|
|
float magnitude = (startFallingPosition - targetFloorPosition).magnitude;
|
|
|
|
base.transform.rotation = Quaternion.Lerp(base.transform.rotation, Quaternion.Euler(itemProperties.restingRotation.x, base.transform.eulerAngles.y, itemProperties.restingRotation.z), 14f * Time.deltaTime / magnitude);
|
|
|
|
base.transform.localPosition = Vector3.Lerp(startFallingPosition, targetFloorPosition, grenadeFallCurve.Evaluate(fallTime));
|
|
|
|
if (magnitude > 5f)
|
|
|
|
{
|
|
|
|
base.transform.localPosition = Vector3.Lerp(new Vector3(base.transform.localPosition.x, startFallingPosition.y, base.transform.localPosition.z), new Vector3(base.transform.localPosition.x, targetFloorPosition.y, base.transform.localPosition.z), grenadeVerticalFallCurveNoBounce.Evaluate(fallTime));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
base.transform.localPosition = Vector3.Lerp(new Vector3(base.transform.localPosition.x, startFallingPosition.y, base.transform.localPosition.z), new Vector3(base.transform.localPosition.x, targetFloorPosition.y, base.transform.localPosition.z), grenadeVerticalFallCurve.Evaluate(fallTime));
|
|
|
|
}
|
|
|
|
fallTime += Mathf.Abs(Time.deltaTime * 12f / magnitude);
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerator pullPinAnimation()
|
|
|
|
{
|
|
|
|
inPullingPinAnimation = true;
|
|
|
|
playerHeldBy.activatingItem = true;
|
|
|
|
playerHeldBy.doingUpperBodyEmote = 1.16f;
|
2023-12-23 00:55:14 +00:00
|
|
|
playerHeldBy.playerBodyAnimator.SetTrigger(playerAnimation);
|
2023-12-22 22:51:17 +00:00
|
|
|
itemAnimator.SetTrigger("pullPin");
|
|
|
|
itemAudio.PlayOneShot(pullPinSFX);
|
|
|
|
WalkieTalkie.TransmitOneShotAudio(itemAudio, pullPinSFX, 0.8f);
|
|
|
|
yield return new WaitForSeconds(1f);
|
|
|
|
if (playerHeldBy != null)
|
|
|
|
{
|
2023-12-23 00:55:14 +00:00
|
|
|
if (!DestroyGrenade)
|
|
|
|
{
|
|
|
|
playerHeldBy.activatingItem = false;
|
|
|
|
}
|
2023-12-22 22:51:17 +00:00
|
|
|
playerThrownBy = playerHeldBy;
|
|
|
|
}
|
|
|
|
inPullingPinAnimation = false;
|
|
|
|
pinPulled = true;
|
|
|
|
itemUsedUp = true;
|
|
|
|
if (base.IsOwner && playerHeldBy != null)
|
|
|
|
{
|
|
|
|
SetControlTipForGrenade();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
if (pinPulled && !hasExploded)
|
|
|
|
{
|
|
|
|
explodeTimer += Time.deltaTime;
|
2023-12-23 00:55:14 +00:00
|
|
|
if (explodeTimer > TimeToExplode)
|
2023-12-22 22:51:17 +00:00
|
|
|
{
|
2023-12-23 00:55:14 +00:00
|
|
|
ExplodeStunGrenade(DestroyGrenade);
|
2023-12-22 22:51:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-23 00:55:14 +00:00
|
|
|
private void ExplodeStunGrenade(bool destroy = false)
|
2023-12-22 22:51:17 +00:00
|
|
|
{
|
2023-12-23 00:55:14 +00:00
|
|
|
if (!hasExploded)
|
|
|
|
{
|
|
|
|
hasExploded = true;
|
|
|
|
itemAudio.PlayOneShot(explodeSFX);
|
|
|
|
WalkieTalkie.TransmitOneShotAudio(itemAudio, explodeSFX);
|
|
|
|
Object.Instantiate(parent: (!isInElevator) ? RoundManager.Instance.mapPropsContainer.transform : StartOfRound.Instance.elevatorTransform, original: stunGrenadeExplosion, position: base.transform.position, rotation: Quaternion.identity);
|
|
|
|
StunExplosion(base.transform.position, affectAudio: true, 1f, 7.5f, 1f, isHeld, playerHeldBy, playerThrownBy);
|
|
|
|
if (DestroyGrenade)
|
|
|
|
{
|
|
|
|
DestroyObjectInHand(playerThrownBy);
|
|
|
|
}
|
2023-12-22 22:51:17 +00:00
|
|
|
}
|
2023-12-23 00:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void StunExplosion(Vector3 explosionPosition, bool affectAudio, float flashSeverityMultiplier, float enemyStunTime, float flashSeverityDistanceRolloff = 1f, bool isHeldItem = false, PlayerControllerB playerHeldBy = null, PlayerControllerB playerThrownBy = null)
|
|
|
|
{
|
2023-12-22 22:51:17 +00:00
|
|
|
PlayerControllerB playerControllerB = GameNetworkManager.Instance.localPlayerController;
|
|
|
|
if (GameNetworkManager.Instance.localPlayerController.isPlayerDead && GameNetworkManager.Instance.localPlayerController.spectatedPlayerScript != null)
|
|
|
|
{
|
|
|
|
playerControllerB = GameNetworkManager.Instance.localPlayerController.spectatedPlayerScript;
|
|
|
|
}
|
2023-12-23 00:55:14 +00:00
|
|
|
float num = Vector3.Distance(playerControllerB.transform.position, explosionPosition);
|
|
|
|
float num2 = 7f / (num * flashSeverityDistanceRolloff);
|
|
|
|
if (Physics.Linecast(explosionPosition + Vector3.up * 0.5f, playerControllerB.gameplayCamera.transform.position, StartOfRound.Instance.collidersAndRoomMaskAndDefault, QueryTriggerInteraction.Ignore))
|
2023-12-22 22:51:17 +00:00
|
|
|
{
|
|
|
|
num2 /= 13f;
|
|
|
|
}
|
|
|
|
else if (num < 2f)
|
|
|
|
{
|
|
|
|
num2 = 1f;
|
|
|
|
}
|
2023-12-23 00:55:14 +00:00
|
|
|
else if (!playerControllerB.HasLineOfSightToPosition(explosionPosition, 60f, 15, 2f))
|
2023-12-22 22:51:17 +00:00
|
|
|
{
|
|
|
|
num2 = Mathf.Clamp(num2 / 3f, 0f, 1f);
|
|
|
|
}
|
2023-12-23 00:55:14 +00:00
|
|
|
if (isHeldItem && playerHeldBy == GameNetworkManager.Instance.localPlayerController)
|
2023-12-22 22:51:17 +00:00
|
|
|
{
|
|
|
|
num2 = 1f;
|
2023-12-23 00:30:32 +00:00
|
|
|
GameNetworkManager.Instance.localPlayerController.DamagePlayer(20, hasDamageSFX: false, callRPC: true, CauseOfDeath.Blast);
|
2023-12-22 22:51:17 +00:00
|
|
|
}
|
2023-12-23 00:55:14 +00:00
|
|
|
num2 = Mathf.Clamp(num2 * flashSeverityMultiplier, 0f, 1f);
|
2023-12-22 22:51:17 +00:00
|
|
|
HUDManager.Instance.flashbangScreenFilter.weight = num2;
|
2023-12-23 00:55:14 +00:00
|
|
|
if (affectAudio)
|
|
|
|
{
|
|
|
|
SoundManager.Instance.earsRingingTimer = num2;
|
|
|
|
}
|
|
|
|
if (enemyStunTime <= 0f)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Collider[] array = Physics.OverlapSphere(explosionPosition, 12f, 524288);
|
2023-12-22 22:51:17 +00:00
|
|
|
if (array.Length == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < array.Length; i++)
|
|
|
|
{
|
|
|
|
EnemyAICollisionDetect component = array[i].GetComponent<EnemyAICollisionDetect>();
|
|
|
|
if (component == null)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Vector3 b = component.mainScript.transform.position + Vector3.up * 0.5f;
|
2023-12-23 00:55:14 +00:00
|
|
|
if (component.mainScript.HasLineOfSightToPosition(explosionPosition + Vector3.up * 0.5f, 120f, 23, 7f) || (!Physics.Linecast(explosionPosition + Vector3.up * 0.5f, component.mainScript.transform.position + Vector3.up * 0.5f, 256) && Vector3.Distance(explosionPosition, b) < 11f))
|
2023-12-22 22:51:17 +00:00
|
|
|
{
|
|
|
|
if (playerThrownBy != null)
|
|
|
|
{
|
2023-12-23 00:55:14 +00:00
|
|
|
component.mainScript.SetEnemyStunned(setToStunned: true, enemyStunTime, playerThrownBy);
|
2023-12-22 22:51:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-12-23 00:55:14 +00:00
|
|
|
component.mainScript.SetEnemyStunned(setToStunned: true, enemyStunTime);
|
2023-12-22 22:51:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Vector3 GetGrenadeThrowDestination()
|
|
|
|
{
|
|
|
|
Vector3 position = base.transform.position;
|
|
|
|
Debug.DrawRay(playerHeldBy.gameplayCamera.transform.position, playerHeldBy.gameplayCamera.transform.forward, Color.yellow, 15f);
|
|
|
|
grenadeThrowRay = new Ray(playerHeldBy.gameplayCamera.transform.position, playerHeldBy.gameplayCamera.transform.forward);
|
|
|
|
position = ((!Physics.Raycast(grenadeThrowRay, out grenadeHit, 12f, StartOfRound.Instance.collidersAndRoomMaskAndDefault)) ? grenadeThrowRay.GetPoint(10f) : grenadeThrowRay.GetPoint(grenadeHit.distance - 0.05f));
|
|
|
|
Debug.DrawRay(position, Vector3.down, Color.blue, 15f);
|
|
|
|
grenadeThrowRay = new Ray(position, Vector3.down);
|
|
|
|
if (Physics.Raycast(grenadeThrowRay, out grenadeHit, 30f, StartOfRound.Instance.collidersAndRoomMaskAndDefault))
|
|
|
|
{
|
|
|
|
return grenadeHit.point + Vector3.up * 0.05f;
|
|
|
|
}
|
|
|
|
return grenadeThrowRay.GetPoint(30f);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void __initializeVariables()
|
|
|
|
{
|
|
|
|
base.__initializeVariables();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected internal override string __getTypeName()
|
|
|
|
{
|
|
|
|
return "StunGrenadeItem";
|
|
|
|
}
|
|
|
|
}
|