From d326d7a56c1ba9273cbbff4ecfff3b85e4a9e4f4 Mon Sep 17 00:00:00 2001 From: Jonathan Rampersad Date: Sun, 8 Jun 2025 12:13:51 -0400 Subject: [PATCH] Effect Actor (Basic Implementation) --- .../Blueprints/Actors/BP_HealthPotion.uasset | 3 ++ Content/Maps/StartupMap.umap | 4 +- Source/Aura/Private/Actor/AuraEffectActor.cpp | 51 +++++++++++++++++++ Source/Aura/Public/Actor/AuraEffectActor.h | 37 ++++++++++++++ 4 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 Content/Blueprints/Actors/BP_HealthPotion.uasset create mode 100644 Source/Aura/Private/Actor/AuraEffectActor.cpp create mode 100644 Source/Aura/Public/Actor/AuraEffectActor.h diff --git a/Content/Blueprints/Actors/BP_HealthPotion.uasset b/Content/Blueprints/Actors/BP_HealthPotion.uasset new file mode 100644 index 0000000..a0428af --- /dev/null +++ b/Content/Blueprints/Actors/BP_HealthPotion.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6402aca822e193952c03cd8c6a085fefdd8c24d3ca6e784cbd0006be70777c88 +size 31349 diff --git a/Content/Maps/StartupMap.umap b/Content/Maps/StartupMap.umap index 7258a21..ccf8f5b 100644 --- a/Content/Maps/StartupMap.umap +++ b/Content/Maps/StartupMap.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5c425e1027540bd9081efc0140a25d1867796d1e391a4ccf498d1c29be7d0269 -size 51546 +oid sha256:30ab3ec2087baef160acef36b433e315d88674a9d16a4020cb2cb52b344e3e20 +size 54538 diff --git a/Source/Aura/Private/Actor/AuraEffectActor.cpp b/Source/Aura/Private/Actor/AuraEffectActor.cpp new file mode 100644 index 0000000..7d3f624 --- /dev/null +++ b/Source/Aura/Private/Actor/AuraEffectActor.cpp @@ -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(TEXT("Mesh")); + SetRootComponent(Mesh); + + Sphere = CreateDefaultSubobject(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(OtherActor)) + { + const UAuraAttributeSet* AuraAttributeSet = Cast(ASCInterface->GetAbilitySystemComponent()->GetAttributeSet(UAuraAttributeSet::StaticClass())); + UAuraAttributeSet* MutableAuraAttributeSet = const_cast(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); +} + + diff --git a/Source/Aura/Public/Actor/AuraEffectActor.h b/Source/Aura/Public/Actor/AuraEffectActor.h new file mode 100644 index 0000000..46329dc --- /dev/null +++ b/Source/Aura/Public/Actor/AuraEffectActor.h @@ -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 Mesh; + + UPROPERTY(VisibleAnywhere) + TObjectPtr Sphere; + +};