Files
Main/Assets/Code/Logic/_Required/Entity/Character/Buff/Buff.cs

168 lines
4.5 KiB
C#
Raw Normal View History

2025-01-25 04:38:09 +08:00
using System;
using System.Collections.Generic;
using Thousandto.Cfg.Data;
using Thousandto.Code.Center;
using Thousandto.Core.Asset;
using Thousandto.Core.Base;
using UnityEngine;
using Thousandto.Code.Global;
namespace Thousandto.Code.Logic
{
//buff
public class Buff
{
#region//私有变量
private FGameObjectVFX _vfxID = null;
private float _delayTime = 0f;
#endregion
#region//属性
//配置ID
public int DataID { get; private set; }
//叠加层数
public int CurLevel { get; private set; }
//剩余时间
public float RemainTime { get; private set; }
//参数列表
public List<int> Args { get; private set; }
//增加此buff的时间。用于计算buff剩余时间
public float SyncTime { get; private set; }
public ulong OwenId { get; private set; }
public DeclareBuff Cfg { get; private set; }
//当前剩余时间
public float CurRemainTime
{
get
{
return RemainTime - (Time.realtimeSinceStartup - SyncTime);
}
}
#endregion
#region//公有函数
//刷新buff数据
public void RefreshData(ulong ownerID, DeclareBuff cfg, MSG_Common.Buff buff)
{
OwenId = ownerID;
DataID = buff.buffId;
CurLevel = buff.curLevel;
Cfg = cfg;
RemainTime = buff.remainTime;
Args = buff.args;
SyncTime = Time.realtimeSinceStartup;
}
//处理buff增加事件增加buff特效
public void DoAdd(bool delay)
{
_delayTime = 0f;
if (delay && Cfg.DTime > 0)
{
_delayTime = Cfg.DTime / 1000f;
}
else
{
DoBuffVisualAdd();
AddBuffSpecial();
}
}
//增加buff的外观显示
public void DoBuffVisualAdd(Character inOwner = null)
{
DeleteBuffVfx();
Character owner = null;
if (inOwner != null)
{
owner = inOwner;
}
else
{
owner = GameCenter.GameSceneSystem.FindEntity<Character>(OwenId);
}
//判断特效开关
if (owner != null && GameObjectLimit.CanPlayVfx(owner, ModelTypeCode.BuffVFX))
{
if (Cfg.BuffVfx > 0)
{
_vfxID = owner.Skin.PlayVFX(ModelTypeCode.BuffVFX, Cfg.BuffVfx, SlotUtils.GetSlotName((Slot)Cfg.VfxSlot), FSkinPartCode.Body, true, Cfg.VfxScal / 100.0f, true);
}
}
if (Cfg.Wenzi != 0 && owner != null)
{
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_HUD_POPUP_BUFFNAME, this);
}
}
//增加buff的特殊效果展示
public void AddBuffSpecial(Character inOwner = null)
{
Character owner = null;
if (inOwner != null)
{
owner = inOwner;
}
else
{
owner = GameCenter.GameSceneSystem.FindEntity<Character>(OwenId);
}
OnAddBuffSpecial(owner);
}
//处理buff删除事件删除buff特效
public void DoDelete()
{
DeleteBuffVfx();
DeleteBuffSpecial();
}
//删除buff特效
public void DeleteBuffVfx()
{
if (_vfxID != null)
{
_vfxID.Destroy();
_vfxID = null;
}
}
public void DeleteBuffSpecial()
{
Character owner = GameCenter.GameSceneSystem.FindEntity<Character>(OwenId);
OnDeleteBuffSpecial(owner);
}
//更新
public void Update()
{
OnUpdate();
}
#endregion
#region//子类继承
protected virtual void OnAddBuffSpecial(Character inOwner = null)
{
}
protected virtual void OnDeleteBuffSpecial(Character owner)
{
}
protected virtual void OnUpdate()
{
if (_delayTime > 0 && (Time.realtimeSinceStartup - SyncTime) > _delayTime)
{
DoBuffVisualAdd();
AddBuffSpecial();
_delayTime = 0f;
}
}
#endregion
}
}