122 lines
3.8 KiB
C++
122 lines
3.8 KiB
C++
// © 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"
|
|
#include "Components/GameFrameworkComponentManager.h"
|
|
#include "GameFramework/PlayerState.h"
|
|
|
|
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())
|
|
{
|
|
//@Todo replace this log by our custom log.
|
|
UE_LOG(LogTemp, Verbose, TEXT("PostInitProperties for %s - Setting up ASC Replication Mode to: %d"), *GetName(), ReplicationMode);
|
|
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;
|
|
}
|