using SHADE; using SHADE.Test; using SHADE_Scripting.Audio; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States { public class ChaseState :AIBaseState { float giveUpDuration = 10.0f; float giveUpTimer = 0.0f; float atkDistance = 1.0f; bool run = true; float footStepInterval = 12.0f / 30.0f; float footStepTimer = 0.0f; public ChaseState(StateMachine machine): base(machine) { stateName = "Chase"; } public override void OnEnter() { giveUpTimer = giveUpDuration; animator.Play(ai.alertRunAnim); run = true; RotateToVelocity r = machine.GetScript(); if (r) { r.rotateToPlayerLastKnown = true; } footStepTimer = footStepInterval * 0.5f; } public override void OnExit() { animator.Stop(); RotateToVelocity r = machine.GetScript(); if (r) { r.rotateToPlayerLastKnown = false; } RotateToVelocity rotate = ai.GetScript(); if (rotate) { rotate.lookAround = false; } } public override void update() { Navigation nav = machine.GetComponent(); AILineOfSight los = ai.GetScript(); RigidBody rigid = machine.GetComponent(); if (los && nav) { Transform playerTransform = los.player.GetComponent(); if (los.withinSight) { nav.MoveTo(playerTransform.GlobalPosition); } else { nav.MoveTo(los.lastFoundPos); giveUpTimer -= Time.DeltaTimeF; } if(los.lastFoundTimer>= 10.0f || giveUpTimer <= 0.0f) { machine.SetState(typeof(TimeoutState)); } if(los.distance < atkDistance) { machine.SetState(typeof(AttackState)); } if(rigid) { if (los.withinSight) rigid.LinearVelocity = nav.GetForward() * ai.chaseSpeed; else rigid.LinearVelocity = nav.GetForward() * ai.chaseSpeed; } if(nav.ReachedTarget()) { giveUpTimer -= Time.DeltaTimeF; ai.RotateToPlayer(); RotateToVelocity rotate = ai.GetScript(); if(rotate) { rotate.lookAround = true; } } } if (animator && rigid) { if (rigid.LinearVelocity.GetMagnitude() < 0.001f) { if(run) { animator.Play(ai.idleAnim); run = false; } } else { if(!run) { animator.Play(ai.alertRunAnim); run = true; } } } footStepTimer -= Time.DeltaTimeF; if (footStepTimer <= 0.0f) { footStepTimer += footStepInterval; AudioHandler.audioClipHandlers["HO_footsteps"].Play(); } } public override void fixedUpdate() { } } }