2026-04-08 스킬시스템 진행중, 폴더구조 변경등
This commit is contained in:
55
Assets/02_Scripts/_Shared/Status/DebuffInstance.cs
Normal file
55
Assets/02_Scripts/_Shared/Status/DebuffInstance.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class DebuffInstance
|
||||
{
|
||||
public DebuffData Data { get; private set; }
|
||||
public float RemainingTime { get; private set; }
|
||||
public bool IsExpired => RemainingTime <= 0f;
|
||||
|
||||
private StatusEffectReceiver _receiver;
|
||||
private float _tickAccumulator;
|
||||
private GameObject _visualInstance;
|
||||
|
||||
public DebuffInstance(DebuffData data, StatusEffectReceiver receiver)
|
||||
{
|
||||
Data = data;
|
||||
_receiver = receiver;
|
||||
RemainingTime = data.Duration;
|
||||
_tickAccumulator = 0f;
|
||||
}
|
||||
|
||||
public void OnApply()
|
||||
{
|
||||
if (Data.EffectPrefab != null)
|
||||
{
|
||||
_visualInstance = Object.Instantiate(Data.EffectPrefab, _receiver.transform);
|
||||
}
|
||||
}
|
||||
|
||||
public void Tick(float deltaTime)
|
||||
{
|
||||
RemainingTime -= deltaTime;
|
||||
|
||||
if (Data.DebuffType == DebuffType.DamageOverTime && Data.TickInterval > 0)
|
||||
{
|
||||
_tickAccumulator += deltaTime;
|
||||
if (_tickAccumulator >= Data.TickInterval)
|
||||
{
|
||||
_tickAccumulator -= Data.TickInterval;
|
||||
IDamageable damageable = _receiver.GetComponent<IDamageable>();
|
||||
damageable?.TakeDamage(Mathf.RoundToInt(Data.Value), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnRemove()
|
||||
{
|
||||
if (_visualInstance != null)
|
||||
Object.Destroy(_visualInstance);
|
||||
}
|
||||
|
||||
public void RefreshDuration()
|
||||
{
|
||||
RemainingTime = Data.Duration;
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/_Shared/Status/DebuffInstance.cs.meta
Normal file
2
Assets/02_Scripts/_Shared/Status/DebuffInstance.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17e97bf635cef364781fdf5cedc5dfee
|
||||
7
Assets/02_Scripts/_Shared/Status/IDamageable.cs
Normal file
7
Assets/02_Scripts/_Shared/Status/IDamageable.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using UnityEngine;
|
||||
|
||||
public interface IDamageable
|
||||
{
|
||||
void TakeDamage(int damage, Transform source);
|
||||
Transform GetTransform();
|
||||
}
|
||||
2
Assets/02_Scripts/_Shared/Status/IDamageable.cs.meta
Normal file
2
Assets/02_Scripts/_Shared/Status/IDamageable.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd29cb0b94cdd2c4388ff287969a9b5e
|
||||
69
Assets/02_Scripts/_Shared/Status/StatusEffectReceiver.cs
Normal file
69
Assets/02_Scripts/_Shared/Status/StatusEffectReceiver.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class StatusEffectReceiver : MonoBehaviour
|
||||
{
|
||||
private List<DebuffInstance> _activeDebuffs = new List<DebuffInstance>();
|
||||
|
||||
public void ApplyDebuff(DebuffData data)
|
||||
{
|
||||
if (data == null) return;
|
||||
|
||||
if (!data.Stackable)
|
||||
{
|
||||
DebuffInstance existing = _activeDebuffs.Find(d => d.Data == data);
|
||||
if (existing != null)
|
||||
{
|
||||
existing.RefreshDuration();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int count = 0;
|
||||
foreach (var d in _activeDebuffs)
|
||||
if (d.Data == data) count++;
|
||||
|
||||
if (count >= data.MaxStacks) return;
|
||||
}
|
||||
|
||||
DebuffInstance instance = new DebuffInstance(data, this);
|
||||
_activeDebuffs.Add(instance);
|
||||
instance.OnApply();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
for (int i = _activeDebuffs.Count - 1; i >= 0; i--)
|
||||
{
|
||||
_activeDebuffs[i].Tick(Time.deltaTime);
|
||||
if (_activeDebuffs[i].IsExpired)
|
||||
{
|
||||
_activeDebuffs[i].OnRemove();
|
||||
_activeDebuffs.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasDebuff(DebuffType type)
|
||||
{
|
||||
foreach (var d in _activeDebuffs)
|
||||
if (d.Data.DebuffType == type) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public float GetDebuffValue(DebuffType type)
|
||||
{
|
||||
float total = 0f;
|
||||
foreach (var d in _activeDebuffs)
|
||||
if (d.Data.DebuffType == type) total += d.Data.Value;
|
||||
return total;
|
||||
}
|
||||
|
||||
public void ClearAllDebuffs()
|
||||
{
|
||||
for (int i = _activeDebuffs.Count - 1; i >= 0; i--)
|
||||
_activeDebuffs[i].OnRemove();
|
||||
_activeDebuffs.Clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dafab9c2111f5d640bf9eb470963b85d
|
||||
Reference in New Issue
Block a user