You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.6 KiB

1 month ago
using CoreGame;
using GAS.Runtime;
using Sog;
namespace CoreGame.Render
{
public class CueCdUiEvent : GameplayCueDurational
{
public int slotId = 1;
public CDUIType type = CDUIType.None;
public override GameplayCueDurationalSpec CreateSpec(in GameplayCueParameters param)
{
var spec = SptPool<CueCdUiEventSpec>.Malloc();
spec.Awake(param);
return spec;
}
public override void FreeSpec(ref GameplayCueDurationalSpec spec)
{
var cameraShakeCueSpec = spec as CueCdUiEventSpec;
SptPool<CueCdUiEventSpec>.Free(ref cameraShakeCueSpec);
spec = null;
}
}
public class CueCdUiEventSpec : GameplayCueDurationalSpec<CueCdUiEvent>
{
private readonly float m_TimeSpan = 0.1f;
private float timeAcc;
private CDUIData data = new();
public override void OnAdd()
{
if (ownerEnt.isLocalPlayer)
{
Fixed64 max = initData.sourceGeSpec.Duration;
data.slot = cue.slotId;
data.type = cue.type;
data.lastCd = max;
data.totalCd = max;
EventSrv.DispatchLogicEvent(ClientEvent.OnUICDChange, data);
}
}
public override void OnRemove()
{
if (ownerEnt.isLocalPlayer)
{
Fixed64 max = initData.sourceGeSpec.Duration;
data.slot = cue.slotId;
data.type = cue.type;
data.lastCd = 0;
data.totalCd = max;
EventSrv.DispatchLogicEvent(ClientEvent.OnUICDChange, data);
}
}
public override void OnGameplayEffectActivate()
{
}
public override void OnGameplayEffectDeactivate()
{
}
public override void OnTick(Fixed64 dt)
{
timeAcc += dt;
if (timeAcc < m_TimeSpan)
{
return;
}
timeAcc -= m_TimeSpan;
if (ownerEnt.isLocalPlayer)
{
Fixed64 value = initData.sourceGeSpec.DurationRemaining();
Fixed64 max = initData.sourceGeSpec.Duration;
data.slot = cue.slotId;
data.type = cue.type;
data.lastCd = value;
data.totalCd = max;
EventSrv.DispatchLogicEvent(ClientEvent.OnUICDChange, data);
}
}
public override void Awake(in GameplayCueParameters param)
{
base.Awake(param);
timeAcc = 0;
}
}
}