Make delegates DYNAMIC_MULTICAST

This commit is contained in:
baz 2024-11-16 02:18:36 +00:00
parent 0bdda47b8b
commit dd8cc06e33
2 changed files with 11 additions and 8 deletions

View File

@ -19,13 +19,13 @@ void UEXPComponent::IncrementEXP(int value)
int oldLevel = CurrentLevel; int oldLevel = CurrentLevel;
CurrentEXP += value; CurrentEXP += value;
OnEXPGained.ExecuteIfBound(value); OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
CurrentLevel = FMath::Floor(CurrentEXP / 100.0f); CurrentLevel = FMath::Floor(CurrentEXP / 100.0f);
if (CurrentLevel != oldLevel) if (CurrentLevel != oldLevel)
{ {
OnEXPLevelUp.ExecuteIfBound(CurrentLevel); OnEXPLevelUp.Broadcast(CurrentLevel);
} }
} }
@ -36,13 +36,13 @@ void UEXPComponent::SetCurrentEXP(int value)
// TODO: I should be updating the level here // TODO: I should be updating the level here
CurrentEXP = value; CurrentEXP = value;
OnEXPGained.ExecuteIfBound(value); OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
CurrentLevel = FMath::Floor(CurrentEXP / 100.0f); CurrentLevel = FMath::Floor(CurrentEXP / 100.0f);
if (CurrentLevel != oldLevel) if (CurrentLevel != oldLevel)
{ {
OnEXPLevelUp.ExecuteIfBound(CurrentLevel); OnEXPLevelUp.Broadcast(CurrentLevel);
} }
} }
@ -60,8 +60,8 @@ void UEXPComponent::Reset()
{ {
CurrentEXP = 0; CurrentEXP = 0;
CurrentLevel = 0; CurrentLevel = 0;
OnEXPGained.ExecuteIfBound(CurrentEXP); OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
OnEXPLevelUp.ExecuteIfBound(CurrentLevel); OnEXPLevelUp.Broadcast(CurrentLevel);
} }
float UEXPComponent::GetCurrentLevelPercent() float UEXPComponent::GetCurrentLevelPercent()

View File

@ -6,8 +6,8 @@
#include "Components/ActorComponent.h" #include "Components/ActorComponent.h"
#include "EXPComponent.generated.h" #include "EXPComponent.generated.h"
DECLARE_DELEGATE_OneParam(FOnEXPGainedDelegate, int) DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnEXPGainedDelegate, int, exp, float, currentLevelPercent);
DECLARE_DELEGATE_OneParam(FOnEXPLevelUpDelegate, int) DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnEXPLevelUpDelegate, int, level);
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class VAMPIRES_API UEXPComponent : public UActorComponent class VAMPIRES_API UEXPComponent : public UActorComponent
@ -15,7 +15,10 @@ class VAMPIRES_API UEXPComponent : public UActorComponent
GENERATED_BODY() GENERATED_BODY()
public: public:
UPROPERTY(BlueprintAssignable, Category="EXP")
FOnEXPGainedDelegate OnEXPGained; FOnEXPGainedDelegate OnEXPGained;
UPROPERTY(BlueprintAssignable, Category="EXP")
FOnEXPLevelUpDelegate OnEXPLevelUp; FOnEXPLevelUpDelegate OnEXPLevelUp;
protected: protected: