You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

80 lines
2.3 KiB

using System;
using System.Collections.Generic;
using IVDataFormat;
using UnityEngine;
[Serializable]
public class StatEffect
{
[SerializeField] eEffectType key;
[SerializeReference, SubclassSelector] public KeyCompare subKey = new DefaultKey();
[SerializeField] ValueModifier value;
public eEffectType Key => key;
public KeyCompare SubKey => subKey;
public ValueModifier Value => value;
public string NameKey => FormatString.StringFormat("efc{0}", (int)key);
}
[Serializable]
public struct BuffProperty
{
public StringKey key;
public StatEffect[] effects;
public float duration;
}
public class BuffData
{
static readonly float _infiniteDuration = 0;
BuffProperty property;
float elapsedDuration = 0.0f;
public IReadOnlyList<StatEffect> Effects => property.effects;
public StringKey NameKey => property.key;
public string IconImgAtlasName => GameProperty.Instance.BuffIconAtlasName;
public string IconImgNameInAtlas => property.key;
public float Duration => property.duration;
public float ElapsedDuration => elapsedDuration;
public float RemainTime => !IsInfiniteDuration ? Mathf.Max(0, property.duration - elapsedDuration) : float.MaxValue;
public bool IsInfiniteDuration => property.duration == _infiniteDuration;
public BuffData(BuffProperty property, object from)
{
this.property = property;
for(int i = 0; i < Effects.Count; i++)
{
Effects[i].Value.From = from;
}
}
public bool UpdateDuration(float deltaTime)
{
if (IsInfiniteDuration) return true;
elapsedDuration += deltaTime;
return elapsedDuration < property.duration;
}
public void ResetDuration()
{
elapsedDuration = 0.0f;
}
public bool TryGetEffect(eEffectType key, object subKey, out StatEffect result)
{
result = null;
for (int i = 0; i < property.effects.Length; i++)
{
var effect = property.effects[i];
if (effect.Key == key && effect.subKey.Match(subKey))
{
result = Effects[i];
break;
}
}
return result != null;
}
public bool HasEffect(eEffectType key, object subKey) => Array.Exists(property.effects, e => e.Key == key && e.subKey.Match(subKey));
}