Files
Main/Assets/Code/Logic/_Required/Entity/Character/Skill/SkillObjectSkill.cs

203 lines
8.5 KiB
C#
Raw Normal View History

2025-01-25 04:38:09 +08:00
using Thousandto.Cfg.Data;
using Thousandto.Code.Center;
using Thousandto.Code.Global;
using Thousandto.Code.Logic.WarningField;
using Thousandto.Core.Asset;
using Thousandto.Core.Base;
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using Thousandto.Core.PostEffect;
namespace Thousandto.Code.Logic
{
public class SkillObjectSkill
{
private SkillObject _owner = null;
private SkillVisualInfo _skillVisualDef = null;
private float _frameTimer = 0f;
public const float OneFrameTime = 1f / 30f;
private uint _nonceFrame = 0;
private bool _isEnd = false;
private FGameObjectVFXBox _vfxIDList = new FGameObjectVFXBox();
public SkillVisualInfo SkillVisualDef
{
get
{
return _skillVisualDef;
}
}
public SkillObject Owner
{
get
{
return _owner;
}
set
{
_owner = value;
}
}
public bool IsEnd
{
get
{
return _isEnd;
}
}
public bool DoCreate(SkillVisualInfo cfg, SkillObject owner)
{
_owner = owner;
_skillVisualDef = cfg;
return true;
}
private void DoEvent(uint frame)
{
for (int i = 0; i < _skillVisualDef.DataList.Count; ++i)
{
if (frame == _skillVisualDef.DataList[i].EventFrame)
{
switch (_skillVisualDef.DataList[i].EventType)
{
case SkillEventDefine.PlayVfx:
{
var objOwner = GameCenter.GameSceneSystem.FindEntity<Character>(_owner.OwnerID);
if (GameObjectLimit.CanPlayVfx(objOwner, ModelTypeCode.SkillVFX))
{
var vfxEvent = _skillVisualDef.DataList[i] as PlayVfxEventInfo;
if (vfxEvent.VfxID > 0)
{
//Debug.LogError("召唤物释放技能!!"+";;;;"+ vfxEvent.VfxID);
var lod = 0;
if (!objOwner.IsLocalPlayer() && !objOwner.IsLocalFlySword())
{//只针对其他玩家
//这里因为GameSettingKeyCode.OtherPlayerSkillVfxLevel的值是:0屏蔽全部,1弱,2中,3强.
//而lod是0最强,往下最弱.
lod = FGameObjectVFXRoot.CN_VFX_LEVEL_MAX - GameCenter.GameSetting[GameSettingKeyCode.OtherPlayerSkillVfxLevel]; ;
}
var vfxID = new FGameObjectVFX(ModelTypeCode.SkillVFX, vfxEvent.VfxID, true, false, lod);
vfxID.SetLayer(Owner.Layer);
vfxID.SetParent(Owner.ModelTransform);
vfxID.SetLocalPosition(Vector3.zero);
vfxID.SetLocalEulerAngles(Vector3.zero);
if(!SkillVisualDef.EndClearVfx)
{
//技能不在结束时清除的特效强制设置为非loop
vfxID.IsNotLoop = true;
}
vfxID.Play();
_vfxIDList.Add(vfxID);
//10倍技能帧数
var vfxLifeTime = _skillVisualDef.FrameCount * OneFrameTime * 10;
if (vfxLifeTime < 5f)
{
vfxLifeTime = 5f;
}
vfxID.LiftTime = vfxLifeTime;
}
}
}
break;
case SkillEventDefine.PlaySfx:
{
var sfxEvent = _skillVisualDef.DataList[i] as PlaySfxEventInfo;
AudioPlayer.PlaySfx(null, sfxEvent.Sound, true);
}
break;
case SkillEventDefine.PlayBlur:
{
var owner = GameCenter.GameSceneSystem.FindEntity<Character>(Owner.OwnerID);
if (owner != null && (owner.IsLocalPlayer() || owner.IsLocalFlySword()))
{
if (GameCenter.GameSetting.IsEnabled(GameSettingKeyCode.EnablePostEffect) && !GameCenter.GameSetting.IsEnabled(GameSettingKeyCode.TPSkillBloom) && GameCenter.GameSetting.IsEnabled(GameSettingKeyCode.EnableRadialBlurEffect))
{
var Info = _skillVisualDef.DataList[i] as PlayBlurEventInfo;
if (Info.BlurType == 0)
{
PostEffectManager.Instance.PlayRadiaBlur(Info.Start, Info.End, Info.Time);
}
else
{
PostEffectManager.Instance.PlayGaussBlur(Info.GrassBlurSize, Info.Time);
}
}
}
}
break;
case SkillEventDefine.PlayCameraShake:
{
var owner = GameCenter.GameSceneSystem.FindEntity<Character>(Owner.OwnerID);
if (owner != null && (owner.IsLocalPlayer() || owner.IsLocalFlySword()))
{
var Info = _skillVisualDef.DataList[i] as PlayCameraShakeEventInfo;
if (!GameCenter.GameSetting.IsEnabled(GameSettingKeyCode.TPSkillShake) && GameCenter.GameSetting.IsEnabled(GameSettingKeyCode.EnableShakeEffect))
{
PostEffectManager.Instance.PlayCameraShake(Info.Curve, Info.CurveTotalTime, Info.CurveType, Info.CurvePower);
}
}
}
break;
case SkillEventDefine.PlaySlow:
{
var owner = GameCenter.GameSceneSystem.FindEntity<Character>(Owner.OwnerID);
if (owner != null && (owner.IsLocalPlayer() || owner.IsLocalFlySword()))
{
var Info = _skillVisualDef.DataList[i] as PlaySlowEventInfo;
GameCenter.GameSceneSystem.DoTimeScale(Info.TimeScale, Info.Time);
}
}
break;
}
}
}
}
public void Start()
{
_nonceFrame = 0;
_frameTimer = 0f;
_vfxIDList.Clear();
DoEvent(_nonceFrame);
CombatUtil.ShowWarningFiled(_skillVisualDef, _owner);
}
public void Stop()
{
_vfxIDList.Clear(SkillVisualDef.EndClearVfx);
}
public void Update(float dt)
{
if (IsEnd)
return;
_frameTimer += dt;
while (_frameTimer >= OneFrameTime)
{
_frameTimer -= OneFrameTime;
++_nonceFrame;
DoEvent(_nonceFrame);
}
if (_nonceFrame >= _skillVisualDef.FrameCount)
{
//技能结束
_isEnd = true;
}
_vfxIDList.Update(0);
}
}
}