using Invector.vCharacterController.AI.FSMBehaviour; using UnityEngine; namespace ArcherEnemy { /// /// Decision checking if archer can shoot /// Checks cooldown, aiming, and射ing AI component readiness /// [CreateAssetMenu(menuName = "Invector/FSM/Decisions/Archer/Can Shoot")] public class DEC_CanShoot : vStateDecision { public override string categoryName => "Archer/Combat"; public override string defaultName => "Can Shoot"; [Header("Configuration")] [Tooltip("Check if archer is facing target within tolerance")] public bool checkFacingTarget = true; [Tooltip("Angle tolerance for shooting (degrees)")] public float aimTolerance = 20f; [Header("Debug")] [Tooltip("Enable debug logging")] public bool enableDebug = false; public override bool Decide(vIFSMBehaviourController fsmBehaviour) { // Get ArcherShootingAI component var shootingAI = fsmBehaviour.gameObject.GetComponent(); if (shootingAI == null) { if (enableDebug) Debug.LogWarning("[DEC_CanShoot] No ArcherShootingAI component found!"); return false; } // Use the shooting AI's CanShoot method bool canShoot = shootingAI.CanShoot(); // Optional: additional facing check if (canShoot && checkFacingTarget) { Transform target = shootingAI.GetTarget(); if (target != null) { Vector3 directionToTarget = (target.position - fsmBehaviour.transform.position).normalized; float angle = Vector3.Angle(fsmBehaviour.transform.forward, directionToTarget); if (angle > aimTolerance) { canShoot = false; if (enableDebug) Debug.Log($"[DEC_CanShoot] Not facing target: {angle:F1}° (tolerance: {aimTolerance}°)"); } } } if (enableDebug) { Debug.Log($"[DEC_CanShoot] {(canShoot ? "CAN SHOOT" : "CANNOT SHOOT")}"); } return canShoot; } } }