-
Notifications
You must be signed in to change notification settings - Fork 0
/
SActionEffect.cpp
75 lines (52 loc) · 1.53 KB
/
SActionEffect.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Fill out your copyright notice in the Description page of Project Settings.
#include "SActionEffect.h"
#include "SActionComponent.h"
#include "GameFramework/GameStateBase.h"
USActionEffect::USActionEffect()
{
bAutoStart = true;
}
void USActionEffect::StartAction_Implementation(AActor* Instigator)
{
Super::StartAction_Implementation(Instigator);
if (Duration > 0.0f)
{
FTimerDelegate Delegate;
Delegate.BindUFunction(this, "StopAction", Instigator);
GetWorld()->GetTimerManager().SetTimer(DurationHandle, Delegate, Duration, false);
}
if (Period > 0.0f)
{
FTimerDelegate Delegate;
Delegate.BindUFunction(this, "ExecutePeriodicEffect", Instigator);
GetWorld()->GetTimerManager().SetTimer(PeriodHandle, Delegate, Period, true);
}
}
void USActionEffect::StopAction_Implementation(AActor* Instigator)
{
if (GetWorld()->GetTimerManager().GetTimerRemaining(PeriodHandle) < KINDA_SMALL_NUMBER)
{
ExecutePeriodicEffect(Instigator);
}
Super::StopAction_Implementation(Instigator);
GetWorld()->GetTimerManager().ClearTimer(PeriodHandle);
GetWorld()->GetTimerManager().ClearTimer(DurationHandle);
USActionComponent* Comp = GetOwningComponent();
if (Comp)
{
Comp->RemoveAction(this);
}
}
float USActionEffect::GetTimeRemaining() const
{
AGameStateBase* GS = GetWorld()->GetGameState<AGameStateBase>();
if (GS)
{
float EndTime = TimeStarted + Duration;
return EndTime - GS->GetServerWorldTimeSeconds();
}
return Duration;
}
void USActionEffect::ExecutePeriodicEffect_Implementation(AActor* Instigator)
{
}