NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Buff/BaseBuff.cs

233 lines
5.6 KiB
C#
Raw Normal View History

2023-10-19 15:00:19 +08:00
using System.Text;
2023-08-22 19:08:45 +08:00
using Gameplay.Common;
2023-10-31 14:53:52 +08:00
using Gameplay.Effect;
2023-10-19 15:00:19 +08:00
using Gameplay.Pool;
2023-08-22 19:08:45 +08:00
namespace Gameplay.Buff
{
using cfg.BuffCfg;
2023-10-19 15:00:19 +08:00
public class BaseBuff: IPoolData
2023-08-22 19:08:45 +08:00
{
/// <summary>
/// buff被挂载的对象
/// </summary>
public GameUnit owner;
/// <summary>
2023-10-19 15:00:19 +08:00
/// buff的创建者
2023-08-22 19:08:45 +08:00
/// </summary>
2023-10-19 15:00:19 +08:00
public GameUnit creator { get; private set; }
2023-08-22 19:08:45 +08:00
public EBuffType buffType
{
get
{
return configData.BuffType;
}
}
2023-11-15 16:09:10 +08:00
private bool _needRemove = false;
2023-08-22 19:08:45 +08:00
public bool needRemove
{
get
{
switch (configData.ExistType)
{
case EExistType.Once:
2023-11-15 16:09:10 +08:00
return _needRemove;
2023-08-22 19:08:45 +08:00
case EExistType.During:
return runtimeData.passTime >= configData.MaxExistTime;
case EExistType.Allways:
return false;
default:
2023-10-19 15:00:19 +08:00
DebugUtil.LogError("暂未处理的buff existType:{0}",configData.ExistType);
2023-08-22 19:08:45 +08:00
return true;
}
}
}
public DataBuff configData;
public BuffRuntimeData runtimeData;
private float _remainTriggerTime;
2023-10-31 14:53:52 +08:00
private EffectPlayingData _existEffectData;
public bool isParamOverride;
private float[] _overrideParams;
2023-10-19 15:00:19 +08:00
public virtual void Ctor(GameUnit creator,
DataBuff configData)
2023-08-22 19:08:45 +08:00
{
2023-10-19 15:00:19 +08:00
this.creator = creator;
2023-08-22 19:08:45 +08:00
this.configData = configData;
isParamOverride = false;
2023-11-15 16:09:10 +08:00
_needRemove = false;
2023-10-19 15:00:19 +08:00
if (runtimeData == null)
{
runtimeData = new BuffRuntimeData();
}
else
{
runtimeData.Reset();
}
2023-08-22 19:08:45 +08:00
if (configData.TriggerType == ETriggerType.ON_LOOP)
{
_remainTriggerTime = configData.TiggerUnitTime;
}
}
2023-10-19 15:00:19 +08:00
2023-08-22 19:08:45 +08:00
public void Init()
{
_OnInit();
}
protected virtual void _OnInit()
{
2023-11-10 15:46:23 +08:00
2023-08-22 19:08:45 +08:00
}
2023-11-15 16:09:10 +08:00
public void Trigger()
{
_OnTrigger();
if (configData.ExistType == EExistType.Once)
{
_needRemove = true;
}
}
2023-08-22 19:08:45 +08:00
protected virtual void _OnTrigger()
{
}
public void OverrideFloatParams(params float[] overrideParams)
{
isParamOverride = true;
_overrideParams = overrideParams;
}
2023-08-22 19:08:45 +08:00
public void TriggerAdd()
{
if (configData.TriggerType == ETriggerType.ON_ADD)
{
2023-11-15 16:09:10 +08:00
Trigger();
2023-08-22 19:08:45 +08:00
}
2023-11-15 16:09:10 +08:00
_OnAdd();
2023-10-31 14:53:52 +08:00
if (configData.ExistType == EExistType.During ||
configData.ExistType == EExistType.Allways)
{
if (configData.ExistEffectId != 0)
{
var ownerTrans = owner.Node.transform;
_existEffectData = EffectManager.instance.PlayEffectById(configData.ExistEffectId,
ownerTrans.position, ownerTrans.rotation, ownerTrans);
_existEffectData.autoDestroy = false;
}
}
2023-08-22 19:08:45 +08:00
}
2023-10-19 15:00:19 +08:00
protected virtual void _OnAdd()
{
}
protected virtual void _OnRemove()
{
}
2023-08-22 19:08:45 +08:00
public void TriggerRemove()
{
if (configData.TriggerType == ETriggerType.ON_REMOVE)
{
2023-11-15 16:09:10 +08:00
Trigger();
2023-08-22 19:08:45 +08:00
}
2023-11-15 16:09:10 +08:00
_OnRemove();
2023-10-31 14:53:52 +08:00
if (_existEffectData != null)
{
EffectManager.instance.ReturnEffect(_existEffectData);
_existEffectData = null;
}
2023-08-22 19:08:45 +08:00
}
public void LogicUpdate(float dt)
{
2023-10-19 15:00:19 +08:00
runtimeData.passTime += dt;
2023-08-22 19:08:45 +08:00
if (configData.TriggerType == ETriggerType.ON_LOOP)
{
_remainTriggerTime -= dt;
if (_remainTriggerTime <= 0)
{
2023-11-15 16:09:10 +08:00
Trigger();
2023-08-22 19:08:45 +08:00
_remainTriggerTime += configData.TiggerUnitTime;
}
}
2023-10-31 19:33:19 +08:00
2023-08-22 19:08:45 +08:00
_OnLogicUpdate(dt);
}
public void RefreshDuring()
{
runtimeData.passTime = 0;
}
2023-11-15 16:09:10 +08:00
public void SpecialTrigger(ETriggerType triggerType)
2023-10-31 19:33:19 +08:00
{
2023-11-15 16:09:10 +08:00
if (configData.TriggerType == triggerType)
2023-10-31 19:33:19 +08:00
{
2023-11-15 16:09:10 +08:00
Trigger();
2023-10-31 19:33:19 +08:00
}
}
2023-08-22 19:08:45 +08:00
protected virtual void _OnLogicUpdate(float dt)
{
}
public override string ToString()
{
var sb = new StringBuilder();
sb.AppendLine("ID:" + configData.ID);
sb.AppendLine("Name:" + configData.Name);
return sb.ToString();
}
2023-10-19 15:00:19 +08:00
public void OnGet()
{
}
public void OnReturn()
{
2023-10-31 19:33:19 +08:00
_needRemove = false;
2023-10-19 15:00:19 +08:00
}
protected float _TryGetFloatParam(int index)
{
if (isParamOverride)
{
// 使用覆写的
if (_overrideParams.Length > index)
{
return _overrideParams[index];
}
return 0;
}
// 使用配置的
2023-10-19 15:00:19 +08:00
if (configData.FloatParams.Count > index)
{
return configData.FloatParams[index];
}
return 0;
}
2023-08-22 19:08:45 +08:00
}
}