129 lines
5.9 KiB
C#
129 lines
5.9 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace TKS
|
|
{
|
|
/// <summary>
|
|
/// 남아 있는 동안 반복하는 스킬 이펙트(2026-11-10 연출 2차 · 표 skill_vfx.csv):
|
|
/// aura = 그 스킬 효과가 유닛에 남아 있는 동안(예약 대기 · 행동 중 · 시전 중 · 시한 효과 대상 = 범위 버프 받은 아군 / 대상 없는 시한 효과 = 시전자) ·
|
|
/// status = 상태 이상이 걸려 있는 동안(status_stun 기절·행동 불가 · status_confuse 혼란 · status_bleed 출혈 · status_poison 중독 · status_burn 화상).
|
|
/// 0.15초마다 원하는 목록과 띄운 목록을 맞춘다(가상 실행 중 · 전투 없음 = 건너뜀). 전투 코드는 건드리지 않는다(질의만).
|
|
/// </summary>
|
|
public class SkillVfxLoops : MonoBehaviour
|
|
{
|
|
const float Interval = 0.15f;
|
|
static SkillVfxLoops inst;
|
|
|
|
readonly Dictionary<Unit, Dictionary<string, List<GameObject>>> live = new Dictionary<Unit, Dictionary<string, List<GameObject>>>();
|
|
readonly Dictionary<Unit, HashSet<string>> want = new Dictionary<Unit, HashSet<string>>();
|
|
readonly List<Unit> drop = new List<Unit>();
|
|
readonly List<string> dropKeys = new List<string>();
|
|
float next;
|
|
|
|
public static void Ensure()
|
|
{
|
|
if (inst != null || !Application.isPlaying) return;
|
|
var go = new GameObject("SkillVfxLoops");
|
|
inst = go.AddComponent<SkillVfxLoops>();
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
if (inst == this) inst = null;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (Time.unscaledTime < next || Sim.Active) return;
|
|
Tick();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 지금 바로 맞추기 — 행동이 시작되는 순간(SkillSystem.BeginAction)에 부른다. 0.15초 주기를 기다리면 예약 기운이 돌진하는 유닛에 붙어 따라가다
|
|
/// 도착한 자리에서 꺼져 남음(2026-11-11 실측 · PD 「공격이 시작될 때 이펙트가 자연스럽게 종료되면서 공격」 = 출발한 자리에서 끝나야 함).
|
|
/// </summary>
|
|
public static void RefreshNow()
|
|
{
|
|
if (inst != null && !Sim.Active) inst.Tick();
|
|
}
|
|
|
|
void Tick()
|
|
{
|
|
next = Time.unscaledTime + Interval;
|
|
var sys = SkillSystem.Current;
|
|
foreach (var kv in want) kv.Value.Clear();
|
|
if (sys != null && sys.Battle != null) Collect(sys);
|
|
Apply();
|
|
}
|
|
|
|
void Add(Unit u, string evt, string key)
|
|
{
|
|
if (u == null || !u.IsAlive || string.IsNullOrEmpty(key)) return;
|
|
HashSet<string> set;
|
|
if (!want.TryGetValue(u, out set)) want[u] = set = new HashSet<string>();
|
|
set.Add(evt + "|" + key);
|
|
}
|
|
|
|
void Collect(SkillSystem sys)
|
|
{
|
|
// 예약형(다음 행동) = 예약하고 아직 쏘지 않은 동안만(공격이 발동하면 소멸 · PD 2026-11-10 「공격 발동 후에는 스킬 예약 이펙트가 소멸해야」) · 즉시형 = 시전 중
|
|
foreach (var s in sys.Entries)
|
|
if (s.Unit != null && s.Active != null && ((s.Reserved && !s.Armed && s.Active.Trigger == SkillTrigger.NextAction) || s.Casting))
|
|
Add(s.Unit, SkillVfx.EventAura, s.Active.Id);
|
|
// 시한 효과 = 즉시형 스킬만(관평 호위 · 서황 도끼 등) — 예약형의 1턴 효과(유비 반격 무시 등)는 기운을 다시 띄우지 않음
|
|
foreach (var t in sys.TimedEffects)
|
|
{
|
|
if (t.Def == null || !t.Def.IsActive || t.Def.Trigger == SkillTrigger.NextAction || t.Rounds <= 0) continue;
|
|
if (t.Targets != null)
|
|
foreach (var x in t.Targets) Add(x, SkillVfx.EventAura, t.Def.Id);
|
|
else if (t.Owner != null) Add(t.Owner.Unit, SkillVfx.EventAura, t.Def.Id);
|
|
}
|
|
foreach (var u in sys.Battle.Units)
|
|
{
|
|
if (u == null || !u.IsAlive) continue;
|
|
if (SkillStatus.Stunned(u)) Add(u, SkillVfx.EventStatus, "status_stun");
|
|
if (SkillStatus.Confused(u)) Add(u, SkillVfx.EventStatus, "status_confuse");
|
|
if (SkillStatus.Bleeding(u)) Add(u, SkillVfx.EventStatus, "status_bleed");
|
|
if (SkillStatus.Poisoned(u)) Add(u, SkillVfx.EventStatus, "status_poison");
|
|
var st = sys.StatusOf(u);
|
|
if (st != null && st.BurnTurns > 0) Add(u, SkillVfx.EventStatus, "status_burn");
|
|
}
|
|
}
|
|
|
|
void Apply()
|
|
{
|
|
// 없어진 것 끄기
|
|
drop.Clear();
|
|
foreach (var kv in live)
|
|
{
|
|
var u = kv.Key;
|
|
HashSet<string> set;
|
|
bool gone = u == null || !u.IsAlive || !want.TryGetValue(u, out set);
|
|
dropKeys.Clear();
|
|
foreach (var k in kv.Value)
|
|
if (gone || !want[u].Contains(k.Key)) dropKeys.Add(k.Key);
|
|
foreach (var k in dropKeys)
|
|
{
|
|
SkillVfx.Stop(kv.Value[k]);
|
|
kv.Value.Remove(k);
|
|
}
|
|
if (kv.Value.Count == 0) drop.Add(u);
|
|
}
|
|
foreach (var u in drop) live.Remove(u);
|
|
// 새로 켜기(행이 없는 키도 빈 목록으로 기억 · 다시 찾지 않음)
|
|
foreach (var kv in want)
|
|
{
|
|
if (kv.Value.Count == 0) continue;
|
|
Dictionary<string, List<GameObject>> have;
|
|
if (!live.TryGetValue(kv.Key, out have)) live[kv.Key] = have = new Dictionary<string, List<GameObject>>();
|
|
foreach (var k in kv.Value)
|
|
{
|
|
if (have.ContainsKey(k)) continue;
|
|
int bar = k.IndexOf('|');
|
|
have[k] = SkillVfx.SpawnLoops(kv.Key, k.Substring(bar + 1), k.Substring(0, bar));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|