RealtimeStyleTransferRuntime/Source/LyraGame/Player/LyraPlayerState.h

172 lines
5.2 KiB
C
Raw Normal View History

2022-05-23 18:41:30 +00:00
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "AbilitySystemInterface.h"
2022-09-13 07:18:28 +00:00
#include "GenericTeamAgentInterface.h"
#include "HAL/Platform.h"
2022-05-23 18:41:30 +00:00
#include "Messages/LyraVerbMessage.h"
2022-09-13 07:18:28 +00:00
#include "ModularPlayerState.h"
#include "System/GameplayTagStack.h"
2022-05-23 18:41:30 +00:00
#include "Teams/LyraTeamAgentInterface.h"
2022-09-13 07:18:28 +00:00
#include "Templates/Casts.h"
#include "UObject/UObjectGlobals.h"
2022-05-23 18:41:30 +00:00
#include "LyraPlayerState.generated.h"
2022-09-13 07:18:28 +00:00
class AController;
2022-05-23 18:41:30 +00:00
class ALyraPlayerController;
2022-09-13 07:18:28 +00:00
class APlayerState;
class FName;
2022-05-23 18:41:30 +00:00
class UAbilitySystemComponent;
2022-09-13 07:18:28 +00:00
class ULyraAbilitySystemComponent;
2022-05-23 18:41:30 +00:00
class ULyraExperienceDefinition;
2022-09-13 07:18:28 +00:00
class ULyraPawnData;
class UObject;
struct FFrame;
struct FGameplayTag;
2022-05-23 18:41:30 +00:00
/** Defines the types of client connected */
UENUM()
enum class ELyraPlayerConnectionType : uint8
{
// An active player
Player = 0,
// Spectator connected to a running game
LiveSpectator,
// Spectating a demo recording offline
ReplaySpectator,
// A deactivated player (disconnected)
InactivePlayer
};
/**
* ALyraPlayerState
*
* Base player state class used by this project.
*/
UCLASS(Config = Game)
class LYRAGAME_API ALyraPlayerState : public AModularPlayerState, public IAbilitySystemInterface, public ILyraTeamAgentInterface
{
GENERATED_BODY()
public:
ALyraPlayerState(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
UFUNCTION(BlueprintCallable, Category = "Lyra|PlayerState")
ALyraPlayerController* GetLyraPlayerController() const;
UFUNCTION(BlueprintCallable, Category = "Lyra|PlayerState")
ULyraAbilitySystemComponent* GetLyraAbilitySystemComponent() const { return AbilitySystemComponent; }
virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override;
template <class T>
const T* GetPawnData() const { return Cast<T>(PawnData); }
void SetPawnData(const ULyraPawnData* InPawnData);
//~AActor interface
virtual void PreInitializeComponents() override;
virtual void PostInitializeComponents() override;
//~End of AActor interface
//~APlayerState interface
virtual void Reset() override;
virtual void ClientInitialize(AController* C) override;
virtual void CopyProperties(APlayerState* PlayerState) override;
virtual void OnDeactivated() override;
virtual void OnReactivated() override;
//~End of APlayerState interface
//~ILyraTeamAgentInterface interface
virtual void SetGenericTeamId(const FGenericTeamId& NewTeamID) override;
virtual FGenericTeamId GetGenericTeamId() const override;
virtual FOnLyraTeamIndexChangedDelegate* GetOnTeamIndexChangedDelegate() override;
//~End of ILyraTeamAgentInterface interface
static const FName NAME_LyraAbilityReady;
void SetPlayerConnectionType(ELyraPlayerConnectionType NewType);
ELyraPlayerConnectionType GetPlayerConnectionType() const { return MyPlayerConnectionType; }
/** Returns the Squad ID of the squad the player belongs to. */
UFUNCTION(BlueprintCallable)
int32 GetSquadId() const
{
return MySquadID;
}
/** Returns the Team ID of the team the player belongs to. */
UFUNCTION(BlueprintCallable)
int32 GetTeamId() const
{
return GenericTeamIdToInteger(MyTeamID);
}
void SetSquadID(int32 NewSquadID);
// Adds a specified number of stacks to the tag (does nothing if StackCount is below 1)
UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly, Category=Teams)
void AddStatTagStack(FGameplayTag Tag, int32 StackCount);
// Removes a specified number of stacks from the tag (does nothing if StackCount is below 1)
UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly, Category=Teams)
void RemoveStatTagStack(FGameplayTag Tag, int32 StackCount);
// Returns the stack count of the specified tag (or 0 if the tag is not present)
UFUNCTION(BlueprintCallable, Category=Teams)
int32 GetStatTagStackCount(FGameplayTag Tag) const;
// Returns true if there is at least one stack of the specified tag
UFUNCTION(BlueprintCallable, Category=Teams)
bool HasStatTag(FGameplayTag Tag) const;
// Send a message to just this player
// (use only for client notifications like accolades, quest toasts, etc... that can handle being occasionally lost)
UFUNCTION(Client, Unreliable, BlueprintCallable, Category = "Lyra|PlayerState")
void ClientBroadcastMessage(const FLyraVerbMessage Message);
private:
void OnExperienceLoaded(const ULyraExperienceDefinition* CurrentExperience);
protected:
UFUNCTION()
void OnRep_PawnData();
protected:
UPROPERTY(ReplicatedUsing = OnRep_PawnData)
2022-09-13 07:18:28 +00:00
TObjectPtr<const ULyraPawnData> PawnData;
2022-05-23 18:41:30 +00:00
private:
// The ability system component sub-object used by player characters.
UPROPERTY(VisibleAnywhere, Category = "Lyra|PlayerState")
2022-09-13 07:18:28 +00:00
TObjectPtr<ULyraAbilitySystemComponent> AbilitySystemComponent;
2022-05-23 18:41:30 +00:00
UPROPERTY(Replicated)
ELyraPlayerConnectionType MyPlayerConnectionType;
UPROPERTY()
FOnLyraTeamIndexChangedDelegate OnTeamChangedDelegate;
UPROPERTY(ReplicatedUsing=OnRep_MyTeamID)
FGenericTeamId MyTeamID;
UPROPERTY(ReplicatedUsing=OnRep_MySquadID)
int32 MySquadID;
UPROPERTY(Replicated)
FGameplayTagStackContainer StatTags;
private:
UFUNCTION()
void OnRep_MyTeamID(FGenericTeamId OldTeamID);
UFUNCTION()
void OnRep_MySquadID();
};