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

64 lines
2.3 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using UnityEngine;
using Platformer.Mechanics;
using Platformer.Gameplay;
using static Platformer.Core.Simulation;
namespace EerieVillage.Skills.Effectors
{
/// <summary>
/// A05 학익진 — 플레이어 주변 범위 즉시 피해 + FX_SLASH 이펙트.
/// PD 지시 (2026-05-13):
/// - 1.5초 간격 (BaseCooldown 1.5)
/// - 플레이어 주변 영역 (HitboxSize 반경) 내 적에게 피해
/// - 공격력 10 (BaseDamage)
/// - FX_SLASH 이펙트 재생 (data.OnHitFxPrefab)
/// </summary>
public class MeleeAreaSpawner : IEffector
{
public void Trigger(ActiveSkillRuntime runtime, PlayerSkillInventory inventory)
{
var data = runtime.ActiveData;
Vector2 playerPos = inventory.transform.position;
// 이펙트 spawn — 플레이어 위치
if (data.OnHitFxPrefab != null)
{
var fx = Object.Instantiate(data.OnHitFxPrefab, playerPos, Quaternion.identity);
AutoDestroyFx(fx);
}
// 범위 내 적 일괄 피해
int damage = Mathf.Max(runtime.CalculateEffectiveDamage(), data.BaseDamage);
float radius = Mathf.Max(data.HitboxSize.x, data.HitboxSize.y);
var enemies = Object.FindObjectsByType<EnemyController>(FindObjectsSortMode.None);
foreach (var e in enemies)
{
if (e == null) continue;
if (Vector2.Distance(e.transform.position, playerPos) > radius) continue;
var h = e.GetComponent<Health>();
if (h == null || !h.IsAlive) continue;
h.Decrement(damage);
if (!h.IsAlive)
{
Schedule<EnemyDeath>().enemy = e;
}
}
}
static void AutoDestroyFx(GameObject fxGo)
{
if (fxGo == null) return;
var psList = fxGo.GetComponentsInChildren<ParticleSystem>(true);
float max = 0f;
foreach (var ps in psList)
{
var main = ps.main;
float t = main.duration + main.startLifetime.constantMax;
if (t > max) max = t;
}
Object.Destroy(fxGo, Mathf.Max(max, 1f) + 0.2f);
}
}
}