Add Leveling to EXPComponent
This commit is contained in:
parent
079fba5d8b
commit
45b2120cb5
|
@ -15,17 +15,35 @@ UEXPComponent::UEXPComponent()
|
||||||
|
|
||||||
void UEXPComponent::IncrementEXP(int value)
|
void UEXPComponent::IncrementEXP(int value)
|
||||||
{
|
{
|
||||||
// TODO: I should be updating the level here
|
int oldEXP = CurrentEXP;
|
||||||
|
int oldLevel = CurrentLevel;
|
||||||
|
|
||||||
CurrentEXP += value;
|
CurrentEXP += value;
|
||||||
OnEXPGained.ExecuteIfBound(value);
|
OnEXPGained.ExecuteIfBound(value);
|
||||||
|
|
||||||
|
CurrentLevel = FMath::Floor(CurrentEXP / 100.0f);
|
||||||
|
|
||||||
|
if (CurrentLevel != oldLevel)
|
||||||
|
{
|
||||||
OnEXPLevelUp.ExecuteIfBound(CurrentLevel);
|
OnEXPLevelUp.ExecuteIfBound(CurrentLevel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UEXPComponent::SetCurrentEXP(int value)
|
void UEXPComponent::SetCurrentEXP(int value)
|
||||||
{
|
{
|
||||||
|
int oldEXP = CurrentEXP;
|
||||||
|
int oldLevel = CurrentLevel;
|
||||||
|
|
||||||
// TODO: I should be updating the level here
|
// TODO: I should be updating the level here
|
||||||
CurrentEXP = value;
|
CurrentEXP = value;
|
||||||
OnEXPGained.ExecuteIfBound(value);
|
OnEXPGained.ExecuteIfBound(value);
|
||||||
|
|
||||||
|
CurrentLevel = FMath::Floor(CurrentEXP / 100.0f);
|
||||||
|
|
||||||
|
if (CurrentLevel != oldLevel)
|
||||||
|
{
|
||||||
|
OnEXPLevelUp.ExecuteIfBound(CurrentLevel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int UEXPComponent::GetCurrentEXP()
|
int UEXPComponent::GetCurrentEXP()
|
||||||
|
@ -46,6 +64,11 @@ void UEXPComponent::Reset()
|
||||||
OnEXPLevelUp.ExecuteIfBound(CurrentLevel);
|
OnEXPLevelUp.ExecuteIfBound(CurrentLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float UEXPComponent::GetCurrentLevelPercent()
|
||||||
|
{
|
||||||
|
return (CurrentEXP % 100) / 100.0f;
|
||||||
|
}
|
||||||
|
|
||||||
// Called when the game starts
|
// Called when the game starts
|
||||||
void UEXPComponent::BeginPlay()
|
void UEXPComponent::BeginPlay()
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,6 +42,9 @@ public:
|
||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, BlueprintPure)
|
||||||
|
float GetCurrentLevelPercent();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Called when the game starts
|
// Called when the game starts
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
Loading…
Reference in New Issue