EerieVillage/Assets/Scripts/Skills/Effectors/DebuffStack.cs

63 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections.Generic;
using UnityEngine;
using Platformer.Mechanics;
namespace EerieVillage.Skills.Effectors
{
/// <summary>
/// A08 저주의 화살 — 저주 스택 관리 정적 레지스트리.
/// N 스택 도달 시 누적 폭발 대미지 처리.
/// BT12-Dev Phase 2-B §4-6.
///
/// 주의: 씬 전환·EnemyController 파괴 시 Clear(enemy)를 외부에서 호출해야
/// Dictionary 누수를 방지할 수 있다 (Phase 2-C GC 개선 대상).
/// </summary>
public static class DebuffStack
{
private static readonly Dictionary<EnemyController, int> _stacks =
new Dictionary<EnemyController, int>();
/// <summary>
/// 스택 1 추가. limit 도달 시 폭발 대미지 처리 후 스택 초기화.
/// explosionDamage = ActiveSkillData.BaseDamage 기준.
/// </summary>
public static void AddStack(EnemyController enemy, int limit, int explosionDamage)
{
if (enemy == null) return;
if (!_stacks.ContainsKey(enemy))
_stacks[enemy] = 0;
_stacks[enemy]++;
if (_stacks[enemy] >= limit)
{
// N스택 폭발 대미지 — 스택 수 × baseDamage × 2
int total = explosionDamage * _stacks[enemy] * 2;
var health = enemy.GetComponent<Health>();
if (health != null && health.IsAlive)
{
health.Decrement(total);
}
_stacks[enemy] = 0;
}
}
/// <summary>
/// 적 사망 또는 씬 전환 시 스택 레코드 제거.
/// </summary>
public static void Clear(EnemyController enemy)
{
if (enemy != null)
_stacks.Remove(enemy);
}
/// <summary>현재 스택 수 조회 (디버그용).</summary>
public static int GetStack(EnemyController enemy)
{
if (enemy == null) return 0;
return _stacks.TryGetValue(enemy, out int v) ? v : 0;
}
}
}