OLS/Source/ols/Private/ModularGameplayActors/OLSModularCharacter.cpp

99 lines
2.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/OLSModularCharacter.h"
#include "AbilitySystem/OLSAbilitySystemComponent.h"
#include "Components/GameFrameworkComponentManager.h"
AOLSModularCharacter::AOLSModularCharacter(const FObjectInitializer& objectInitializer)
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
// Set this actor to replicate like a Pawn would
bReplicates = true;
// Set Ability System Companion with GAS Companion subclass
AbilitySystemComponent = CreateDefaultSubobject<UOLSAbilitySystemComponent>(TEXT("AbilitySystemComponent"));
AbilitySystemComponent->SetIsReplicated(true);
ReplicationMode = EGameplayEffectReplicationMode::Mixed;
}
void AOLSModularCharacter::PreInitializeComponents()
{
Super::PreInitializeComponents();
UGameFrameworkComponentManager::AddGameFrameworkComponentReceiver(this);
}
void AOLSModularCharacter::BeginPlay()
{
UGameFrameworkComponentManager::SendGameFrameworkComponentExtensionEvent(
this, UGameFrameworkComponentManager::NAME_GameActorReady);
Super::BeginPlay();
}
void AOLSModularCharacter::EndPlay(const EEndPlayReason::Type endPlayReason)
{
UGameFrameworkComponentManager::RemoveGameFrameworkComponentReceiver(this);
Super::EndPlay(endPlayReason);
}
void AOLSModularCharacter::PostInitProperties()
{
Super::PostInitProperties();
if (AbilitySystemComponent)
{
//@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);
}
}
UAbilitySystemComponent* AOLSModularCharacter::GetAbilitySystemComponent() const
{
return AbilitySystemComponent;
}
void AOLSModularCharacter::GetOwnedGameplayTags(FGameplayTagContainer& outTagContainer) const
{
if (AbilitySystemComponent)
{
FGameplayTagContainer ownedTags;
AbilitySystemComponent->GetOwnedGameplayTags(ownedTags);
outTagContainer = MoveTemp(ownedTags);
}
}
bool AOLSModularCharacter::HasMatchingGameplayTag(FGameplayTag tagToCheck) const
{
if (AbilitySystemComponent)
{
return AbilitySystemComponent->HasMatchingGameplayTag(tagToCheck);
}
return false;
}
bool AOLSModularCharacter::HasAllMatchingGameplayTags(const FGameplayTagContainer& tagContainer) const
{
if (AbilitySystemComponent)
{
return AbilitySystemComponent->HasAllMatchingGameplayTags(tagContainer);
}
return false;
}
bool AOLSModularCharacter::HasAnyMatchingGameplayTags(const FGameplayTagContainer& tagContainer) const
{
if (AbilitySystemComponent)
{
return AbilitySystemComponent->HasAnyMatchingGameplayTags(tagContainer);
}
return false;
}