2025-01-04 16:41:49 +00:00
// © 2024 Long Ly. All rights reserved. Any unauthorized use, reproduction, or distribution of this trademark is strictly prohibited and may result in legal action.
# include "Player/OLSPlayerState.h"
# include "AbilitySystem/OLSAbilitySystemComponent.h"
2025-01-08 05:30:09 +00:00
# include "Components/GameFrameworkComponentManager.h"
# include "DataAssets/OLSAbilitySetPrimaryDataAsset.h"
2025-01-13 22:36:08 +00:00
# include "GameModes/OLSExperienceManagerComponent.h"
# include "GameModes/OLSGameMode.h"
2025-01-08 05:30:09 +00:00
# include "Net/UnrealNetwork.h"
2025-01-04 16:41:49 +00:00
# include "Player/OLSPlayerController.h"
2025-01-08 05:30:09 +00:00
# include UE_INLINE_GENERATED_CPP_BY_NAME(OLSPlayerState)
const FName AOLSPlayerState : : NAME_OLSAbilityReady ( " OLSAbilitiesReady " ) ;
2025-01-04 16:41:49 +00:00
AOLSPlayerState : : AOLSPlayerState ( const FObjectInitializer & objectInitializer ) : Super ( objectInitializer )
{
// Create attribute sets here.
}
2025-01-09 23:05:57 +00:00
void AOLSPlayerState : : SetPawnData ( const UOLSPawnDataAsset * pawnData )
2025-01-08 05:30:09 +00:00
{
check ( pawnData ) ;
if ( ! HasAuthority ( ) )
{
return ;
}
if ( PawnData )
{
// @Todo: replace this by our custom log.
// UE_LOG(LogLyra, Error, TEXT("Trying to set PawnData [%s] on player state [%s] that already has valid PawnData [%s]."), *GetNameSafe(InPawnData), *GetNameSafe(this), *GetNameSafe(PawnData));
return ;
}
MARK_PROPERTY_DIRTY_FROM_NAME ( ThisClass , PawnData , this ) ;
for ( const UOLSAbilitySetPrimaryDataAsset * abilityDataAsset : PawnData - > AbilitySets )
{
if ( abilityDataAsset )
{
abilityDataAsset - > GiveToAbilitySystem ( AbilitySystemComponent , nullptr ) ;
}
}
UGameFrameworkComponentManager : : SendGameFrameworkComponentExtensionEvent ( this , NAME_OLSAbilityReady ) ;
ForceNetUpdate ( ) ;
}
2025-01-13 22:36:08 +00:00
void AOLSPlayerState : : AddStatTagStack ( FGameplayTag tag , int32 stackCount )
{
StatTags . AddStack ( tag , stackCount ) ;
}
void AOLSPlayerState : : RemoveStatTagStack ( FGameplayTag tag , int32 stackCount )
{
StatTags . RemoveStack ( tag , stackCount ) ;
}
int32 AOLSPlayerState : : GetStatTagStackCount ( FGameplayTag tag ) const
{
return StatTags . GetStackCount ( tag ) ;
}
bool AOLSPlayerState : : HasStatTag ( FGameplayTag tag ) const
{
return StatTags . ContainsTag ( tag ) ;
}
void AOLSPlayerState : : OnExperienceLoaded ( const UOLSExperienceDefinitionDataAsset * currentExperience )
{
if ( AOLSGameMode * gameMode = GetWorld ( ) - > GetAuthGameMode < AOLSGameMode > ( ) )
{
if ( const UOLSPawnDataAsset * newPawnData = gameMode - > GetPawnDataForController ( GetOwningController ( ) ) )
{
SetPawnData ( newPawnData ) ;
}
else
{
// @T ODO: Replace this with our custom.
// UE_LOG(LogLyra, Error, TEXT("ALyraPlayerState::OnExperienceLoaded(): Unable to find PawnData to initialize player state [%s]!"), *GetNameSafe(this));
}
}
}
2025-01-08 05:30:09 +00:00
void AOLSPlayerState : : OnRep_PawnData ( )
{
}
2025-01-04 16:41:49 +00:00
void AOLSPlayerState : : PostInitializeComponents ( )
{
Super : : PostInitializeComponents ( ) ;
check ( AbilitySystemComponent ) ;
AbilitySystemComponent - > InitAbilityActorInfo ( this , GetPawn ( ) ) ;
const TObjectPtr < UWorld > world = GetWorld ( ) ;
if ( world & & world - > IsGameWorld ( ) & & world - > GetNetMode ( ) ! = NM_Client )
{
const TObjectPtr < AGameStateBase > gameState = GetWorld ( ) - > GetGameState ( ) ;
check ( gameState ) ;
2025-01-13 22:36:08 +00:00
UOLSExperienceManagerComponent * ExperienceComponent = gameState - > FindComponentByClass < UOLSExperienceManagerComponent > ( ) ;
check ( ExperienceComponent ) ;
ExperienceComponent - > CallOrRegister_OnExperienceLoaded ( FOLSExperienceLoadedNativeDelegate : : FDelegate : : CreateUObject ( this , & ThisClass : : OnExperienceLoaded ) ) ;
2025-01-04 16:41:49 +00:00
}
}
2025-01-08 05:30:09 +00:00
void AOLSPlayerState : : GetLifetimeReplicatedProps ( TArray < FLifetimeProperty > & OutLifetimeProps ) const
{
Super : : GetLifetimeReplicatedProps ( OutLifetimeProps ) ;
FDoRepLifetimeParams SharedParams ;
SharedParams . bIsPushBased = true ;
DOREPLIFETIME_WITH_PARAMS_FAST ( ThisClass , PawnData , SharedParams ) ;
}
2025-01-04 16:41:49 +00:00
AOLSPlayerController * AOLSPlayerState : : GetOLSPlayerController ( ) const
{
return Cast < AOLSPlayerController > ( GetOwner ( ) ) ;
}
UOLSAbilitySystemComponent * AOLSPlayerState : : GetOLSAbilitySystemComponent ( ) const
{
return AbilitySystemComponent ;
2025-01-08 05:30:09 +00:00
}