:(
This commit is contained in:
75
Source/Aura/Private/Actor/AuraProjectile.cpp
Normal file
75
Source/Aura/Private/Actor/AuraProjectile.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
// Copyright Echo Devgroup
|
||||
|
||||
#include "Actor/AuraProjectile.h"
|
||||
|
||||
#include "AbilitySystemBlueprintLibrary.h"
|
||||
#include "AbilitySystemComponent.h"
|
||||
#include "NiagaraFunctionLibrary.h"
|
||||
#include "Aura/Aura.h"
|
||||
#include "Components/AudioComponent.h"
|
||||
#include "Components/SphereComponent.h"
|
||||
#include "GameFramework/ProjectileMovementComponent.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
AAuraProjectile::AAuraProjectile()
|
||||
{
|
||||
bReplicates = true;
|
||||
PrimaryActorTick.bCanEverTick = false;
|
||||
Sphere = CreateDefaultSubobject<USphereComponent>("Sphere");
|
||||
SetRootComponent(Sphere);
|
||||
Sphere->SetCollisionObjectType(ECC_PROJECTILE);
|
||||
Sphere->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
||||
Sphere->SetCollisionResponseToAllChannels(ECR_Ignore);
|
||||
Sphere->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
||||
Sphere->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
||||
Sphere->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
||||
|
||||
ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>("ProjectileMovement");
|
||||
ProjectileMovement->InitialSpeed = 550.f;
|
||||
ProjectileMovement->MaxSpeed = 550.f;
|
||||
ProjectileMovement->ProjectileGravityScale = 0.f;
|
||||
}
|
||||
|
||||
void AAuraProjectile::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
SetLifeSpan(LifeSpan);
|
||||
Sphere->OnComponentBeginOverlap.AddDynamic(this, &AAuraProjectile::OnSphereOverlap);
|
||||
LoopingSoundComponent = UGameplayStatics::SpawnSoundAttached(LoopingSound, GetRootComponent());
|
||||
}
|
||||
|
||||
void AAuraProjectile::Destroyed()
|
||||
{
|
||||
if (!bHit && !HasAuthority())
|
||||
{
|
||||
UGameplayStatics::PlaySoundAtLocation(GetWorld(), ImpactSound, GetActorLocation());
|
||||
UNiagaraFunctionLibrary::SpawnSystemAtLocation(this, ImpactEffect, GetActorLocation());
|
||||
LoopingSoundComponent->Stop();
|
||||
}
|
||||
Super::Destroyed();
|
||||
}
|
||||
|
||||
void AAuraProjectile::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent,
|
||||
AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp,
|
||||
int32 OtherBodyIndex,
|
||||
bool bFromSweep,
|
||||
const FHitResult& SweepResult)
|
||||
{
|
||||
if (OtherActor == GetInstigator()) return; //So that the projectile will not collide with the owning actor.
|
||||
UGameplayStatics::PlaySoundAtLocation(GetWorld(), ImpactSound, GetActorLocation());
|
||||
UNiagaraFunctionLibrary::SpawnSystemAtLocation(this, ImpactEffect, GetActorLocation());
|
||||
LoopingSoundComponent->Stop();
|
||||
|
||||
if (HasAuthority())
|
||||
{
|
||||
if (UAbilitySystemComponent* TargetASC = UAbilitySystemBlueprintLibrary::GetAbilitySystemComponent(OtherActor))
|
||||
{
|
||||
TargetASC->ApplyGameplayEffectSpecToSelf(*DamageEffectSpecHandle.Data.Get());
|
||||
}
|
||||
Destroy();
|
||||
}
|
||||
else { bHit = true; }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user