|
|
|
|
| #include "LyraCharacter.h"
|
|
|
| #include "AbilitySystem/LyraAbilitySystemComponent.h"
|
| #include "Camera/LyraCameraComponent.h"
|
| #include "Character/LyraHealthComponent.h"
|
| #include "Character/LyraPawnExtensionComponent.h"
|
| #include "Components/CapsuleComponent.h"
|
| #include "Components/SkeletalMeshComponent.h"
|
| #include "LyraCharacterMovementComponent.h"
|
| #include "LyraGameplayTags.h"
|
| #include "LyraLogChannels.h"
|
| #include "Net/UnrealNetwork.h"
|
| #include "Player/LyraPlayerController.h"
|
| #include "Player/LyraPlayerState.h"
|
| #include "System/LyraSignificanceManager.h"
|
| #include "TimerManager.h"
|
|
|
| #include UE_INLINE_GENERATED_CPP_BY_NAME(LyraCharacter)
|
|
|
| class AActor;
|
| class FLifetimeProperty;
|
| class IRepChangedPropertyTracker;
|
| class UInputComponent;
|
|
|
| static FName NAME_LyraCharacterCollisionProfile_Capsule(TEXT("LyraPawnCapsule"));
|
| static FName NAME_LyraCharacterCollisionProfile_Mesh(TEXT("LyraPawnMesh"));
|
|
|
| ALyraCharacter::ALyraCharacter(const FObjectInitializer& ObjectInitializer)
|
| : Super(ObjectInitializer.SetDefaultSubobjectClass<ULyraCharacterMovementComponent>(ACharacter::CharacterMovementComponentName))
|
| {
|
|
|
| PrimaryActorTick.bCanEverTick = false;
|
| PrimaryActorTick.bStartWithTickEnabled = false;
|
|
|
| SetNetCullDistanceSquared(900000000.0f);
|
|
|
| UCapsuleComponent* CapsuleComp = GetCapsuleComponent();
|
| check(CapsuleComp);
|
| CapsuleComp->InitCapsuleSize(40.0f, 90.0f);
|
| CapsuleComp->SetCollisionProfileName(NAME_LyraCharacterCollisionProfile_Capsule);
|
|
|
| USkeletalMeshComponent* MeshComp = GetMesh();
|
| check(MeshComp);
|
| MeshComp->SetRelativeRotation(FRotator(0.0f, -90.0f, 0.0f));
|
| MeshComp->SetCollisionProfileName(NAME_LyraCharacterCollisionProfile_Mesh);
|
|
|
| ULyraCharacterMovementComponent* LyraMoveComp = CastChecked<ULyraCharacterMovementComponent>(GetCharacterMovement());
|
| LyraMoveComp->GravityScale = 1.0f;
|
| LyraMoveComp->MaxAcceleration = 2400.0f;
|
| LyraMoveComp->BrakingFrictionFactor = 1.0f;
|
| LyraMoveComp->BrakingFriction = 6.0f;
|
| LyraMoveComp->GroundFriction = 8.0f;
|
| LyraMoveComp->BrakingDecelerationWalking = 1400.0f;
|
| LyraMoveComp->bUseControllerDesiredRotation = false;
|
| LyraMoveComp->bOrientRotationToMovement = false;
|
| LyraMoveComp->RotationRate = FRotator(0.0f, 720.0f, 0.0f);
|
| LyraMoveComp->bAllowPhysicsRotationDuringAnimRootMotion = false;
|
| LyraMoveComp->GetNavAgentPropertiesRef().bCanCrouch = true;
|
| LyraMoveComp->bCanWalkOffLedgesWhenCrouching = true;
|
| LyraMoveComp->SetCrouchedHalfHeight(65.0f);
|
|
|
| PawnExtComponent = CreateDefaultSubobject<ULyraPawnExtensionComponent>(TEXT("PawnExtensionComponent"));
|
| PawnExtComponent->OnAbilitySystemInitialized_RegisterAndCall(FSimpleMulticastDelegate::FDelegate::CreateUObject(this, &ThisClass::OnAbilitySystemInitialized));
|
| PawnExtComponent->OnAbilitySystemUninitialized_Register(FSimpleMulticastDelegate::FDelegate::CreateUObject(this, &ThisClass::OnAbilitySystemUninitialized));
|
|
|
| HealthComponent = CreateDefaultSubobject<ULyraHealthComponent>(TEXT("HealthComponent"));
|
| HealthComponent->OnDeathStarted.AddDynamic(this, &ThisClass::OnDeathStarted);
|
| HealthComponent->OnDeathFinished.AddDynamic(this, &ThisClass::OnDeathFinished);
|
|
|
| CameraComponent = CreateDefaultSubobject<ULyraCameraComponent>(TEXT("CameraComponent"));
|
| CameraComponent->SetRelativeLocation(FVector(-300.0f, 0.0f, 75.0f));
|
|
|
| bUseControllerRotationPitch = false;
|
| bUseControllerRotationYaw = true;
|
| bUseControllerRotationRoll = false;
|
|
|
| BaseEyeHeight = 80.0f;
|
| CrouchedEyeHeight = 50.0f;
|
| }
|
|
|
| void ALyraCharacter::PreInitializeComponents()
|
| {
|
| Super::PreInitializeComponents();
|
| }
|
|
|
| void ALyraCharacter::BeginPlay()
|
| {
|
| Super::BeginPlay();
|
|
|
| UWorld* World = GetWorld();
|
|
|
| const bool bRegisterWithSignificanceManager = !IsNetMode(NM_DedicatedServer);
|
| if (bRegisterWithSignificanceManager)
|
| {
|
| if (ULyraSignificanceManager* SignificanceManager = USignificanceManager::Get<ULyraSignificanceManager>(World))
|
| {
|
|
|
| }
|
| }
|
| }
|
|
|
| void ALyraCharacter::EndPlay(const EEndPlayReason::Type EndPlayReason)
|
| {
|
| Super::EndPlay(EndPlayReason);
|
|
|
| UWorld* World = GetWorld();
|
|
|
| const bool bRegisterWithSignificanceManager = !IsNetMode(NM_DedicatedServer);
|
| if (bRegisterWithSignificanceManager)
|
| {
|
| if (ULyraSignificanceManager* SignificanceManager = USignificanceManager::Get<ULyraSignificanceManager>(World))
|
| {
|
| SignificanceManager->UnregisterObject(this);
|
| }
|
| }
|
| }
|
|
|
| void ALyraCharacter::Reset()
|
| {
|
| DisableMovementAndCollision();
|
|
|
| K2_OnReset();
|
|
|
| UninitAndDestroy();
|
| }
|
|
|
| void ALyraCharacter::GetLifetimeReplicatedProps(TArray< FLifetimeProperty >& OutLifetimeProps) const
|
| {
|
| Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
|
|
| DOREPLIFETIME_CONDITION(ThisClass, ReplicatedAcceleration, COND_SimulatedOnly);
|
| DOREPLIFETIME(ThisClass, MyTeamID)
|
| }
|
|
|
| void ALyraCharacter::PreReplication(IRepChangedPropertyTracker& ChangedPropertyTracker)
|
| {
|
| Super::PreReplication(ChangedPropertyTracker);
|
|
|
| if (UCharacterMovementComponent* MovementComponent = GetCharacterMovement())
|
| {
|
|
|
| const double MaxAccel = MovementComponent->MaxAcceleration;
|
| const FVector CurrentAccel = MovementComponent->GetCurrentAcceleration();
|
| double AccelXYRadians, AccelXYMagnitude;
|
| FMath::CartesianToPolar(CurrentAccel.X, CurrentAccel.Y, AccelXYMagnitude, AccelXYRadians);
|
|
|
| ReplicatedAcceleration.AccelXYRadians = FMath::FloorToInt((AccelXYRadians / TWO_PI) * 255.0);
|
| ReplicatedAcceleration.AccelXYMagnitude = FMath::FloorToInt((AccelXYMagnitude / MaxAccel) * 255.0);
|
| ReplicatedAcceleration.AccelZ = FMath::FloorToInt((CurrentAccel.Z / MaxAccel) * 127.0);
|
| }
|
| }
|
|
|
| void ALyraCharacter::NotifyControllerChanged()
|
| {
|
| const FGenericTeamId OldTeamId = GetGenericTeamId();
|
|
|
| Super::NotifyControllerChanged();
|
|
|
|
|
| if (HasAuthority() && (GetController() != nullptr))
|
| {
|
| if (ILyraTeamAgentInterface* ControllerWithTeam = Cast<ILyraTeamAgentInterface>(GetController()))
|
| {
|
| MyTeamID = ControllerWithTeam->GetGenericTeamId();
|
| ConditionalBroadcastTeamChanged(this, OldTeamId, MyTeamID);
|
| }
|
| }
|
| }
|
|
|
| ALyraPlayerController* ALyraCharacter::GetLyraPlayerController() const
|
| {
|
| return CastChecked<ALyraPlayerController>(GetController(), ECastCheckedType::NullAllowed);
|
| }
|
|
|
| ALyraPlayerState* ALyraCharacter::GetLyraPlayerState() const
|
| {
|
| return CastChecked<ALyraPlayerState>(GetPlayerState(), ECastCheckedType::NullAllowed);
|
| }
|
|
|
| ULyraAbilitySystemComponent* ALyraCharacter::GetLyraAbilitySystemComponent() const
|
| {
|
| return Cast<ULyraAbilitySystemComponent>(GetAbilitySystemComponent());
|
| }
|
|
|
| UAbilitySystemComponent* ALyraCharacter::GetAbilitySystemComponent() const
|
| {
|
| if (PawnExtComponent == nullptr)
|
| {
|
| return nullptr;
|
| }
|
|
|
| return PawnExtComponent->GetLyraAbilitySystemComponent();
|
| }
|
|
|
| void ALyraCharacter::OnAbilitySystemInitialized()
|
| {
|
| ULyraAbilitySystemComponent* LyraASC = GetLyraAbilitySystemComponent();
|
| check(LyraASC);
|
|
|
| HealthComponent->InitializeWithAbilitySystem(LyraASC);
|
|
|
| InitializeGameplayTags();
|
| }
|
|
|
| void ALyraCharacter::OnAbilitySystemUninitialized()
|
| {
|
| HealthComponent->UninitializeFromAbilitySystem();
|
| }
|
|
|
| void ALyraCharacter::PossessedBy(AController* NewController)
|
| {
|
| const FGenericTeamId OldTeamID = MyTeamID;
|
|
|
| Super::PossessedBy(NewController);
|
|
|
| PawnExtComponent->HandleControllerChanged();
|
|
|
|
|
| if (ILyraTeamAgentInterface* ControllerAsTeamProvider = Cast<ILyraTeamAgentInterface>(NewController))
|
| {
|
| MyTeamID = ControllerAsTeamProvider->GetGenericTeamId();
|
| ControllerAsTeamProvider->GetTeamChangedDelegateChecked().AddDynamic(this, &ThisClass::OnControllerChangedTeam);
|
| }
|
| ConditionalBroadcastTeamChanged(this, OldTeamID, MyTeamID);
|
| }
|
|
|
| void ALyraCharacter::UnPossessed()
|
| {
|
| AController* const OldController = GetController();
|
|
|
|
|
| const FGenericTeamId OldTeamID = MyTeamID;
|
| if (ILyraTeamAgentInterface* ControllerAsTeamProvider = Cast<ILyraTeamAgentInterface>(OldController))
|
| {
|
| ControllerAsTeamProvider->GetTeamChangedDelegateChecked().RemoveAll(this);
|
| }
|
|
|
| Super::UnPossessed();
|
|
|
| PawnExtComponent->HandleControllerChanged();
|
|
|
|
|
| MyTeamID = DetermineNewTeamAfterPossessionEnds(OldTeamID);
|
| ConditionalBroadcastTeamChanged(this, OldTeamID, MyTeamID);
|
| }
|
|
|
| void ALyraCharacter::OnRep_Controller()
|
| {
|
| Super::OnRep_Controller();
|
|
|
| PawnExtComponent->HandleControllerChanged();
|
| }
|
|
|
| void ALyraCharacter::OnRep_PlayerState()
|
| {
|
| Super::OnRep_PlayerState();
|
|
|
| PawnExtComponent->HandlePlayerStateReplicated();
|
| }
|
|
|
| void ALyraCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
| {
|
| Super::SetupPlayerInputComponent(PlayerInputComponent);
|
|
|
| PawnExtComponent->SetupPlayerInputComponent();
|
| }
|
|
|
| void ALyraCharacter::InitializeGameplayTags()
|
| {
|
|
|
| if (ULyraAbilitySystemComponent* LyraASC = GetLyraAbilitySystemComponent())
|
| {
|
| for (const TPair<uint8, FGameplayTag>& TagMapping : LyraGameplayTags::MovementModeTagMap)
|
| {
|
| if (TagMapping.Value.IsValid())
|
| {
|
| LyraASC->SetLooseGameplayTagCount(TagMapping.Value, 0);
|
| }
|
| }
|
|
|
| for (const TPair<uint8, FGameplayTag>& TagMapping : LyraGameplayTags::CustomMovementModeTagMap)
|
| {
|
| if (TagMapping.Value.IsValid())
|
| {
|
| LyraASC->SetLooseGameplayTagCount(TagMapping.Value, 0);
|
| }
|
| }
|
|
|
| ULyraCharacterMovementComponent* LyraMoveComp = CastChecked<ULyraCharacterMovementComponent>(GetCharacterMovement());
|
| SetMovementModeTag(LyraMoveComp->MovementMode, LyraMoveComp->CustomMovementMode, true);
|
| }
|
| }
|
|
|
| void ALyraCharacter::GetOwnedGameplayTags(FGameplayTagContainer& TagContainer) const
|
| {
|
| if (const ULyraAbilitySystemComponent* LyraASC = GetLyraAbilitySystemComponent())
|
| {
|
| LyraASC->GetOwnedGameplayTags(TagContainer);
|
| }
|
| }
|
|
|
| bool ALyraCharacter::HasMatchingGameplayTag(FGameplayTag TagToCheck) const
|
| {
|
| if (const ULyraAbilitySystemComponent* LyraASC = GetLyraAbilitySystemComponent())
|
| {
|
| return LyraASC->HasMatchingGameplayTag(TagToCheck);
|
| }
|
|
|
| return false;
|
| }
|
|
|
| bool ALyraCharacter::HasAllMatchingGameplayTags(const FGameplayTagContainer& TagContainer) const
|
| {
|
| if (const ULyraAbilitySystemComponent* LyraASC = GetLyraAbilitySystemComponent())
|
| {
|
| return LyraASC->HasAllMatchingGameplayTags(TagContainer);
|
| }
|
|
|
| return false;
|
| }
|
|
|
| bool ALyraCharacter::HasAnyMatchingGameplayTags(const FGameplayTagContainer& TagContainer) const
|
| {
|
| if (const ULyraAbilitySystemComponent* LyraASC = GetLyraAbilitySystemComponent())
|
| {
|
| return LyraASC->HasAnyMatchingGameplayTags(TagContainer);
|
| }
|
|
|
| return false;
|
| }
|
|
|
| void ALyraCharacter::FellOutOfWorld(const class UDamageType& dmgType)
|
| {
|
| HealthComponent->DamageSelfDestruct( true);
|
| }
|
|
|
| void ALyraCharacter::OnDeathStarted(AActor*)
|
| {
|
| DisableMovementAndCollision();
|
| }
|
|
|
| void ALyraCharacter::OnDeathFinished(AActor*)
|
| {
|
| GetWorld()->GetTimerManager().SetTimerForNextTick(this, &ThisClass::DestroyDueToDeath);
|
| }
|
|
|
|
|
| void ALyraCharacter::DisableMovementAndCollision()
|
| {
|
| if (GetController())
|
| {
|
| GetController()->SetIgnoreMoveInput(true);
|
| }
|
|
|
| UCapsuleComponent* CapsuleComp = GetCapsuleComponent();
|
| check(CapsuleComp);
|
| CapsuleComp->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
| CapsuleComp->SetCollisionResponseToAllChannels(ECR_Ignore);
|
|
|
| ULyraCharacterMovementComponent* LyraMoveComp = CastChecked<ULyraCharacterMovementComponent>(GetCharacterMovement());
|
| LyraMoveComp->StopMovementImmediately();
|
| LyraMoveComp->DisableMovement();
|
| }
|
|
|
| void ALyraCharacter::DestroyDueToDeath()
|
| {
|
| K2_OnDeathFinished();
|
|
|
| UninitAndDestroy();
|
| }
|
|
|
|
|
| void ALyraCharacter::UninitAndDestroy()
|
| {
|
| if (GetLocalRole() == ROLE_Authority)
|
| {
|
| DetachFromControllerPendingDestroy();
|
| SetLifeSpan(0.1f);
|
| }
|
|
|
|
|
| if (ULyraAbilitySystemComponent* LyraASC = GetLyraAbilitySystemComponent())
|
| {
|
| if (LyraASC->GetAvatarActor() == this)
|
| {
|
| PawnExtComponent->UninitializeAbilitySystem();
|
| }
|
| }
|
|
|
| SetActorHiddenInGame(true);
|
| }
|
|
|
| void ALyraCharacter::OnMovementModeChanged(EMovementMode PrevMovementMode, uint8 PreviousCustomMode)
|
| {
|
| Super::OnMovementModeChanged(PrevMovementMode, PreviousCustomMode);
|
|
|
| ULyraCharacterMovementComponent* LyraMoveComp = CastChecked<ULyraCharacterMovementComponent>(GetCharacterMovement());
|
|
|
| SetMovementModeTag(PrevMovementMode, PreviousCustomMode, false);
|
| SetMovementModeTag(LyraMoveComp->MovementMode, LyraMoveComp->CustomMovementMode, true);
|
| }
|
|
|
| void ALyraCharacter::SetMovementModeTag(EMovementMode MovementMode, uint8 CustomMovementMode, bool bTagEnabled)
|
| {
|
| if (ULyraAbilitySystemComponent* LyraASC = GetLyraAbilitySystemComponent())
|
| {
|
| const FGameplayTag* MovementModeTag = nullptr;
|
| if (MovementMode == MOVE_Custom)
|
| {
|
| MovementModeTag = LyraGameplayTags::CustomMovementModeTagMap.Find(CustomMovementMode);
|
| }
|
| else
|
| {
|
| MovementModeTag = LyraGameplayTags::MovementModeTagMap.Find(MovementMode);
|
| }
|
|
|
| if (MovementModeTag && MovementModeTag->IsValid())
|
| {
|
| LyraASC->SetLooseGameplayTagCount(*MovementModeTag, (bTagEnabled ? 1 : 0));
|
| }
|
| }
|
| }
|
|
|
| void ALyraCharacter::ToggleCrouch()
|
| {
|
| const ULyraCharacterMovementComponent* LyraMoveComp = CastChecked<ULyraCharacterMovementComponent>(GetCharacterMovement());
|
|
|
| if (IsCrouched() || LyraMoveComp->bWantsToCrouch)
|
| {
|
| UnCrouch();
|
| }
|
| else if (LyraMoveComp->IsMovingOnGround())
|
| {
|
| Crouch();
|
| }
|
| }
|
|
|
| void ALyraCharacter::OnStartCrouch(float HalfHeightAdjust, float ScaledHalfHeightAdjust)
|
| {
|
| if (ULyraAbilitySystemComponent* LyraASC = GetLyraAbilitySystemComponent())
|
| {
|
| LyraASC->SetLooseGameplayTagCount(LyraGameplayTags::Status_Crouching, 1);
|
| }
|
|
|
|
|
| Super::OnStartCrouch(HalfHeightAdjust, ScaledHalfHeightAdjust);
|
| }
|
|
|
| void ALyraCharacter::OnEndCrouch(float HalfHeightAdjust, float ScaledHalfHeightAdjust)
|
| {
|
| if (ULyraAbilitySystemComponent* LyraASC = GetLyraAbilitySystemComponent())
|
| {
|
| LyraASC->SetLooseGameplayTagCount(LyraGameplayTags::Status_Crouching, 0);
|
| }
|
|
|
| Super::OnEndCrouch(HalfHeightAdjust, ScaledHalfHeightAdjust);
|
| }
|
|
|
| bool ALyraCharacter::CanJumpInternal_Implementation() const
|
| {
|
|
|
| return JumpIsAllowedInternal();
|
| }
|
|
|
| void ALyraCharacter::OnRep_ReplicatedAcceleration()
|
| {
|
| if (ULyraCharacterMovementComponent* LyraMovementComponent = Cast<ULyraCharacterMovementComponent>(GetCharacterMovement()))
|
| {
|
|
|
| const double MaxAccel = LyraMovementComponent->MaxAcceleration;
|
| const double AccelXYMagnitude = double(ReplicatedAcceleration.AccelXYMagnitude) * MaxAccel / 255.0;
|
| const double AccelXYRadians = double(ReplicatedAcceleration.AccelXYRadians) * TWO_PI / 255.0;
|
|
|
| FVector UnpackedAcceleration(FVector::ZeroVector);
|
| FMath::PolarToCartesian(AccelXYMagnitude, AccelXYRadians, UnpackedAcceleration.X, UnpackedAcceleration.Y);
|
| UnpackedAcceleration.Z = double(ReplicatedAcceleration.AccelZ) * MaxAccel / 127.0;
|
|
|
| LyraMovementComponent->SetReplicatedAcceleration(UnpackedAcceleration);
|
| }
|
| }
|
|
|
| void ALyraCharacter::SetGenericTeamId(const FGenericTeamId& NewTeamID)
|
| {
|
| if (GetController() == nullptr)
|
| {
|
| if (HasAuthority())
|
| {
|
| const FGenericTeamId OldTeamID = MyTeamID;
|
| MyTeamID = NewTeamID;
|
| ConditionalBroadcastTeamChanged(this, OldTeamID, MyTeamID);
|
| }
|
| else
|
| {
|
| UE_LOG(LogLyraTeams, Error, TEXT("You can't set the team ID on a character (%s) except on the authority"), *GetPathNameSafe(this));
|
| }
|
| }
|
| else
|
| {
|
| UE_LOG(LogLyraTeams, Error, TEXT("You can't set the team ID on a possessed character (%s); it's driven by the associated controller"), *GetPathNameSafe(this));
|
| }
|
| }
|
|
|
| FGenericTeamId ALyraCharacter::GetGenericTeamId() const
|
| {
|
| return MyTeamID;
|
| }
|
|
|
| FOnLyraTeamIndexChangedDelegate* ALyraCharacter::GetOnTeamIndexChangedDelegate()
|
| {
|
| return &OnTeamChangedDelegate;
|
| }
|
|
|
| void ALyraCharacter::OnControllerChangedTeam(UObject* TeamAgent, int32 OldTeam, int32 NewTeam)
|
| {
|
| const FGenericTeamId MyOldTeamID = MyTeamID;
|
| MyTeamID = IntegerToGenericTeamId(NewTeam);
|
| ConditionalBroadcastTeamChanged(this, MyOldTeamID, MyTeamID);
|
| }
|
|
|
| void ALyraCharacter::OnRep_MyTeamID(FGenericTeamId OldTeamID)
|
| {
|
| ConditionalBroadcastTeamChanged(this, OldTeamID, MyTeamID);
|
| }
|
|
|
| bool ALyraCharacter::UpdateSharedReplication()
|
| {
|
| if (GetLocalRole() == ROLE_Authority)
|
| {
|
| FSharedRepMovement SharedMovement;
|
| if (SharedMovement.FillForCharacter(this))
|
| {
|
|
|
|
|
|
|
|
|
| if (!SharedMovement.Equals(LastSharedReplication, this))
|
| {
|
| LastSharedReplication = SharedMovement;
|
| SetReplicatedMovementMode(SharedMovement.RepMovementMode);
|
|
|
| FastSharedReplication(SharedMovement);
|
| }
|
| return true;
|
| }
|
| }
|
|
|
|
|
| return false;
|
| }
|
|
|
| void ALyraCharacter::FastSharedReplication_Implementation(const FSharedRepMovement& SharedRepMovement)
|
| {
|
| if (GetWorld()->IsPlayingReplay())
|
| {
|
| return;
|
| }
|
|
|
|
|
| if (GetLocalRole() == ROLE_SimulatedProxy)
|
| {
|
|
|
| SetReplicatedServerLastTransformUpdateTimeStamp(SharedRepMovement.RepTimeStamp);
|
|
|
|
|
| if (GetReplicatedMovementMode() != SharedRepMovement.RepMovementMode)
|
| {
|
| SetReplicatedMovementMode(SharedRepMovement.RepMovementMode);
|
| GetCharacterMovement()->bNetworkMovementModeChanged = true;
|
| GetCharacterMovement()->bNetworkUpdateReceived = true;
|
| }
|
|
|
|
|
| FRepMovement& MutableRepMovement = GetReplicatedMovement_Mutable();
|
| MutableRepMovement = SharedRepMovement.RepMovement;
|
|
|
|
|
| OnRep_ReplicatedMovement();
|
|
|
|
|
| SetProxyIsJumpForceApplied(SharedRepMovement.bProxyIsJumpForceApplied);
|
|
|
|
|
| if (IsCrouched() != SharedRepMovement.bIsCrouched)
|
| {
|
| SetIsCrouched(SharedRepMovement.bIsCrouched);
|
| OnRep_IsCrouched();
|
| }
|
| }
|
| }
|
|
|
| FSharedRepMovement::FSharedRepMovement()
|
| {
|
| RepMovement.LocationQuantizationLevel = EVectorQuantization::RoundTwoDecimals;
|
| }
|
|
|
| bool FSharedRepMovement::FillForCharacter(ACharacter* Character)
|
| {
|
| if (USceneComponent* PawnRootComponent = Character->GetRootComponent())
|
| {
|
| UCharacterMovementComponent* CharacterMovement = Character->GetCharacterMovement();
|
|
|
| RepMovement.Location = FRepMovement::RebaseOntoZeroOrigin(PawnRootComponent->GetComponentLocation(), Character);
|
| RepMovement.Rotation = PawnRootComponent->GetComponentRotation();
|
| RepMovement.LinearVelocity = CharacterMovement->Velocity;
|
| RepMovementMode = CharacterMovement->PackNetworkMovementMode();
|
| bProxyIsJumpForceApplied = Character->GetProxyIsJumpForceApplied() || (Character->JumpForceTimeRemaining > 0.0f);
|
| bIsCrouched = Character->IsCrouched();
|
|
|
|
|
| if ((CharacterMovement->NetworkSmoothingMode == ENetworkSmoothingMode::Linear) || CharacterMovement->bNetworkAlwaysReplicateTransformUpdateTimestamp)
|
| {
|
| RepTimeStamp = CharacterMovement->GetServerLastTransformUpdateTimeStamp();
|
| }
|
| else
|
| {
|
| RepTimeStamp = 0.f;
|
| }
|
|
|
| return true;
|
| }
|
| return false;
|
| }
|
|
|
| bool FSharedRepMovement::Equals(const FSharedRepMovement& Other, ACharacter* Character) const
|
| {
|
| if (RepMovement.Location != Other.RepMovement.Location)
|
| {
|
| return false;
|
| }
|
|
|
| if (RepMovement.Rotation != Other.RepMovement.Rotation)
|
| {
|
| return false;
|
| }
|
|
|
| if (RepMovement.LinearVelocity != Other.RepMovement.LinearVelocity)
|
| {
|
| return false;
|
| }
|
|
|
| if (RepMovementMode != Other.RepMovementMode)
|
| {
|
| return false;
|
| }
|
|
|
| if (bProxyIsJumpForceApplied != Other.bProxyIsJumpForceApplied)
|
| {
|
| return false;
|
| }
|
|
|
| if (bIsCrouched != Other.bIsCrouched)
|
| {
|
| return false;
|
| }
|
|
|
| return true;
|
| }
|
|
|
| bool FSharedRepMovement::NetSerialize(FArchive& Ar, class UPackageMap* Map, bool& bOutSuccess)
|
| {
|
| bOutSuccess = true;
|
| RepMovement.NetSerialize(Ar, Map, bOutSuccess);
|
| Ar << RepMovementMode;
|
| Ar << bProxyIsJumpForceApplied;
|
| Ar << bIsCrouched;
|
|
|
|
|
| uint8 bHasTimeStamp = (RepTimeStamp != 0.f);
|
| Ar.SerializeBits(&bHasTimeStamp, 1);
|
| if (bHasTimeStamp)
|
| {
|
| Ar << RepTimeStamp;
|
| }
|
| else
|
| {
|
| RepTimeStamp = 0.f;
|
| }
|
|
|
| return true;
|
| } |