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

101 lines
2.6 KiB
C#
Raw Normal View History

2023-12-22 22:51:17 +00:00
using GameNetcodeStuff;
using Unity.Netcode;
using UnityEngine;
public class EnemyAICollisionDetect : MonoBehaviour, IHittable, INoiseListener, IShockableWithGun
{
public EnemyAI mainScript;
public bool canCollideWithEnemies;
2023-12-23 00:55:14 +00:00
public bool onlyCollideWhenGrounded;
2023-12-22 22:51:17 +00:00
private void OnTriggerStay(Collider other)
{
if (other.CompareTag("Player"))
{
2023-12-23 00:55:14 +00:00
if (onlyCollideWhenGrounded)
{
CharacterController component = other.gameObject.GetComponent<CharacterController>();
if (!(component != null) || !component.isGrounded)
{
return;
}
mainScript.OnCollideWithPlayer(other);
}
2023-12-22 22:51:17 +00:00
mainScript.OnCollideWithPlayer(other);
}
2023-12-23 00:55:14 +00:00
else if (!onlyCollideWhenGrounded && canCollideWithEnemies && other.CompareTag("Enemy"))
2023-12-22 22:51:17 +00:00
{
2023-12-23 00:55:14 +00:00
EnemyAICollisionDetect component2 = other.gameObject.GetComponent<EnemyAICollisionDetect>();
if (component2 != null && component2.mainScript != mainScript)
2023-12-22 22:51:17 +00:00
{
2023-12-23 00:55:14 +00:00
mainScript.OnCollideWithEnemy(other, component2.mainScript);
2023-12-22 22:51:17 +00:00
}
}
}
2023-12-23 02:13:19 +00:00
bool IHittable.Hit(int force, Vector3 hitDirection, PlayerControllerB playerWhoHit, bool playHitSFX)
2023-12-22 22:51:17 +00:00
{
2023-12-23 02:13:19 +00:00
if (onlyCollideWhenGrounded)
2023-12-23 00:55:14 +00:00
{
2023-12-23 02:13:19 +00:00
Debug.Log("Enemy collision detect returned false");
return false;
2023-12-23 00:55:14 +00:00
}
2023-12-23 02:13:19 +00:00
mainScript.HitEnemyOnLocalClient(force, hitDirection, playerWhoHit, playHitSFX);
return true;
2023-12-22 22:51:17 +00:00
}
void INoiseListener.DetectNoise(Vector3 noisePosition, float noiseLoudness, int timesNoisePlayedInOneSpot, int noiseID)
{
2023-12-23 00:55:14 +00:00
if (!onlyCollideWhenGrounded)
{
mainScript.DetectNoise(noisePosition, noiseLoudness, timesNoisePlayedInOneSpot, noiseID);
}
2023-12-22 22:51:17 +00:00
}
bool IShockableWithGun.CanBeShocked()
{
2023-12-23 00:55:14 +00:00
if (!onlyCollideWhenGrounded && mainScript.postStunInvincibilityTimer <= 0f && mainScript.enemyType.canBeStunned)
2023-12-22 22:51:17 +00:00
{
return !mainScript.isEnemyDead;
}
return false;
}
Vector3 IShockableWithGun.GetShockablePosition()
{
if (mainScript.eye != null)
{
return mainScript.eye.position;
}
2023-12-23 00:30:32 +00:00
return base.transform.position + Vector3.up * 0.5f;
2023-12-22 22:51:17 +00:00
}
float IShockableWithGun.GetDifficultyMultiplier()
{
return mainScript.enemyType.stunGameDifficultyMultiplier;
}
void IShockableWithGun.ShockWithGun(PlayerControllerB shockedByPlayer)
{
mainScript.SetEnemyStunned(setToStunned: true, 0.25f, shockedByPlayer);
mainScript.stunnedIndefinitely++;
}
Transform IShockableWithGun.GetShockableTransform()
{
return base.transform;
}
NetworkObject IShockableWithGun.GetNetworkObject()
{
return mainScript.NetworkObject;
}
void IShockableWithGun.StopShockingWithGun()
{
mainScript.stunnedIndefinitely = Mathf.Clamp(mainScript.stunnedIndefinitely - 1, 0, 100);
}
}