vampires/Source/vampires/EXPComponent.cpp

79 lines
1.6 KiB
C++
Raw Normal View History

2024-06-12 20:06:51 +02:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "EXPComponent.h"
// Sets default values for this component's properties
UEXPComponent::UEXPComponent()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = false;
// ...
}
void UEXPComponent::IncrementEXP(int value)
{
2024-08-21 00:32:24 +02:00
int oldEXP = CurrentEXP;
int oldLevel = CurrentLevel;
2024-06-12 20:06:51 +02:00
CurrentEXP += value;
2024-11-16 03:18:36 +01:00
OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
2024-08-21 00:32:24 +02:00
CurrentLevel = FMath::Floor(CurrentEXP / 100.0f);
if (CurrentLevel != oldLevel)
{
2024-11-16 03:18:36 +01:00
OnEXPLevelUp.Broadcast(CurrentLevel);
2024-08-21 00:32:24 +02:00
}
2024-06-12 20:06:51 +02:00
}
void UEXPComponent::SetCurrentEXP(int value)
{
2024-08-21 00:32:24 +02:00
int oldEXP = CurrentEXP;
int oldLevel = CurrentLevel;
2024-06-12 20:06:51 +02:00
// TODO: I should be updating the level here
CurrentEXP = value;
2024-11-16 03:18:36 +01:00
OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
2024-08-21 00:32:24 +02:00
CurrentLevel = FMath::Floor(CurrentEXP / 100.0f);
if (CurrentLevel != oldLevel)
{
2024-11-16 03:18:36 +01:00
OnEXPLevelUp.Broadcast(CurrentLevel);
2024-08-21 00:32:24 +02:00
}
2024-06-12 20:06:51 +02:00
}
int UEXPComponent::GetCurrentEXP()
{
return CurrentEXP;
}
int UEXPComponent::GetCurrentLevel()
{
return CurrentLevel;
}
void UEXPComponent::Reset()
{
CurrentEXP = 0;
CurrentLevel = 0;
2024-11-16 03:18:36 +01:00
OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
OnEXPLevelUp.Broadcast(CurrentLevel);
2024-06-12 20:06:51 +02:00
}
2024-08-21 00:32:24 +02:00
float UEXPComponent::GetCurrentLevelPercent()
{
return (CurrentEXP % 100) / 100.0f;
}
2024-06-12 20:06:51 +02:00
// Called when the game starts
void UEXPComponent::BeginPlay()
{
Super::BeginPlay();
Reset();
}