Effect Actor (Basic Implementation)
This commit is contained in:
51
Source/Aura/Private/Actor/AuraEffectActor.cpp
Normal file
51
Source/Aura/Private/Actor/AuraEffectActor.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
// Assets provided by DruidMechanics. Copyright Jonathan Rampersad 2024
|
||||
|
||||
|
||||
#include "Actor/AuraEffectActor.h"
|
||||
|
||||
#include "AbilitySystemComponent.h"
|
||||
#include "AbilitySystemInterface.h"
|
||||
#include "AbilitySystem/AuraAttributeSet.h"
|
||||
#include "Components/SphereComponent.h"
|
||||
|
||||
// Sets default values
|
||||
AAuraEffectActor::AAuraEffectActor()
|
||||
{
|
||||
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||
PrimaryActorTick.bCanEverTick = false;
|
||||
|
||||
Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
|
||||
SetRootComponent(Mesh);
|
||||
|
||||
Sphere = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere"));
|
||||
Sphere->SetupAttachment(GetRootComponent());
|
||||
}
|
||||
|
||||
void AAuraEffectActor::OnOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
|
||||
{
|
||||
//TODO: Change this to apply a Gameplay Effect. For now using const_cast as a hack!
|
||||
if (const IAbilitySystemInterface* ASCInterface = Cast<IAbilitySystemInterface>(OtherActor))
|
||||
{
|
||||
const UAuraAttributeSet* AuraAttributeSet = Cast<UAuraAttributeSet>(ASCInterface->GetAbilitySystemComponent()->GetAttributeSet(UAuraAttributeSet::StaticClass()));
|
||||
UAuraAttributeSet* MutableAuraAttributeSet = const_cast<UAuraAttributeSet*>(AuraAttributeSet);
|
||||
MutableAuraAttributeSet->SetHealth(AuraAttributeSet->GetHealth() + 25.f);
|
||||
}
|
||||
}
|
||||
|
||||
void AAuraEffectActor::EndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
void AAuraEffectActor::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
Sphere->OnComponentBeginOverlap.AddDynamic(this, &AAuraEffectActor::OnOverlap);
|
||||
Sphere->OnComponentEndOverlap.AddDynamic(this, &AAuraEffectActor::EndOverlap);
|
||||
}
|
||||
|
||||
|
37
Source/Aura/Public/Actor/AuraEffectActor.h
Normal file
37
Source/Aura/Public/Actor/AuraEffectActor.h
Normal file
@ -0,0 +1,37 @@
|
||||
// Assets provided by DruidMechanics. Copyright Jonathan Rampersad 2024
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "AuraEffectActor.generated.h"
|
||||
|
||||
class USphereComponent;
|
||||
|
||||
UCLASS()
|
||||
class AURA_API AAuraEffectActor : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Sets default values for this actor's properties
|
||||
AAuraEffectActor();
|
||||
|
||||
UFUNCTION()
|
||||
virtual void OnOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
|
||||
|
||||
UFUNCTION()
|
||||
virtual void EndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
private:
|
||||
UPROPERTY(VisibleAnywhere)
|
||||
TObjectPtr<UStaticMeshComponent> Mesh;
|
||||
|
||||
UPROPERTY(VisibleAnywhere)
|
||||
TObjectPtr<USphereComponent> Sphere;
|
||||
|
||||
};
|
Reference in New Issue
Block a user