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;
CurrentEXP += value;
OnEXPGained.ExecuteIfBound(value);
OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
CurrentLevel = FMath::Floor(CurrentEXP / 100.0f);
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
CurrentEXP = value;
OnEXPGained.ExecuteIfBound(value);
OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
CurrentLevel = FMath::Floor(CurrentEXP / 100.0f);
if (CurrentLevel != oldLevel)
{
OnEXPLevelUp.ExecuteIfBound(CurrentLevel);
OnEXPLevelUp.Broadcast(CurrentLevel);
}
}
@ -60,8 +60,8 @@ void UEXPComponent::Reset()
{
CurrentEXP = 0;
CurrentLevel = 0;
OnEXPGained.ExecuteIfBound(CurrentEXP);
OnEXPLevelUp.ExecuteIfBound(CurrentLevel);
OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
OnEXPLevelUp.Broadcast(CurrentLevel);
}
float UEXPComponent::GetCurrentLevelPercent()

View File

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