File size: 8,149 Bytes
1e67697 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | // Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "AbilitySystemInterface.h"
#include "GameplayCueInterface.h"
#include "GameplayTagAssetInterface.h"
#include "ModularCharacter.h"
#include "Teams/LyraTeamAgentInterface.h"
#include "LyraCharacter.generated.h"
#define UE_API LYRAGAME_API
class AActor;
class AController;
class ALyraPlayerController;
class ALyraPlayerState;
class FLifetimeProperty;
class IRepChangedPropertyTracker;
class UAbilitySystemComponent;
class UInputComponent;
class ULyraAbilitySystemComponent;
class ULyraCameraComponent;
class ULyraHealthComponent;
class ULyraPawnExtensionComponent;
class UObject;
struct FFrame;
struct FGameplayTag;
struct FGameplayTagContainer;
/**
* FLyraReplicatedAcceleration: Compressed representation of acceleration
*/
USTRUCT()
struct FLyraReplicatedAcceleration
{
GENERATED_BODY()
UPROPERTY()
uint8 AccelXYRadians = 0; // Direction of XY accel component, quantized to represent [0, 2*pi]
UPROPERTY()
uint8 AccelXYMagnitude = 0; //Accel rate of XY component, quantized to represent [0, MaxAcceleration]
UPROPERTY()
int8 AccelZ = 0; // Raw Z accel rate component, quantized to represent [-MaxAcceleration, MaxAcceleration]
};
/** The type we use to send FastShared movement updates. */
USTRUCT()
struct FSharedRepMovement
{
GENERATED_BODY()
FSharedRepMovement();
bool FillForCharacter(ACharacter* Character);
bool Equals(const FSharedRepMovement& Other, ACharacter* Character) const;
bool NetSerialize(FArchive& Ar, class UPackageMap* Map, bool& bOutSuccess);
UPROPERTY(Transient)
FRepMovement RepMovement;
UPROPERTY(Transient)
float RepTimeStamp = 0.0f;
UPROPERTY(Transient)
uint8 RepMovementMode = 0;
UPROPERTY(Transient)
bool bProxyIsJumpForceApplied = false;
UPROPERTY(Transient)
bool bIsCrouched = false;
};
template<>
struct TStructOpsTypeTraits<FSharedRepMovement> : public TStructOpsTypeTraitsBase2<FSharedRepMovement>
{
enum
{
WithNetSerializer = true,
WithNetSharedSerialization = true,
};
};
/**
* ALyraCharacter
*
* The base character pawn class used by this project.
* Responsible for sending events to pawn components.
* New behavior should be added via pawn components when possible.
*/
UCLASS(MinimalAPI, Config = Game, Meta = (ShortTooltip = "The base character pawn class used by this project."))
class ALyraCharacter : public AModularCharacter, public IAbilitySystemInterface, public IGameplayCueInterface, public IGameplayTagAssetInterface, public ILyraTeamAgentInterface
{
GENERATED_BODY()
public:
UE_API ALyraCharacter(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
UFUNCTION(BlueprintCallable, Category = "Lyra|Character")
UE_API ALyraPlayerController* GetLyraPlayerController() const;
UFUNCTION(BlueprintCallable, Category = "Lyra|Character")
UE_API ALyraPlayerState* GetLyraPlayerState() const;
UFUNCTION(BlueprintCallable, Category = "Lyra|Character")
UE_API ULyraAbilitySystemComponent* GetLyraAbilitySystemComponent() const;
UE_API virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override;
UE_API virtual void GetOwnedGameplayTags(FGameplayTagContainer& TagContainer) const override;
UE_API virtual bool HasMatchingGameplayTag(FGameplayTag TagToCheck) const override;
UE_API virtual bool HasAllMatchingGameplayTags(const FGameplayTagContainer& TagContainer) const override;
UE_API virtual bool HasAnyMatchingGameplayTags(const FGameplayTagContainer& TagContainer) const override;
UE_API void ToggleCrouch();
//~AActor interface
UE_API virtual void PreInitializeComponents() override;
UE_API virtual void BeginPlay() override;
UE_API virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
UE_API virtual void Reset() override;
UE_API virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
UE_API virtual void PreReplication(IRepChangedPropertyTracker& ChangedPropertyTracker) override;
//~End of AActor interface
//~APawn interface
UE_API virtual void NotifyControllerChanged() override;
//~End of APawn interface
//~ILyraTeamAgentInterface interface
UE_API virtual void SetGenericTeamId(const FGenericTeamId& NewTeamID) override;
UE_API virtual FGenericTeamId GetGenericTeamId() const override;
UE_API virtual FOnLyraTeamIndexChangedDelegate* GetOnTeamIndexChangedDelegate() override;
//~End of ILyraTeamAgentInterface interface
/** RPCs that is called on frames when default property replication is skipped. This replicates a single movement update to everyone. */
UFUNCTION(NetMulticast, unreliable)
UE_API void FastSharedReplication(const FSharedRepMovement& SharedRepMovement);
// Last FSharedRepMovement we sent, to avoid sending repeatedly.
FSharedRepMovement LastSharedReplication;
UE_API virtual bool UpdateSharedReplication();
protected:
UE_API virtual void OnAbilitySystemInitialized();
UE_API virtual void OnAbilitySystemUninitialized();
UE_API virtual void PossessedBy(AController* NewController) override;
UE_API virtual void UnPossessed() override;
UE_API virtual void OnRep_Controller() override;
UE_API virtual void OnRep_PlayerState() override;
UE_API virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;
UE_API void InitializeGameplayTags();
UE_API virtual void FellOutOfWorld(const class UDamageType& dmgType) override;
// Begins the death sequence for the character (disables collision, disables movement, etc...)
UFUNCTION()
UE_API virtual void OnDeathStarted(AActor* OwningActor);
// Ends the death sequence for the character (detaches controller, destroys pawn, etc...)
UFUNCTION()
UE_API virtual void OnDeathFinished(AActor* OwningActor);
UE_API void DisableMovementAndCollision();
UE_API void DestroyDueToDeath();
UE_API void UninitAndDestroy();
// Called when the death sequence for the character has completed
UFUNCTION(BlueprintImplementableEvent, meta=(DisplayName="OnDeathFinished"))
UE_API void K2_OnDeathFinished();
UE_API virtual void OnMovementModeChanged(EMovementMode PrevMovementMode, uint8 PreviousCustomMode) override;
UE_API void SetMovementModeTag(EMovementMode MovementMode, uint8 CustomMovementMode, bool bTagEnabled);
UE_API virtual void OnStartCrouch(float HalfHeightAdjust, float ScaledHalfHeightAdjust) override;
UE_API virtual void OnEndCrouch(float HalfHeightAdjust, float ScaledHalfHeightAdjust) override;
UE_API virtual bool CanJumpInternal_Implementation() const;
private:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Lyra|Character", Meta = (AllowPrivateAccess = "true"))
TObjectPtr<ULyraPawnExtensionComponent> PawnExtComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Lyra|Character", Meta = (AllowPrivateAccess = "true"))
TObjectPtr<ULyraHealthComponent> HealthComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Lyra|Character", Meta = (AllowPrivateAccess = "true"))
TObjectPtr<ULyraCameraComponent> CameraComponent;
UPROPERTY(Transient, ReplicatedUsing = OnRep_ReplicatedAcceleration)
FLyraReplicatedAcceleration ReplicatedAcceleration;
UPROPERTY(ReplicatedUsing = OnRep_MyTeamID)
FGenericTeamId MyTeamID;
UPROPERTY()
FOnLyraTeamIndexChangedDelegate OnTeamChangedDelegate;
protected:
// Called to determine what happens to the team ID when possession ends
virtual FGenericTeamId DetermineNewTeamAfterPossessionEnds(FGenericTeamId OldTeamID) const
{
// This could be changed to return, e.g., OldTeamID if you want to keep it assigned afterwards, or return an ID for some neutral faction, or etc...
return FGenericTeamId::NoTeam;
}
private:
UFUNCTION()
UE_API void OnControllerChangedTeam(UObject* TeamAgent, int32 OldTeam, int32 NewTeam);
UFUNCTION()
UE_API void OnRep_ReplicatedAcceleration();
UFUNCTION()
UE_API void OnRep_MyTeamID(FGenericTeamId OldTeamID);
};
#undef UE_API
|