using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Reflection.PortableExecutable; using System.Text; using System.Threading.Tasks; using SHADE; 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; [NonSerialized] public IEnumerable patrolPointPool; public void Reset() { Transform transform = GetComponent(); 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); } patrolPointPool = patrolPointParent.GetComponentsInChildren(); Transform transform = GetComponent(); if (transform) { startPos = transform.GlobalPosition; } } protected override void start() { attackHitbox.SetActive(false); } 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(); if(machine) { if (Input.GetKeyDown(Input.KeyCode.F)) { machine.SetState(typeof(AlertState)); } if(Input.GetKeyDown(Input.KeyCode.L)) { machine.SetState(typeof(IdleState)); } } } } }