#include "GasaPlayerState.h" #include "Net/UnrealNetwork.h" #include "Networking/GasaNetLibrary_Inlines.h" #include "GasaGameInstance.h" #include "GasaPlayerController.h" #include "AbilitySystem/GasaAbilitySystemComponent.h" #include "AbilitySystem/GasaAttributeSet.h" AGasaPlayerState::AGasaPlayerState() { bAutoAbilitySystem = true; Level = 1; AbilitySystem = CreateDefaultSubobject("Ability System"); AbilitySystem->SetIsReplicated(true); AbilitySystem->SetReplicationMode(EGameplayEffectReplicationMode::Mixed); Attributes = CreateDefaultSubobject("Attributes"); // Replication NetUpdateFrequency = 100.f; } void AGasaPlayerState::Client_OnRep_Level(int32 OldPlayerLevel) { } #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(NewOwner); if (GasaPC) GasaPC->Client_CheckIfOwnerReady(); } #pragma endregion PlayerState #pragma region Actor void AGasaPlayerState::BeginPlay() { NetLog("Begin Play"); Super::BeginPlay(); UGasaGameInstance* GI = GetGameInstance(); 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(GetInstigatorController()); PC->Event_NetOwner_OnReady.AddDynamic(this, & ThisClass::OnNetOwnerReady); } } #pragma endregion Actor #pragma region UObject void AGasaPlayerState::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const { Super::GetLifetimeReplicatedProps(OutLifetimeProps); DOREPLIFETIME(AGasaPlayerState, Level); } #pragma endregion UObject