2024-04-13 07:19:45 -07:00
|
|
|
|
#include "GasaPlayerState.h"
|
|
|
|
|
|
2024-10-22 14:32:37 -07:00
|
|
|
|
#include "Net/UnrealNetwork.h"
|
|
|
|
|
|
2024-04-23 15:54:17 -07:00
|
|
|
|
#include "Networking/GasaNetLibrary_Inlines.h"
|
|
|
|
|
#include "GasaGameInstance.h"
|
|
|
|
|
#include "GasaPlayerController.h"
|
2024-04-13 08:09:22 -07:00
|
|
|
|
#include "AbilitySystem/GasaAbilitySystemComponent.h"
|
2024-04-13 15:35:19 -07:00
|
|
|
|
#include "AbilitySystem/GasaAttributeSet.h"
|
2024-04-13 08:09:22 -07:00
|
|
|
|
|
2024-04-13 07:19:45 -07:00
|
|
|
|
AGasaPlayerState::AGasaPlayerState()
|
|
|
|
|
{
|
2024-04-22 22:10:02 -07:00
|
|
|
|
bAutoAbilitySystem = true;
|
|
|
|
|
|
2024-10-22 14:32:37 -07:00
|
|
|
|
Level = 1;
|
|
|
|
|
|
2024-04-13 08:09:22 -07:00
|
|
|
|
AbilitySystem = CreateDefaultSubobject<UGasaAbilitySystemComp>("Ability System");
|
|
|
|
|
AbilitySystem->SetIsReplicated(true);
|
2024-04-13 08:56:19 -07:00
|
|
|
|
AbilitySystem->SetReplicationMode(EGameplayEffectReplicationMode::Mixed);
|
2024-04-13 08:09:22 -07:00
|
|
|
|
|
2024-04-13 15:35:19 -07:00
|
|
|
|
Attributes = CreateDefaultSubobject<UGasaAttributeSet>("Attributes");
|
2024-04-13 08:09:22 -07:00
|
|
|
|
|
2024-04-13 07:19:45 -07:00
|
|
|
|
// Replication
|
|
|
|
|
NetUpdateFrequency = 100.f;
|
|
|
|
|
}
|
2024-04-23 15:54:17 -07:00
|
|
|
|
|
2024-10-22 14:32:37 -07:00
|
|
|
|
void AGasaPlayerState::Client_OnRep_Level(int32 OldPlayerLevel)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-23 15:54:17 -07:00
|
|
|
|
#pragma region GameFramework
|
|
|
|
|
void AGasaPlayerState::OnGameFrameworkInitialized()
|
|
|
|
|
{
|
|
|
|
|
NetLog("Received game framework initialization.");
|
|
|
|
|
BP_OnGameFrameworkInitialized();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AGasaPlayerState::OnNetOwnerReady(AGasaPlayerController* PC)
|
|
|
|
|
{
|
|
|
|
|
BP_OnNetOwnerReady();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AGasaPlayerState::Reset()
|
|
|
|
|
{
|
|
|
|
|
Super::Reset();
|
|
|
|
|
NetLog("Reset");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma endregion GameFramework
|
|
|
|
|
|
|
|
|
|
#pragma region PlayerState
|
|
|
|
|
void AGasaPlayerState::ClientInitialize(AController* NewOwner)
|
|
|
|
|
{
|
|
|
|
|
Super::ClientInitialize(NewOwner);
|
|
|
|
|
NetLog("Client Initialization: This is the OnRep for player state.");
|
|
|
|
|
|
|
|
|
|
AGasaPlayerController* GasaPC = Cast<AGasaPlayerController>(NewOwner);
|
|
|
|
|
if (GasaPC)
|
|
|
|
|
GasaPC->Client_CheckIfOwnerReady();
|
|
|
|
|
}
|
|
|
|
|
#pragma endregion PlayerState
|
|
|
|
|
|
|
|
|
|
#pragma region Actor
|
|
|
|
|
void AGasaPlayerState::BeginPlay()
|
|
|
|
|
{
|
|
|
|
|
NetLog("Begin Play");
|
|
|
|
|
Super::BeginPlay();
|
|
|
|
|
|
|
|
|
|
UGasaGameInstance* GI = GetGameInstance<UGasaGameInstance>();
|
|
|
|
|
GI->Event_OnGameFrameworkInitialized.AddDynamic(this, & ThisClass::OnGameFrameworkInitialized);
|
|
|
|
|
GI->NotifyGameFrameworkClassReady(EGameFrameworkClassFlag::PlayerState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AGasaPlayerState::PostInitializeComponents()
|
|
|
|
|
{
|
|
|
|
|
Super::PostInitializeComponents();
|
|
|
|
|
NetLog("Post Initialization");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AGasaPlayerState::RegisterPlayerWithSession(bool bWasFromInvite)
|
|
|
|
|
{
|
|
|
|
|
Super::RegisterPlayerWithSession(bWasFromInvite);
|
|
|
|
|
NetLog("RegisterPlayerWithSession");
|
|
|
|
|
|
|
|
|
|
if (IsServer() && GetInstigatorController())
|
|
|
|
|
{
|
|
|
|
|
AGasaPlayerController* PC = Cast<AGasaPlayerController>(GetInstigatorController());
|
|
|
|
|
PC->Event_NetOwner_OnReady.AddDynamic(this, & ThisClass::OnNetOwnerReady);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#pragma endregion Actor
|
|
|
|
|
|
|
|
|
|
#pragma region UObject
|
|
|
|
|
void AGasaPlayerState::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
|
|
|
|
{
|
|
|
|
|
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
|
|
|
|
|
2024-10-22 14:32:37 -07:00
|
|
|
|
DOREPLIFETIME(AGasaPlayerState, Level);
|
2024-04-23 15:54:17 -07:00
|
|
|
|
}
|
|
|
|
|
#pragma endregion UObject
|