using Invector.vCharacterController.AI.FSMBehaviour; using UnityEngine; namespace DemonBoss.Summoner { /// /// FSM Decision checking if summoner can spawn minions /// Checks: not already spawning, minion count below max, cooldown passed /// [CreateAssetMenu(menuName = "Invector/FSM/Decisions/Summoner/Can Spawn Minions")] public class DEC_CanSpawnMinions : vStateDecision { public override string categoryName => "Summoner"; public override string defaultName => "Can Spawn Minions"; [Header("Spawn Conditions")] [Tooltip("Check if health is below threshold")] public bool checkHealthThreshold = true; [Tooltip("Check if minions are below max count")] public bool checkMinionCount = true; [Tooltip("Check if cooldown has passed")] public bool checkCooldown = true; [Tooltip("Cooldown between summon attempts (seconds)")] public float cooldownTime = 15f; [Header("Distance Check")] [Tooltip("Only spawn if player is within this distance (0 = disabled)")] public float maxDistanceToPlayer = 0f; [Tooltip("Require summoner to be at or beyond safe distance before summoning")] public bool requireSafeDistance = false; [Header("Debug")] [Tooltip("Enable debug logging")] public bool enableDebug = false; private string cooldownKey = "SummonMinions"; public override bool Decide(vIFSMBehaviourController fsmBehaviour) { var summoner = fsmBehaviour.gameObject.GetComponent(); if (summoner == null) { if (enableDebug) Debug.LogWarning("[DEC_CanSpawnMinions] No SummonerAI component found!"); return false; } // Check if already spawning if (summoner.IsSpawning) { if (enableDebug) Debug.Log("[DEC_CanSpawnMinions] Already spawning - FALSE"); return false; } // Check minion count if (checkMinionCount && !summoner.CanSpawnMinions) { if (enableDebug) Debug.Log($"[DEC_CanSpawnMinions] Max minions reached ({summoner.ActiveMinionCount}) - FALSE"); return false; } // Check health threshold if (checkHealthThreshold && !summoner.ShouldSummonByHealth()) { if (enableDebug) Debug.Log("[DEC_CanSpawnMinions] Health threshold not met - FALSE"); return false; } // Check distance to player if (maxDistanceToPlayer > 0f) { float distance = summoner.GetDistanceToPlayer(); if (distance > maxDistanceToPlayer) { if (enableDebug) Debug.Log($"[DEC_CanSpawnMinions] Player too far ({distance:F1}m) - FALSE"); return false; } } if (requireSafeDistance && !summoner.IsAtSafeDistance()) { if (enableDebug) Debug.Log("[DEC_CanSpawnMinions] Not at safe distance - FALSE"); return false; } // Check cooldown if (checkCooldown) { string timerKey = "cooldown_" + cooldownKey; if (fsmBehaviour.HasTimer(timerKey)) { float lastUsedTime = fsmBehaviour.GetTimer(timerKey); float timeSinceLastUse = Time.time - lastUsedTime; if (timeSinceLastUse < cooldownTime) { if (enableDebug) Debug.Log($"[DEC_CanSpawnMinions] On cooldown - {cooldownTime - timeSinceLastUse:F1}s remaining - FALSE"); return false; } } // Set cooldown for next use fsmBehaviour.SetTimer(timerKey, Time.time); } if (enableDebug) Debug.Log("[DEC_CanSpawnMinions] All conditions met - TRUE"); return true; } } }