using Invector.vCharacterController.AI.FSMBehaviour; using UnityEngine; namespace DemonBoss.Summoner { /// /// FSM Decision checking if summoner should engage in melee combat /// Checks: player distance, minion status, combat settings /// [CreateAssetMenu(menuName = "Invector/FSM/Decisions/Summoner/Should Melee Attack")] public class DEC_ShouldMeleeAttack : vStateDecision { public override string categoryName => "Summoner"; public override string defaultName => "Should Melee Attack"; [Header("Distance Configuration")] [Tooltip("Minimum distance to engage melee")] public float minMeleeDistance = 0f; [Tooltip("Maximum distance to engage melee")] public float maxMeleeDistance = 3f; [Header("Behavior")] [Tooltip("Attack even when minions are alive")] public bool attackWithMinions = false; [Tooltip("Force melee when player is too close, even if minions are alive")] public bool forceMeleeWhenTooClose = true; [Header("Debug")] [Tooltip("Enable debug logging")] public bool enableDebug = false; public override bool Decide(vIFSMBehaviourController fsmBehaviour) { var summoner = fsmBehaviour.gameObject.GetComponent(); if (summoner == null) { if (enableDebug) Debug.LogWarning("[DEC_ShouldMeleeAttack] No SummonerAI component found!"); return false; } // Don't attack while spawning if (summoner.IsSpawning) { if (enableDebug) Debug.Log("[DEC_ShouldMeleeAttack] Currently spawning - FALSE"); return false; } // Check distance to player float distance = summoner.GetDistanceToPlayer(); bool inRange = distance >= minMeleeDistance && distance <= maxMeleeDistance; // Last resort: only melee when in range AND cannot spawn or cast bool canSpawn = summoner.CanSpawnMinions; bool canCast = summoner.CanCastSpell(); if (forceMeleeWhenTooClose && inRange) { bool lastResort = !canSpawn && !canCast; if (enableDebug) { Debug.Log($"[DEC_ShouldMeleeAttack] Last resort check (distance {distance:F1}m, canSpawn={canSpawn}, canCast={canCast}) - {(lastResort ? "TRUE" : "FALSE")}"); } return lastResort; } // Check if has minions and shouldn't attack with them if (!attackWithMinions && summoner.HasActiveMinions) { if (enableDebug) Debug.Log($"[DEC_ShouldMeleeAttack] Has {summoner.ActiveMinionCount} minions and attackWithMinions=false - FALSE"); return false; } if (enableDebug) { if (inRange) { Debug.Log($"[DEC_ShouldMeleeAttack] Player in melee range ({distance:F1}m) - TRUE"); } else { Debug.Log($"[DEC_ShouldMeleeAttack] Player not in melee range ({distance:F1}m, need {minMeleeDistance:F1}-{maxMeleeDistance:F1}m) - FALSE"); } } return inRange && !canSpawn && !canCast; } } }