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

207 lines
5.0 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-10-31 19:33:19 +08:00
private bool _needRemove;
2023-08-22 19:08:45 +08:00
public bool needRemove
{
get
{
switch (configData.ExistType)
{
case EExistType.Once:
return true;
case EExistType.During:
return runtimeData.passTime >= configData.MaxExistTime;
case EExistType.Allways:
return false;
2023-10-31 19:33:19 +08:00
case EExistType.AfterReload:
return _needRemove;
2023-08-22 19:08:45 +08:00
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;
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;
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()
{
}
protected virtual void _OnTrigger()
{
}
public void TriggerAdd()
{
2023-10-19 15:00:19 +08:00
_OnAdd();
2023-08-22 19:08:45 +08:00
if (configData.TriggerType == ETriggerType.ON_ADD)
{
_OnTrigger();
}
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()
{
2023-10-19 15:00:19 +08:00
_OnRemove();
2023-08-22 19:08:45 +08:00
if (configData.TriggerType == ETriggerType.ON_REMOVE)
{
_OnTrigger();
}
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)
{
_OnTrigger();
_remainTriggerTime += configData.TiggerUnitTime;
}
}
2023-10-31 19:33:19 +08:00
2023-08-22 19:08:45 +08:00
_OnLogicUpdate(dt);
}
2023-10-31 19:33:19 +08:00
public void TriggerOnReload()
{
if (configData.TriggerType == ETriggerType.ON_RELOAD)
{
_OnTrigger();
}
if (configData.ExistType == EExistType.AfterReload)
{
_needRemove = true;
}
_OnReload();
}
protected virtual void _OnReload()
{
}
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 (configData.FloatParams.Count > index)
{
return configData.FloatParams[index];
}
return 0;
}
2023-08-22 19:08:45 +08:00
}
}