// 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("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("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)) { //UE_LOG(LogTemp,Warning,TEXT("Projectile - TargetASC %s - OtherActor %s"), *TargetASC->GetName(), *OtherActor->GetName()); TargetASC->ApplyGameplayEffectSpecToSelf(*DamageEffectSpecHandle.Data.Get()); } Destroy(); } else { bHit = true; } }