-
Notifications
You must be signed in to change notification settings - Fork 0
/
SNonExplodingProjectile.cpp
65 lines (49 loc) · 2.28 KB
/
SNonExplodingProjectile.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
// Fill out your copyright notice in the Description page of Project Settings.
#include "SNonExplodingProjectile.h"
#include "Components/SphereComponent.h"
#include "SGameplayFunctionLibrary.h"
#include "SActionComponent.h"
#include "GameFramework/ProjectileMovementComponent.h"
#include "SActionEffect.h"
ASNonExplodingProjectile::ASNonExplodingProjectile()
{
SphereComp->SetSphereRadius(20.0f);
InitialLifeSpan = 10.0f;
DamageAmount = 20.0f;
}
void ASNonExplodingProjectile::PostInitializeComponents()
{
Super::PostInitializeComponents();
// More consistent to bind here compared to Constructor which may fail to bind if Blueprint was created before adding this binding (or when using hotreload)
// PostInitializeComponent is the preferred way of binding any events.
SphereComp->OnComponentBeginOverlap.AddDynamic(this, &ASNonExplodingProjectile::OnActorOverlap);
}
void ASNonExplodingProjectile::OnActorOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (OtherActor && OtherActor != GetInstigator())
{
//static FGameplayTag Tag = FGameplayTag::RequestGameplayTag("Status.Parrying");
// Parry Ability (GameplayTag Example)
USActionComponent* ActionComp = Cast<USActionComponent>(OtherActor->GetComponentByClass(USActionComponent::StaticClass()));
if (ActionComp && ActionComp->ActiveGameplayTags.HasTag(ParryTag))
{
MoveComp->Velocity = -MoveComp->Velocity;
SetInstigator(Cast<APawn>(OtherActor));
return;
}
/*Count is passed by reference, any changes made to it will also change the value of the
Count in the HitCount Tmap, to keep track of the number of Hits applied to each actor.*/
int& Count = HitCount.FindOrAdd(OtherActor);
if (Count >= MaxHits) return;
//GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, FString::Printf(TEXT("%d"), Count));
Count++;
// Apply Damage & Impulse if Count is less than or equal to MaxHits(int) for Current Key(Actor) in (Tmap)HitCount
if (USGameplayFunctionLibrary::ApplyDirectionalDamage(GetInstigator(), OtherActor, DamageAmount, SweepResult))
{
if (ActionComp && BurningActionClass && HasAuthority())
{
ActionComp->AddAction(GetInstigator(), BurningActionClass);
}
}
}
}