- 드로그 전투 컨텍스트를 BossBehaviorRuntimeState 중심 구조로 정리하고 BossEnemy, 패턴 액션, 조건 노드가 마지막 실행 결과와 phase 상태를 직접 사용하도록 갱신 - BT_Drog와 재빌드 에디터 스크립트를 확장해 phase 전환, 집행 결과 분기, 거리/쿨타임 기반 패턴 선택을 드로그 전용 자산과 노드 파라미터로 재구성 - 드로그 패턴/스킬/이펙트/애니메이션 플레이스홀더 자산을 재생성하고 보스 프리팹이 새 런타임 상태 및 등록 클립 구성을 참조하도록 정리
402 lines
13 KiB
C#
402 lines
13 KiB
C#
using System;
|
|
|
|
using Colosseum.Abnormalities;
|
|
using Colosseum.AI;
|
|
using Colosseum.Combat;
|
|
using Colosseum.Enemy;
|
|
using Colosseum.Player;
|
|
using Colosseum.Skills;
|
|
|
|
using Unity.Behavior;
|
|
using Unity.Properties;
|
|
using UnityEngine;
|
|
|
|
using Action = Unity.Behavior.Action;
|
|
|
|
/// <summary>
|
|
/// 보스 공통 패턴 실행용 Behavior Action 기반 클래스입니다.
|
|
/// </summary>
|
|
[Serializable, GeneratePropertyBag]
|
|
public abstract partial class BossPatternActionBase : Action
|
|
{
|
|
[SerializeReference]
|
|
public BlackboardVariable<GameObject> Target;
|
|
|
|
protected BossEnemy bossEnemy;
|
|
protected EnemyBase enemyBase;
|
|
protected SkillController skillController;
|
|
protected BossBehaviorRuntimeState runtimeState;
|
|
protected UnityEngine.AI.NavMeshAgent navMeshAgent;
|
|
protected AbnormalityManager abnormalityManager;
|
|
|
|
private BossPatternData activePattern;
|
|
private GameObject activeTarget;
|
|
private int currentStepIndex;
|
|
private bool isWaiting;
|
|
private float waitEndTime;
|
|
private bool isSkillStepExecuting;
|
|
|
|
private bool isChargeWaiting;
|
|
private float chargeEndTime;
|
|
private float chargeAccumulatedDamage;
|
|
private float chargeRequiredDamage;
|
|
private ChargeStepData activeChargeData;
|
|
private bool chargeTelegraphApplied;
|
|
|
|
/// <summary>
|
|
/// 액션 시작 시 실제로 실행할 패턴과 대상을 결정합니다.
|
|
/// </summary>
|
|
protected abstract bool TryResolvePattern(out BossPatternData pattern, out GameObject target);
|
|
|
|
/// <summary>
|
|
/// 패턴이 의미 있는 결과와 함께 종료되었을 때, 실패 결과도 다음 노드로 넘길지 결정합니다.
|
|
/// </summary>
|
|
protected virtual bool ContinueSequenceOnResolvedFailure => false;
|
|
|
|
protected override Status OnStart()
|
|
{
|
|
ResolveReferences();
|
|
ClearRuntimeState();
|
|
|
|
if (!IsReady())
|
|
return Status.Failure;
|
|
|
|
if (runtimeState.IsBehaviorSuppressed)
|
|
{
|
|
StopMovement();
|
|
return Status.Failure;
|
|
}
|
|
|
|
if (bossEnemy.IsDead)
|
|
return Status.Failure;
|
|
|
|
if (skillController.IsPlayingAnimation)
|
|
return Status.Failure;
|
|
|
|
if (!TryResolvePattern(out BossPatternData pattern, out GameObject target))
|
|
return Status.Failure;
|
|
|
|
activePattern = pattern;
|
|
activeTarget = target;
|
|
runtimeState.BeginPatternExecution(activePattern);
|
|
|
|
runtimeState.WasChargeBroken = false;
|
|
runtimeState.LastChargeStaggerDuration = 0f;
|
|
|
|
if (Target != null)
|
|
Target.Value = target;
|
|
|
|
runtimeState.SetCurrentTarget(target);
|
|
|
|
StopMovement();
|
|
return ExecuteCurrentStep();
|
|
}
|
|
|
|
protected override Status OnUpdate()
|
|
{
|
|
if (!IsReady() || activePattern == null)
|
|
return FinalizePatternFailure(BossPatternExecutionResult.Failed);
|
|
|
|
if (runtimeState.IsBehaviorSuppressed)
|
|
{
|
|
StopMovement();
|
|
return FinalizePatternFailure(BossPatternExecutionResult.Cancelled);
|
|
}
|
|
|
|
if (bossEnemy.IsDead)
|
|
return FinalizePatternFailure(BossPatternExecutionResult.Cancelled);
|
|
|
|
if (isChargeWaiting)
|
|
{
|
|
if (chargeAccumulatedDamage >= chargeRequiredDamage)
|
|
{
|
|
EndChargeWait(broken: true);
|
|
skillController?.CancelSkill(SkillCancelReason.Interrupt);
|
|
runtimeState.WasChargeBroken = true;
|
|
runtimeState.SetPatternCooldown(activePattern);
|
|
LogDebug($"충전 차단 성공: 누적 {chargeAccumulatedDamage:F1} / 필요 {chargeRequiredDamage:F1}");
|
|
CombatBalanceTracker.RecordBossEvent("집행 개시 차단 성공");
|
|
return FinalizeResolvedPattern(BossPatternExecutionResult.Failed);
|
|
}
|
|
|
|
if (Time.time < chargeEndTime)
|
|
return Status.Running;
|
|
|
|
EndChargeWait(broken: false);
|
|
}
|
|
else if (isWaiting)
|
|
{
|
|
if (Time.time < waitEndTime)
|
|
return Status.Running;
|
|
|
|
isWaiting = false;
|
|
}
|
|
else if (isSkillStepExecuting)
|
|
{
|
|
if (skillController.IsPlayingAnimation)
|
|
return Status.Running;
|
|
|
|
isSkillStepExecuting = false;
|
|
if (skillController.LastExecutionResult != SkillExecutionResult.Completed)
|
|
return FinalizePatternFailure(BossPatternExecutionResult.Cancelled);
|
|
}
|
|
|
|
currentStepIndex++;
|
|
if (currentStepIndex >= activePattern.Steps.Count)
|
|
{
|
|
runtimeState.SetPatternCooldown(activePattern);
|
|
return FinalizeResolvedPattern(BossPatternExecutionResult.Succeeded);
|
|
}
|
|
|
|
return ExecuteCurrentStep();
|
|
}
|
|
|
|
protected override void OnEnd()
|
|
{
|
|
ClearRuntimeState();
|
|
}
|
|
|
|
protected virtual GameObject ResolveStepTarget(GameObject fallbackTarget)
|
|
{
|
|
return fallbackTarget;
|
|
}
|
|
|
|
protected GameObject FindNearestLivingPlayer()
|
|
{
|
|
PlayerNetworkController[] players = UnityEngine.Object.FindObjectsByType<PlayerNetworkController>(FindObjectsSortMode.None);
|
|
GameObject nearestTarget = null;
|
|
float nearestDistance = float.MaxValue;
|
|
float maxDistance = enemyBase != null && enemyBase.Data != null ? enemyBase.Data.AggroRange : Mathf.Infinity;
|
|
|
|
for (int i = 0; i < players.Length; i++)
|
|
{
|
|
PlayerNetworkController player = players[i];
|
|
if (player == null || player.IsDead || !player.gameObject.activeInHierarchy)
|
|
continue;
|
|
|
|
GameObject candidate = player.gameObject;
|
|
|
|
float distance = Vector3.Distance(GameObject.transform.position, candidate.transform.position);
|
|
if (distance > maxDistance || distance >= nearestDistance)
|
|
continue;
|
|
|
|
nearestDistance = distance;
|
|
nearestTarget = candidate;
|
|
}
|
|
|
|
return nearestTarget;
|
|
}
|
|
|
|
protected GameObject ResolvePrimaryTarget()
|
|
{
|
|
GameObject highestThreatTarget = enemyBase != null
|
|
? enemyBase.GetHighestThreatTarget(Target?.Value, null, enemyBase.Data != null ? enemyBase.Data.AggroRange : Mathf.Infinity)
|
|
: null;
|
|
|
|
GameObject target = highestThreatTarget != null ? highestThreatTarget : FindNearestLivingPlayer();
|
|
if (Target != null)
|
|
Target.Value = target;
|
|
|
|
return target;
|
|
}
|
|
|
|
protected bool IsValidHostileTarget(GameObject candidate)
|
|
{
|
|
if (candidate == null || !candidate.activeInHierarchy)
|
|
return false;
|
|
|
|
// 보스는 항상 적 팀이므로, 플레이어만 적대 대상으로 간주
|
|
if (candidate.GetComponent<PlayerNetworkController>() == null)
|
|
return false;
|
|
|
|
IDamageable damageable = candidate.GetComponent<IDamageable>();
|
|
return damageable == null || !damageable.IsDead;
|
|
}
|
|
|
|
protected void StopMovement()
|
|
{
|
|
if (navMeshAgent == null || !navMeshAgent.enabled)
|
|
return;
|
|
|
|
navMeshAgent.isStopped = true;
|
|
navMeshAgent.ResetPath();
|
|
}
|
|
|
|
protected void LogDebug(string message)
|
|
{
|
|
runtimeState?.LogDebug(GetType().Name, message);
|
|
}
|
|
|
|
private Status ExecuteCurrentStep()
|
|
{
|
|
if (activePattern == null || currentStepIndex < 0 || currentStepIndex >= activePattern.Steps.Count)
|
|
return Status.Failure;
|
|
|
|
PatternStep step = activePattern.Steps[currentStepIndex];
|
|
if (step.Type == PatternStepType.Wait)
|
|
{
|
|
isWaiting = true;
|
|
waitEndTime = Time.time + step.Duration;
|
|
return Status.Running;
|
|
}
|
|
|
|
if (step.Type == PatternStepType.ChargeWait)
|
|
{
|
|
StartChargeWait(step);
|
|
return Status.Running;
|
|
}
|
|
|
|
if (step.Skill == null)
|
|
{
|
|
Debug.LogWarning($"[{GetType().Name}] 스킬이 비어 있는 패턴 스텝입니다: {activePattern.PatternName} / Step={currentStepIndex}");
|
|
return Status.Failure;
|
|
}
|
|
|
|
GameObject skillTarget = activeTarget;
|
|
if (step.Skill.JumpToTarget)
|
|
{
|
|
skillTarget = ResolveStepTarget(activeTarget);
|
|
if (skillTarget == null)
|
|
{
|
|
if (activePattern != null && activePattern.SkipJumpStepOnNoTarget)
|
|
{
|
|
runtimeState.SetPatternCooldown(activePattern);
|
|
LogDebug($"점프 대상 없음, 조합 패턴 조기 종료: {activePattern.PatternName}");
|
|
return Status.Success;
|
|
}
|
|
|
|
LogDebug($"점프 타겟을 찾지 못해 실패: {activePattern.PatternName}");
|
|
return Status.Failure;
|
|
}
|
|
|
|
enemyBase?.SetJumpTarget(skillTarget.transform.position);
|
|
}
|
|
|
|
if (!skillController.ExecuteSkill(step.Skill, skillTarget))
|
|
{
|
|
Debug.LogWarning($"[{GetType().Name}] 스킬 실행 실패: {step.Skill.SkillName}");
|
|
return FinalizePatternFailure(BossPatternExecutionResult.Failed);
|
|
}
|
|
|
|
isSkillStepExecuting = true;
|
|
LogDebug($"패턴 실행: {activePattern.PatternName} / Step={currentStepIndex} / Skill={step.Skill.SkillName}");
|
|
return Status.Running;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 충전 대기를 시작합니다. 전조 이상상태를 부여하고 데미지 추적을 시작합니다.
|
|
/// </summary>
|
|
private void StartChargeWait(PatternStep step)
|
|
{
|
|
isChargeWaiting = true;
|
|
activeChargeData = step.ChargeData;
|
|
chargeEndTime = Time.time + step.Duration;
|
|
chargeAccumulatedDamage = 0f;
|
|
|
|
float damageRatio = activeChargeData != null ? activeChargeData.RequiredDamageRatio : 0.1f;
|
|
chargeRequiredDamage = bossEnemy.MaxHealth * damageRatio;
|
|
chargeTelegraphApplied = false;
|
|
|
|
if (enemyBase != null)
|
|
enemyBase.OnDamageTaken += OnChargeDamageTaken;
|
|
|
|
if (activeChargeData != null && activeChargeData.TelegraphAbnormality != null && abnormalityManager != null)
|
|
{
|
|
abnormalityManager.ApplyAbnormality(activeChargeData.TelegraphAbnormality, GameObject);
|
|
chargeTelegraphApplied = true;
|
|
}
|
|
|
|
LogDebug($"충전 대기 시작: 필요 피해={chargeRequiredDamage:F1} / 대기={step.Duration:F1}s");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 충전 대기를 종료합니다. 전조 이상상태를 제거하고 데미지 추적을 해제합니다.
|
|
/// </summary>
|
|
private void EndChargeWait(bool broken)
|
|
{
|
|
isChargeWaiting = false;
|
|
|
|
if (enemyBase != null)
|
|
enemyBase.OnDamageTaken -= OnChargeDamageTaken;
|
|
|
|
if (chargeTelegraphApplied && abnormalityManager != null && activeChargeData != null
|
|
&& activeChargeData.TelegraphAbnormality != null)
|
|
{
|
|
abnormalityManager.RemoveAbnormality(activeChargeData.TelegraphAbnormality);
|
|
chargeTelegraphApplied = false;
|
|
}
|
|
|
|
if (broken && activeChargeData != null)
|
|
{
|
|
runtimeState.LastChargeStaggerDuration = activeChargeData.StaggerDuration;
|
|
}
|
|
|
|
activeChargeData = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 충전 중 보스가 받은 피해를 누적합니다.
|
|
/// </summary>
|
|
private void OnChargeDamageTaken(float damage)
|
|
{
|
|
if (!isChargeWaiting || damage <= 0f)
|
|
return;
|
|
|
|
chargeAccumulatedDamage += damage;
|
|
}
|
|
|
|
private bool IsReady()
|
|
{
|
|
return bossEnemy != null && enemyBase != null && skillController != null && runtimeState != null;
|
|
}
|
|
|
|
private void ResolveReferences()
|
|
{
|
|
if (bossEnemy == null)
|
|
bossEnemy = GameObject.GetComponent<BossEnemy>();
|
|
|
|
if (enemyBase == null)
|
|
enemyBase = GameObject.GetComponent<EnemyBase>();
|
|
|
|
if (skillController == null)
|
|
skillController = GameObject.GetComponent<SkillController>();
|
|
|
|
if (runtimeState == null)
|
|
runtimeState = GameObject.GetComponent<BossBehaviorRuntimeState>();
|
|
|
|
if (navMeshAgent == null)
|
|
navMeshAgent = GameObject.GetComponent<UnityEngine.AI.NavMeshAgent>();
|
|
|
|
if (abnormalityManager == null)
|
|
abnormalityManager = GameObject.GetComponent<AbnormalityManager>();
|
|
}
|
|
|
|
private void ClearRuntimeState()
|
|
{
|
|
if (isChargeWaiting)
|
|
EndChargeWait(broken: false);
|
|
|
|
activePattern = null;
|
|
activeTarget = null;
|
|
currentStepIndex = 0;
|
|
isWaiting = false;
|
|
isSkillStepExecuting = false;
|
|
waitEndTime = 0f;
|
|
}
|
|
|
|
private Status FinalizeResolvedPattern(BossPatternExecutionResult result)
|
|
{
|
|
runtimeState?.CompletePatternExecution(activePattern, result);
|
|
if (result == BossPatternExecutionResult.Failed && ContinueSequenceOnResolvedFailure)
|
|
return Status.Success;
|
|
|
|
return Status.Success;
|
|
}
|
|
|
|
private Status FinalizePatternFailure(BossPatternExecutionResult result)
|
|
{
|
|
runtimeState?.CompletePatternExecution(activePattern, result);
|
|
return Status.Failure;
|
|
}
|
|
}
|