26. Effect Actor complete

This commit is contained in:
Edward R. Gonzalez 2024-04-13 19:29:25 -04:00
parent c2e5793a7d
commit 7b9e277bc1
10 changed files with 129 additions and 2 deletions

BIN
Project/Content/Core/Pickups/BP_HealthPotion.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Project/Content/Levels/StartupMap.umap (Stored with Git LFS)

Binary file not shown.

View File

@ -2,3 +2,4 @@
#include "GasaCommon.h" #include "GasaCommon.h"

View File

@ -147,3 +147,12 @@ public:
void GetLifetimeReplicatedProps( TArray< FLifetimeProperty >& OutLifetimeProps ) const override; void GetLifetimeReplicatedProps( TArray< FLifetimeProperty >& OutLifetimeProps ) const override;
#pragma endregion UObject #pragma endregion UObject
}; };
namespace Gasa
{
inline UGasaAttributeSet const* GetAttributeSet( UAbilitySystemComponent* ASC )
{
return Cast< UGasaAttributeSet >( ASC->GetAttributeSet( UGasaAttributeSet::StaticClass() ) );
}
}

View File

@ -0,0 +1,61 @@
#include "GasaEffectActor.h"
#include "AbilitySystemComponent.h"
#include "AbilitySystemInterface.h"
#include "GasaAttributeSet.h"
#include "Components/SphereComponent.h"
AGasaEffectActor::AGasaEffectActor()
{
PrimaryActorTick.bCanEverTick = false;
Mesh = CreateDefaultSubobject<UStaticMeshComponent>("Mesh");
Sphere = CreateDefaultSubobject<USphereComponent>("Sphere");
SetRootComponent(Mesh);
Sphere->SetupAttachment(Mesh);
}
void AGasaEffectActor::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent
, AActor* OtherActor
, UPrimitiveComponent* OtherComp
, int32 OtherBodyIndex
, bool bFromSweep
, FHitResult const& SweepResult)
{
// Demo of "restricted way"
if ( ! OtherActor->Implements<UAbilitySystemInterface>())
return;
IAbilitySystemInterface* ASI = Cast<IAbilitySystemInterface>(OtherActor);
if (ASI == nullptr)
return;
// TODO(Ed): Change this to use a gameplay effect instead
UAbilitySystemComponent* AbilitySystem = ASI->GetAbilitySystemComponent();
UGasaAttributeSet* MutAttributes = const_cast<UGasaAttributeSet*>(Gasa::GetAttributeSet(AbilitySystem));
MutAttributes->SetHealth( MutAttributes->GetHealth() + 25.f );
Destroy();
}
void AGasaEffectActor::OnOverlapEnd(UPrimitiveComponent* OverlappedComponent
, AActor* OtherActor
, UPrimitiveComponent* OtherComp
, int32 OtherBodyIndex)
{
}
void AGasaEffectActor::BeginPlay()
{
Super::BeginPlay();
}
void AGasaEffectActor::PostInitializeComponents()
{
Super::PostInitializeComponents();
Sphere->OnComponentBeginOverlap.AddUniqueDynamic(this, &ThisClass::OnOverlapBegin);
Sphere->OnComponentEndOverlap.AddUniqueDynamic(this, &ThisClass::OnOverlapEnd);
}

View File

@ -0,0 +1,39 @@
#pragma once
#include "GasaCommon.h"
#include "GasaEffectActor.generated.h"
UCLASS()
class GASA_API AGasaEffectActor : public AActor
{
GENERATED_BODY()
public:
UPROPERTY(VisibleAnywhere)
TObjectPtr<UStaticMeshComponent> Mesh;
UPROPERTY(VisibleAnywhere)
TObjectPtr<USphereComponent> Sphere;
AGasaEffectActor();
UFUNCTION()
void OnOverlapBegin(UPrimitiveComponent* OverlappedComponent
, AActor* OtherActor
, UPrimitiveComponent* OtherComp
, int32 OtherBodyIndex
, bool bFromSweep
, FHitResult const& SweepResult);
UFUNCTION()
void OnOverlapEnd(UPrimitiveComponent* OverlappedComponent
, AActor* OtherActor
, UPrimitiveComponent* OtherComp
, int32 OtherBodyIndex);
#pragma region Actor
void BeginPlay() override;
void PostInitializeComponents() override;
#pragma endregion Actor
};

View File

@ -23,6 +23,7 @@ class UAttributeSet;
class UCameraComponent; class UCameraComponent;
class UInputAction; class UInputAction;
class UInputMappingContext; class UInputMappingContext;
class USphereComponent;
class USpringArmComponent; class USpringArmComponent;
#pragma endregion Engine Forwards #pragma endregion Engine Forwards
@ -41,6 +42,7 @@ class AGasaLevelScriptActor;
class AGasaPlayerController; class AGasaPlayerController;
class UGasaAbilitySystemComp; class UGasaAbilitySystemComp;
class UGasaAttributeSet;
class UGasaDevOptions; class UGasaDevOptions;
#pragma endregion Forwards #pragma endregion Forwards

View File

@ -208,12 +208,24 @@ int gen_main()
); );
} }
CodeNS ns_gasa = parse_namespace( code(
namespace Gasa
{
inline
UGasaAttributeSet const* GetAttributeSet( UAbilitySystemComponent* ASC )
{
return Cast<UGasaAttributeSet>(ASC->GetAttributeSet( UGasaAttributeSet::StaticClass() ));
}
}
));
header.print( Include_AttributeSet); header.print( Include_AttributeSet);
header.print( Include_AbilitySystemComponent); header.print( Include_AbilitySystemComponent);
header.print( Include_GasaAttributeSet_Generated); header.print( Include_GasaAttributeSet_Generated);
header.print( fmt_newline); header.print( fmt_newline);
header.print(umeta_uclass); header.print(umeta_uclass);
header.print(GasaAttributeSet); header.print(GasaAttributeSet);
header.print(ns_gasa);
} }
header.write(); header.write();
} }