86 lines
1.9 KiB
C++
86 lines
1.9 KiB
C++
// Amasson
|
|
|
|
|
|
#include "AbilitySystem/Components/PerkPointsComponent.h"
|
|
#include "Net/UnrealNetwork.h"
|
|
|
|
UPerkPointsComponent::UPerkPointsComponent()
|
|
{
|
|
PrimaryComponentTick.bCanEverTick = false;
|
|
SetIsReplicatedByDefault(true);
|
|
}
|
|
|
|
void UPerkPointsComponent::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
|
{
|
|
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
|
|
|
DOREPLIFETIME_CONDITION_NOTIFY(UPerkPointsComponent, AttributePoints, COND_OwnerOnly, REPNOTIFY_OnChanged)
|
|
DOREPLIFETIME_CONDITION_NOTIFY(UPerkPointsComponent, AbilityPoints, COND_OwnerOnly, REPNOTIFY_OnChanged)
|
|
}
|
|
|
|
|
|
/** Attribute Points */
|
|
|
|
void UPerkPointsComponent::AddToAttributePoints(int32 AddingPoints)
|
|
{
|
|
SetAttributePoints(AttributePoints + AddingPoints);
|
|
}
|
|
|
|
int32 UPerkPointsComponent::SpendAttributePoints(int32 Count)
|
|
{
|
|
int32 SpentCount = FMath::Min(Count, AttributePoints);
|
|
|
|
if (SpentCount)
|
|
{
|
|
AddToAttributePoints(-SpentCount);
|
|
}
|
|
return SpentCount;
|
|
}
|
|
|
|
void UPerkPointsComponent::SetAttributePoints(int32 NewPoints)
|
|
{
|
|
if (AttributePoints != NewPoints)
|
|
{
|
|
AttributePoints = NewPoints;
|
|
OnAttributePointsChangedDelegate.Broadcast(AttributePoints);
|
|
}
|
|
}
|
|
|
|
void UPerkPointsComponent::OnRep_AttributePoints(int32 OldAttributePoints) const
|
|
{
|
|
OnAttributePointsChangedDelegate.Broadcast(AttributePoints);
|
|
}
|
|
|
|
|
|
/** Skill Points */
|
|
|
|
void UPerkPointsComponent::AddToAbilityPoints(int32 AddingPoints)
|
|
{
|
|
SetAbilityPoints(AbilityPoints + AddingPoints);
|
|
}
|
|
|
|
int32 UPerkPointsComponent::SpendAbilityPoints(int32 Count)
|
|
{
|
|
int32 SpentCount = FMath::Min(Count, AbilityPoints);
|
|
|
|
if (SpentCount)
|
|
{
|
|
AddToAbilityPoints(-SpentCount);
|
|
}
|
|
return SpentCount;
|
|
}
|
|
|
|
void UPerkPointsComponent::SetAbilityPoints(int32 NewPoints)
|
|
{
|
|
if (AbilityPoints != NewPoints)
|
|
{
|
|
AbilityPoints = NewPoints;
|
|
OnAbilityPointsChangedDelegate.Broadcast(AbilityPoints);
|
|
}
|
|
}
|
|
|
|
void UPerkPointsComponent::OnRep_AbilityPoints(int32 OldAbilityPoints) const
|
|
{
|
|
OnAbilityPointsChangedDelegate.Broadcast(AbilityPoints);
|
|
}
|