From 45b2120cb53369b6e2fd986ccccebf3036cf9d71 Mon Sep 17 00:00:00 2001 From: baz Date: Tue, 20 Aug 2024 23:32:24 +0100 Subject: [PATCH] Add Leveling to EXPComponent --- Source/vampires/EXPComponent.cpp | 27 +++++++++++++++++++++++++-- Source/vampires/EXPComponent.h | 3 +++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Source/vampires/EXPComponent.cpp b/Source/vampires/EXPComponent.cpp index d43bd5f..d0acb78 100644 --- a/Source/vampires/EXPComponent.cpp +++ b/Source/vampires/EXPComponent.cpp @@ -15,17 +15,35 @@ UEXPComponent::UEXPComponent() void UEXPComponent::IncrementEXP(int value) { - // TODO: I should be updating the level here + int oldEXP = CurrentEXP; + int oldLevel = CurrentLevel; + CurrentEXP += value; OnEXPGained.ExecuteIfBound(value); - OnEXPLevelUp.ExecuteIfBound(CurrentLevel); + + CurrentLevel = FMath::Floor(CurrentEXP / 100.0f); + + if (CurrentLevel != oldLevel) + { + OnEXPLevelUp.ExecuteIfBound(CurrentLevel); + } } void UEXPComponent::SetCurrentEXP(int value) { + int oldEXP = CurrentEXP; + int oldLevel = CurrentLevel; + // TODO: I should be updating the level here CurrentEXP = value; OnEXPGained.ExecuteIfBound(value); + + CurrentLevel = FMath::Floor(CurrentEXP / 100.0f); + + if (CurrentLevel != oldLevel) + { + OnEXPLevelUp.ExecuteIfBound(CurrentLevel); + } } int UEXPComponent::GetCurrentEXP() @@ -46,6 +64,11 @@ void UEXPComponent::Reset() OnEXPLevelUp.ExecuteIfBound(CurrentLevel); } +float UEXPComponent::GetCurrentLevelPercent() +{ + return (CurrentEXP % 100) / 100.0f; +} + // Called when the game starts void UEXPComponent::BeginPlay() { diff --git a/Source/vampires/EXPComponent.h b/Source/vampires/EXPComponent.h index 4245f00..9e137da 100644 --- a/Source/vampires/EXPComponent.h +++ b/Source/vampires/EXPComponent.h @@ -42,6 +42,9 @@ public: UFUNCTION(BlueprintCallable) void Reset(); + UFUNCTION(BlueprintCallable, BlueprintPure) + float GetCurrentLevelPercent(); + protected: // Called when the game starts virtual void BeginPlay() override;