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; float endTime = 0.5f; bool windUp = false; bool hold = false; bool seq = false; bool end = false; bool raccoonCaught = true; public AttackState(StateMachine machine) : base(machine) { stateName = "Attack"; } public override void OnEnter() { timer = 0.0f; animator.PlayOneShot(ai.atkWindupAnim); windUp = true; hold = false; seq = false; end = false; timer = windupTime; raccoonCaught = false; RotateToVelocity rotate = machine.GetScript(); if (rotate) rotate.active = false; RigidBody rigid = machine.GetComponent(); if (rigid) { rigid.LinearVelocity = Vector3.Zero; } 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 OnExit() { RotateToVelocity rotate = ai.GetScript(); if (rotate) { rotate.active = true; rotate.lookAround = false; } //ai.attackHitbox.SetActive(false); machine.GetScript().atk = false; } public override void update() { if (ai.hitboxScript.raccoonFound && machine.GetScript().atk) { raccoonCaught = true; Transform pcTransform = ai.player.GetComponent(); ai.player.GetScript().Caught(); Transform netTransform = ai.attackHitbox.GetComponentInChildren(); if (pcTransform && netTransform) { pcTransform.GlobalPosition = netTransform.GlobalPosition; } } timer -= Time.DeltaTimeF; if (windUp) { if (timer <= 0.0f) { windUp = false; hold = true; animator.Play(ai.atkHoldAnim); timer = holdTime; //ai.attackHitbox.SetActive(true); //machine.GetScript().atk = true; } } else if (hold) { if (timer <= 0.0f) { hold = false; seq = true; animator.PlayOneShot(ai.atkSeqAnim); timer = seqTime; } } else if (seq) { if (timer <= seqTime * 0.5f) { //ai.attackHitbox.SetActive(true); machine.GetScript().atk = true; } if (timer <= 0.0f) { seq = false; end = true; timer = endTime; } } else if (end) { if (timer <= 0.0f) { end = false; if(raccoonCaught) { machine.SetState(typeof(CaughtRaccoonState)); } else { AILineOfSight los = ai.GetScript(); if (los && los.withinSight) { machine.SetState(typeof(ChaseState)); } else { machine.SetState(typeof(TimeoutState)); } } } } } public override void fixedUpdate() { } } }