Files
realms-in-ruin-dev/Source/REALMSINRUIN/Private/Attributes/RIRAttributeSet.cpp
T
tedwardsandCursor ff5640a020 Establish UE 5.8 known-good baseline with Batch 1 archaeology docs.
Initialize Git with LFS for binary assets and add standard Unreal Engine .gitignore/.gitattributes.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-16 19:40:19 -07:00

74 lines
2.6 KiB
C++

// REALMS IN RUIN. Copyright (c) 2025 Trevor Edwards. All rights reserved.
#include "Attributes/RIRAttributeSet.h"
#include "Net/UnrealNetwork.h"
#include "GameplayEffectExtension.h"
URIRAttributeSet::URIRAttributeSet()
{
// Initialize values via Attribute Accessors macro
InitHealth(75.f);
InitMaxHealth(100.f);
InitMana(25.f);
InitMaxMana(50.f);
}
// Sets up replication rules for each attribute in the class
void URIRAttributeSet::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
// Each of the following macros registers an attribute for replication with:
// - COND_None: No condition for replication (always replicates)
// - REPNOTIFY_Always: Always call the corresponding OnRep_ function on the client when replicated
DOREPLIFETIME_CONDITION_NOTIFY(URIRAttributeSet, Health, COND_None, REPNOTIFY_Always);
DOREPLIFETIME_CONDITION_NOTIFY(URIRAttributeSet, MaxHealth, COND_None, REPNOTIFY_Always);
DOREPLIFETIME_CONDITION_NOTIFY(URIRAttributeSet, Mana, COND_None, REPNOTIFY_Always);
DOREPLIFETIME_CONDITION_NOTIFY(URIRAttributeSet, MaxMana, COND_None, REPNOTIFY_Always);
DOREPLIFETIME_CONDITION_NOTIFY(URIRAttributeSet, Stamina, COND_None, REPNOTIFY_Always);
DOREPLIFETIME_CONDITION_NOTIFY(URIRAttributeSet, MaxStamina, COND_None, REPNOTIFY_Always);
}
// --------- Replication Notification Functions ---------
// These functions are called automatically when the corresponding attribute is updated on clients
// due to replication. They ensure that GAS-related logic like delegates or UI updates are triggered.
// Health
void URIRAttributeSet::OnRep_Health(const FGameplayAttributeData& OldHealth) const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(URIRAttributeSet, Health, OldHealth);
}
// MaxHealth
void URIRAttributeSet::OnRep_MaxHealth(const FGameplayAttributeData& OldMaxHealth) const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(URIRAttributeSet, MaxHealth, OldMaxHealth);
}
// Mana
void URIRAttributeSet::OnRep_Mana(const FGameplayAttributeData& OldMana) const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(URIRAttributeSet, Mana, OldMana);
}
// MaxMana
void URIRAttributeSet::OnRep_MaxMana(const FGameplayAttributeData& OldMaxMana) const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(URIRAttributeSet, MaxMana, OldMaxMana);
}
// Stamina
void URIRAttributeSet::OnRep_Stamina(const FGameplayAttributeData& OldStamina) const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(URIRAttributeSet, Stamina, OldStamina);
}
// MaxStamina
void URIRAttributeSet::OnRep_MaxStamina(const FGameplayAttributeData& OldMaxStamina) const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(URIRAttributeSet, MaxStamina, OldMaxStamina);
}