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 "ModularGameplayActors/OLSModularPlayerStateCharacter.h"
|
|
|
|
|
|
|
|
|
|
#include "AbilitySystemComponent.h"
|
|
|
|
|
#include "AbilitySystemGlobals.h"
|
2025-01-16 21:24:05 +00:00
|
|
|
|
#include "OLSLog.h"
|
2025-01-04 16:41:49 +00:00
|
|
|
|
#include "Components/GameFrameworkComponentManager.h"
|
|
|
|
|
#include "GameFramework/PlayerState.h"
|
|
|
|
|
|
2025-01-16 21:24:05 +00:00
|
|
|
|
DEFINE_LOG_CATEGORY(LogOLSModularPlayerStateCharacter);
|
|
|
|
|
|
2025-01-04 16:41:49 +00:00
|
|
|
|
AOLSModularPlayerStateCharacter::AOLSModularPlayerStateCharacter(const FObjectInitializer& objectInitializer) : Super(objectInitializer)
|
|
|
|
|
{
|
|
|
|
|
SetMinNetUpdateFrequency(33.f);
|
|
|
|
|
SetNetUpdateFrequency(66.f);
|
|
|
|
|
|
|
|
|
|
ReplicationMode = EGameplayEffectReplicationMode::Mixed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AOLSModularPlayerStateCharacter::PreInitializeComponents()
|
|
|
|
|
{
|
|
|
|
|
Super::PreInitializeComponents();
|
|
|
|
|
UGameFrameworkComponentManager::AddGameFrameworkComponentReceiver(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AOLSModularPlayerStateCharacter::BeginPlay()
|
|
|
|
|
{
|
|
|
|
|
UGameFrameworkComponentManager::SendGameFrameworkComponentExtensionEvent(this, UGameFrameworkComponentManager::NAME_GameActorReady);
|
|
|
|
|
Super::BeginPlay();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AOLSModularPlayerStateCharacter::EndPlay(const EEndPlayReason::Type endPlayReason)
|
|
|
|
|
{
|
|
|
|
|
UGameFrameworkComponentManager::RemoveGameFrameworkComponentReceiver(this);
|
|
|
|
|
Super::EndPlay(endPlayReason);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AOLSModularPlayerStateCharacter::PostInitProperties()
|
|
|
|
|
{
|
|
|
|
|
Super::PostInitProperties();
|
|
|
|
|
|
|
|
|
|
if (AbilitySystemComponent.IsValid())
|
|
|
|
|
{
|
2025-01-16 21:24:05 +00:00
|
|
|
|
OLS_LOG(LogOLSModularPlayerStateCharacter, Verbose,
|
|
|
|
|
TEXT("PostInitProperties for %s - Setting up ASC Replication Mode to: %d"), GET_UOBJECT_NAME(this),
|
|
|
|
|
ReplicationMode);
|
2025-01-04 16:41:49 +00:00
|
|
|
|
AbilitySystemComponent->SetReplicationMode(ReplicationMode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AOLSModularPlayerStateCharacter::PossessedBy(AController* newController)
|
|
|
|
|
{
|
|
|
|
|
Super::PossessedBy(newController);
|
|
|
|
|
|
|
|
|
|
// For Player State ASC Pawns, initialize ASC on server in PossessedBy
|
|
|
|
|
if (TObjectPtr<APlayerState> playerState = GetPlayerState())
|
|
|
|
|
{
|
|
|
|
|
AbilitySystemComponent = UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(playerState);
|
|
|
|
|
if (AbilitySystemComponent.IsValid())
|
|
|
|
|
{
|
|
|
|
|
AbilitySystemComponent->InitAbilityActorInfo(playerState, this);
|
|
|
|
|
// TODO: Might consider sending GFC extension event in InitAbilityActorInfo instead
|
|
|
|
|
UGameFrameworkComponentManager::SendGameFrameworkComponentExtensionEvent(this, UGameFrameworkComponentManager::NAME_GameActorReady);
|
|
|
|
|
|
|
|
|
|
// Required for ability input binding to update itself when ability are granted again in case of a respawn
|
|
|
|
|
UGameFrameworkComponentManager::SendGameFrameworkComponentExtensionEvent(playerState, UGameFrameworkComponentManager::NAME_GameActorReady);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AOLSModularPlayerStateCharacter::OnRep_PlayerState()
|
|
|
|
|
{
|
|
|
|
|
Super::OnRep_PlayerState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UAbilitySystemComponent* AOLSModularPlayerStateCharacter::GetAbilitySystemComponent() const
|
|
|
|
|
{
|
|
|
|
|
if (AbilitySystemComponent.IsValid())
|
|
|
|
|
{
|
|
|
|
|
return AbilitySystemComponent.Get();
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AOLSModularPlayerStateCharacter::GetOwnedGameplayTags(FGameplayTagContainer& outTagContainer) const
|
|
|
|
|
{
|
|
|
|
|
if (AbilitySystemComponent.IsValid())
|
|
|
|
|
{
|
|
|
|
|
FGameplayTagContainer ownedTags;
|
|
|
|
|
AbilitySystemComponent->GetOwnedGameplayTags(ownedTags);
|
|
|
|
|
outTagContainer = MoveTemp(ownedTags);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AOLSModularPlayerStateCharacter::HasMatchingGameplayTag(FGameplayTag tagToCheck) const
|
|
|
|
|
{
|
|
|
|
|
if (AbilitySystemComponent.IsValid())
|
|
|
|
|
{
|
|
|
|
|
return AbilitySystemComponent->HasMatchingGameplayTag(tagToCheck);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AOLSModularPlayerStateCharacter::HasAllMatchingGameplayTags(const FGameplayTagContainer& tagContainer) const
|
|
|
|
|
{
|
|
|
|
|
if (AbilitySystemComponent.IsValid())
|
|
|
|
|
{
|
|
|
|
|
return AbilitySystemComponent->HasAllMatchingGameplayTags(tagContainer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AOLSModularPlayerStateCharacter::HasAnyMatchingGameplayTags(const FGameplayTagContainer& tagContainer) const
|
|
|
|
|
{
|
|
|
|
|
if (AbilitySystemComponent.IsValid())
|
|
|
|
|
{
|
|
|
|
|
return AbilitySystemComponent->HasAnyMatchingGameplayTags(tagContainer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|