-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWotAction.cpp
90 lines (75 loc) · 2.06 KB
/
WotAction.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "WotAction.h"
#include "WotActionComponent.h"
#include "GameFramework/Pawn.h"
#include "GameFramework/PawnMovementComponent.h"
UWotAction::UWotAction()
{
}
bool UWotAction::CanStart_Implementation(AActor* Instigator)
{
if (IsRunning()) {
return false;
}
UWotActionComponent* Comp = GetOwningComponent();
if (Comp->ActiveGameplayTags.HasAny(BlockedTags)) {
return false;
}
if (!Comp->ActiveGameplayTags.HasAll(RequiredTags)) {
return false;
}
// check if the instigator is falling
if (!bAllowedWhileFalling) {
// cast the actor to a pawn
APawn* Pawn = Cast<APawn>(Instigator);
if (Pawn && Pawn->GetMovementComponent()->IsFalling()) {
return false;
}
}
return true;
}
void UWotAction::Start_Implementation(AActor* Instigator)
{
UE_LOG(LogTemp, Log, TEXT("Running: %s"), *GetNameSafe(this));
UWotActionComponent* Comp = GetOwningComponent();
if (!ensure(Comp)) {
UE_LOG(LogTemp, Error, TEXT("Owning ActionComponent is null!"));
return;
}
// add the tags we grant
Comp->ActiveGameplayTags.AppendTags(GrantsTags);
// remove the tags we remove
Comp->ActiveGameplayTags.RemoveTags(RemovesTags);
// make sure to update the running flag
bIsRunning = true;
}
void UWotAction::Stop_Implementation(AActor* Instigator)
{
UE_LOG(LogTemp, Log, TEXT("Stopping: %s"), *GetNameSafe(this));
ensureAlways(bIsRunning);
UWotActionComponent* Comp = GetOwningComponent();
if (!ensure(Comp)) {
UE_LOG(LogTemp, Error, TEXT("Owning ActionComponent is null!"));
return;
}
// remove the tags we grant
Comp->ActiveGameplayTags.RemoveTags(GrantsTags);
// make sure to update the running flag
bIsRunning = false;
}
UWorld* UWotAction::GetWorld() const
{
// Outer is set when creating action via NewObject<T>
UActorComponent* Comp = Cast<UActorComponent>(GetOuter());
if (Comp) {
return Comp->GetWorld();
}
return nullptr;
}
UWotActionComponent* UWotAction::GetOwningComponent() const
{
return Cast<UWotActionComponent>(GetOuter());
}
bool UWotAction::IsRunning() const
{
return bIsRunning;
}