163 lines
3.6 KiB
C#
163 lines
3.6 KiB
C#
using System.Text;
|
|
using Gameplay.Common;
|
|
using Gameplay.Pool;
|
|
|
|
namespace Gameplay.Buff
|
|
{
|
|
using cfg.BuffCfg;
|
|
|
|
public class BaseBuff: IPoolData
|
|
{
|
|
|
|
/// <summary>
|
|
/// buff被挂载的对象
|
|
/// </summary>
|
|
public GameUnit owner;
|
|
|
|
/// <summary>
|
|
/// buff的创建者
|
|
/// </summary>
|
|
public GameUnit creator { get; private set; }
|
|
|
|
public EBuffType buffType
|
|
{
|
|
get
|
|
{
|
|
return configData.BuffType;
|
|
}
|
|
}
|
|
|
|
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;
|
|
default:
|
|
DebugUtil.LogError("暂未处理的buff existType:{0}",configData.ExistType);
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
public DataBuff configData;
|
|
public BuffRuntimeData runtimeData;
|
|
|
|
private float _remainTriggerTime;
|
|
|
|
public virtual void Ctor(GameUnit creator,
|
|
DataBuff configData)
|
|
{
|
|
this.creator = creator;
|
|
this.configData = configData;
|
|
if (runtimeData == null)
|
|
{
|
|
runtimeData = new BuffRuntimeData();
|
|
}
|
|
else
|
|
{
|
|
runtimeData.Reset();
|
|
}
|
|
if (configData.TriggerType == ETriggerType.ON_LOOP)
|
|
{
|
|
_remainTriggerTime = configData.TiggerUnitTime;
|
|
}
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
_OnInit();
|
|
}
|
|
|
|
protected virtual void _OnInit()
|
|
{
|
|
|
|
}
|
|
|
|
protected virtual void _OnTrigger()
|
|
{
|
|
|
|
}
|
|
|
|
public void TriggerAdd()
|
|
{
|
|
_OnAdd();
|
|
if (configData.TriggerType == ETriggerType.ON_ADD)
|
|
{
|
|
_OnTrigger();
|
|
}
|
|
}
|
|
|
|
protected virtual void _OnAdd()
|
|
{
|
|
|
|
}
|
|
|
|
protected virtual void _OnRemove()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
public void TriggerRemove()
|
|
{
|
|
_OnRemove();
|
|
if (configData.TriggerType == ETriggerType.ON_REMOVE)
|
|
{
|
|
_OnTrigger();
|
|
}
|
|
}
|
|
|
|
public void LogicUpdate(float dt)
|
|
{
|
|
runtimeData.passTime += dt;
|
|
|
|
if (configData.TriggerType == ETriggerType.ON_LOOP)
|
|
{
|
|
_remainTriggerTime -= dt;
|
|
if (_remainTriggerTime <= 0)
|
|
{
|
|
_OnTrigger();
|
|
_remainTriggerTime += configData.TiggerUnitTime;
|
|
}
|
|
}
|
|
_OnLogicUpdate(dt);
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
public void OnGet()
|
|
{
|
|
}
|
|
public void OnReturn()
|
|
{
|
|
}
|
|
|
|
protected float _TryGetFloatParam(int index)
|
|
{
|
|
if (configData.FloatParams.Count > index)
|
|
{
|
|
return configData.FloatParams[index];
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
}
|