-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrap_Explosive_comp.cpp
More file actions
127 lines (104 loc) · 3.57 KB
/
Copy pathTrap_Explosive_comp.cpp
File metadata and controls
127 lines (104 loc) · 3.57 KB
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
122
123
124
125
126
127
#include "Trap_Explosive_comp.h"
#include "TrapBase.h"
#include "Components/BoxComponent.h"
#include "WG/WGCharacter.h"
#include "Engine/DamageEvents.h"
UTrap_Explosive_comp::UTrap_Explosive_comp()
{
PrimaryComponentTick.bCanEverTick = true;
bIsTrapCooldown = false;
}
void UTrap_Explosive_comp::BeginPlay()
{
Super::BeginPlay();
}
void UTrap_Explosive_comp::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}
void UTrap_Explosive_comp::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (OverlappedComp == InteractCollision)
{
if (bIsTrapCooldown == false)
{
ExplodePrepare(OtherActor);
SetTrapCooldown(OtherActor);
}
}
}
void UTrap_Explosive_comp::OnOverlapEnd(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
Super::OnOverlapEnd(OverlappedComp, OtherActor, OtherComp, OtherBodyIndex);
}
void UTrap_Explosive_comp::ExplodePrepare(AActor* OtherActor)
{
if(InteractCollision->IsOverlappingActor(OtherActor))
{
OwnerActor->ChangeMaterialColor(FLinearColor::Yellow);
auto Lambda = [this, OtherActor]()
{
Explode(OtherActor);
};
GetWorld()->GetTimerManager().SetTimer(ExplodeTimerHandle, Lambda, TimeForExplosion, false);
}
}
void UTrap_Explosive_comp::Explode(AActor* OtherActor)
{
OwnerActor->ChangeMaterialColor(FLinearColor::Red);
// Cause damage to all players that stand at the platform
// In case that is solo game, there is no need to cause damage to all players that stand on platform
// We could make same thing just one with if CollisionComp->IsOverlappingActor(OtherActor)
// But in case of test work we will get TArray of actors and cause damage to each who is a Player
// TODO: UE native AOE damage
TArray<AActor*> OverlappingActors;
InteractCollision->GetOverlappingActors(OverlappingActors);
for (AActor* Actor : OverlappingActors)
{
AWGCharacter* Character = Cast<AWGCharacter>(Actor);
if (Character)
{
FDamageEvent DamageEvent;
Character->ApplyDamage(TrapDamage, DamageEvent,this->GetOwner()->GetInstigatorController(),OwnerActor);
}
}
GetWorld()->GetTimerManager().SetTimer(RedColorTimerHandle, this, &UTrap_Explosive_comp::ResetMaterial, MaterialResetTime, false);
if(InteractCollision->IsOverlappingActor(OtherActor) && bIsTrapCooldown == false)
{
auto Lambda = [this, OtherActor]()
{
ExplodePrepare(OtherActor);
};
GetWorld()->GetTimerManager().SetTimer(ExplodeCooldownHandle, Lambda, 0, true);
}
}
void UTrap_Explosive_comp::ResetMaterial()
{
OwnerActor->ChangeMaterialColor(FLinearColor::Gray);
}
void UTrap_Explosive_comp::SetTrapCooldown(AActor* OtherActor)
{
bIsTrapCooldown = true;
auto Lambda = [this, OtherActor]()
{
ResetTrapCooldown(OtherActor);
};
GetWorld()->GetTimerManager().SetTimer(CooldownHandle, Lambda,CooldownDuration, false);
}
void UTrap_Explosive_comp::ResetTrapCooldown(AActor* OtherActor)
{
bIsTrapCooldown = false;
if (OtherActor && OtherActor->IsA<AWGCharacter>() && InteractCollision->IsOverlappingActor(OtherActor))
{
ExplodePrepare(OtherActor);
SetTrapCooldown(OtherActor);
}
}
void UTrap_Explosive_comp::ResetTimer()
{
GetWorld()->GetTimerManager().ClearTimer(ExplodeTimerHandle);
GetWorld()->GetTimerManager().ClearTimer(RedColorTimerHandle);
GetWorld()->GetTimerManager().ClearTimer(ExplodeCooldownHandle);
GetWorld()->GetTimerManager().ClearTimer(CooldownHandle);
}