-
Notifications
You must be signed in to change notification settings - Fork 0
/
SAction.cpp
121 lines (85 loc) · 2.46 KB
/
SAction.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Fill out your copyright notice in the Description page of Project Settings.
#include "SAction.h"
#include "SActionComponent.h"
#include "../ActionRoguelike.h"
#include "Net/UnrealNetwork.h"
void USAction::Initialize(USActionComponent* NewActionComp)
{
ActionComp = NewActionComp;
}
bool USAction::CanStart_Implementation(AActor* Instigator)
{
if (IsRunning())
{
return false;
}
USActionComponent* Comp = GetOwningComponent();
if (Comp->ActiveGameplayTags.HasAny(BlockedTags))
{
return false;
}
return true;
}
void USAction::StartAction_Implementation(AActor* Instigator)
{
UE_LOG(LogTemp, Log, TEXT("Started: %s"), *GetNameSafe(this));
//LogOnScreen(this, FString::Printf(TEXT("Started: %s"), *ActionName.ToString()), FColor::Green);
USActionComponent* Comp = GetOwningComponent();
Comp->ActiveGameplayTags.AppendTags(GrantsTags);
RepData.bIsRunning = true;
RepData.Instigator = Instigator;
if (GetOwningComponent()->GetOwnerRole() == ROLE_Authority)
{
TimeStarted = GetWorld()->TimeSeconds;
}
GetOwningComponent()->OnActionStarted.Broadcast(GetOwningComponent(), this);
}
void USAction::StopAction_Implementation(AActor* Instigator)
{
UE_LOG(LogTemp, Log, TEXT("Stopped: %s"), *GetNameSafe(this));
//LogOnScreen(this, FString::Printf(TEXT("Stopped: %s"), *ActionName.ToString()), FColor::White);
//ensureAlways(bIsRunning);
USActionComponent* Comp = GetOwningComponent();
Comp->ActiveGameplayTags.RemoveTags(GrantsTags);
RepData.bIsRunning = false;
RepData.Instigator = Instigator;
GetOwningComponent()->OnActionStopped.Broadcast(GetOwningComponent(), this);
}
UWorld* USAction::GetWorld() const
{
// Outer is set when creating action via NewObject<T>
AActor* Actor = Cast<AActor>(GetOuter());
if (Actor)
{
return Actor->GetWorld();
}
return nullptr;
}
USActionComponent* USAction::GetOwningComponent() const
{
//AActor* Actor = Cast<AActor>(GetOuter());
//return Actor->GetComponentByClass(USActionComponent::StaticClass());
return ActionComp;
}
void USAction::OnRep_RepData()
{
if (RepData.bIsRunning)
{
StartAction(RepData.Instigator);
}
else
{
StopAction(RepData.Instigator);
}
}
bool USAction::IsRunning() const
{
return RepData.bIsRunning;
}
void USAction::GetLifetimeReplicatedProps(TArray<class FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(USAction, RepData);
DOREPLIFETIME(USAction, TimeStarted);
DOREPLIFETIME(USAction, ActionComp);
}