using SHADE; 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 AttackState: AIBaseState { float timer = 0.0f; float windupTime = 8.0f / 30.0f; float holdTime = 0.3f; float seqTime = 8.0f / 30.0f + 0.5f; bool windUp = false; bool hold = false; bool seq = false; public AttackState(StateMachine machine): base(machine) { } public override void OnEnter() { timer = 0.0f; animator.PlayOneShot(ai.atkWindupAnim); windUp = true; hold = false; seq = false; timer = windupTime; RotateToVelocity rotate = machine.GetScript(); if (rotate) rotate.active = false; RigidBody rigid = machine.GetComponent(); if(rigid) { rigid.LinearVelocity = Vector3.Zero; } ai.attackHitbox.SetActive(false); } public override void OnExit() { animator.Stop(); RotateToVelocity rotate = ai.GetScript(); if (rotate) { rotate.active = true; rotate.lookAround = false; } Transform transform = machine.GetComponent(); AILineOfSight los = machine.GetScript(); Transform playerTransform = ai.player.GetComponent(); if(los && transform) { Vector3 direction = playerTransform.GlobalPosition - transform.GlobalPosition; Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(direction.x, direction.z), 0.0f); transform.LocalRotation = targetRotation; } ai.attackHitbox.SetActive(false); } public override void update() { timer -= Time.DeltaTimeF; if(windUp) { if(timer <= 0.0f) { windUp = false; hold = true; animator.Play(ai.atkHoldAnim); timer = holdTime; ai.attackHitbox.SetActive(true); } } else if(hold) { if(timer <= 0.0f) { hold = false; seq = true; animator.PlayOneShot(ai.atkSeqAnim); timer = seqTime; } } else if(seq) { if(timer <= 0.0f) { seq = false; AILineOfSight los = ai.GetScript(); if(los && los.withinSight) { machine.SetState(typeof(ChaseState)); } else { machine.SetState(typeof(TimeoutState)); } } } } public override void fixedUpdate() { } } }