using System; using System.Collections.Generic; using SHADE; using SHADE_Scripting.Audio; using SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States; namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework { public class HomeOwnerAI : Script { public float idleDuration = 1.0f; public float timeoutDuration = 2.0f; public GameObject patrolPointParent; public float patrolSpeed = 2.0f; public float chaseSpeed = 3.0f; public float alertCooldown = 0.0f; public GameObject player; public GameObject attackHitbox; public AnimationClipAsset walkingAnim; public AnimationClipAsset idleAnim; public AnimationClipAsset alertAnim; public AnimationClipAsset alertRunAnim; public AnimationClipAsset alertIdleAnim; public AnimationClipAsset timeoutAnim; public AnimationClipAsset atkWindupAnim; public AnimationClipAsset atkHoldAnim; public AnimationClipAsset atkSeqAnim; private Vector3 startPos; public bool atk { get; set; } [NonSerialized] public IEnumerable patrolPointPool; private Transform transform; public void Reset() { StateMachine machine = GetScript(); if (transform && machine) { transform.GlobalPosition = startPos; machine.SetState(typeof(IdleState)); } } protected override void awake() { StateMachine machine = GetScript(); if (machine) { Dictionary dictionary = new Dictionary(); dictionary.Add(typeof(IdleState), new IdleState(machine)); dictionary.Add(typeof(PatrolState), new PatrolState(machine)); dictionary.Add(typeof(TimeoutState), new TimeoutState(machine)); dictionary.Add(typeof(ChaseState), new ChaseState(machine)); dictionary.Add(typeof(AlertState), new AlertState(machine)); dictionary.Add(typeof(AttackState), new AttackState(machine)); machine.InitStateMachine(dictionary); } AudioHandler.audioClipHandlers["HO_footsteps"] = SHADE.Audio.CreateAudioClip("event:/Homeowner/homeowner_footsteps"); patrolPointPool = patrolPointParent.GetComponentsInChildren(); transform = GetComponent(); atk = false; } protected override void start() { //attackHitbox.SetActive(false); if (transform) startPos = transform.GlobalPosition; } protected override void update() { if (alertCooldown > 0.0f) { alertCooldown -= Time.DeltaTimeF; } else { alertCooldown = 0.0f; } AICheat(); } public bool ShouldTransitAlert() { AILineOfSight los = GetScript(); if (los) { if (los.withinSight && alertCooldown <= 0.0f) { return true; } } return false; } public void RotateToPlayer() { //Transform playerTransform = player.GetComponent(); ////Rotate to face player. //Transform aiTransform = GetComponent(); //if(playerTransform && aiTransform) //{ // Vector3 direction = playerTransform.GlobalPosition - aiTransform.GlobalPosition; // Quaternion currentRotation = aiTransform.LocalRotation; // Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(direction.x, direction.z), 0.0f); // aiTransform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, 5.0f * (float)Time.FixedDeltaTime); //} } private void AICheat() { StateMachine machine = GetScript(); AILineOfSight los = GetScript(); if (machine && los) { if (Input.GetKeyDown(Input.KeyCode.K)) { los.range = 5.0f; machine.SetState(typeof(AlertState)); } if (Input.GetKeyDown(Input.KeyCode.L)) { los.range = 0.0f; machine.SetState(typeof(IdleState)); } } } } }