RealtimeStyleTransferRuntime/Source/LyraGame/Player/LyraPlayerStart.cpp

79 lines
2.3 KiB
C++
Raw Permalink Normal View History

2022-05-23 18:41:30 +00:00
// Copyright Epic Games, Inc. All Rights Reserved.
#include "LyraPlayerStart.h"
2022-09-13 07:18:28 +00:00
#include "Delegates/Delegate.h"
#include "Engine/World.h"
#include "GameFramework/Controller.h"
2022-05-23 18:41:30 +00:00
#include "GameFramework/GameModeBase.h"
#include "GameFramework/Pawn.h"
2022-09-13 07:18:28 +00:00
#include "Math/MathFwd.h"
#include "Math/Rotator.h"
#include "Math/Vector.h"
#include "Templates/SubclassOf.h"
2022-05-23 18:41:30 +00:00
#include "TimerManager.h"
2022-09-13 07:18:28 +00:00
#include "UObject/Class.h"
2022-05-23 18:41:30 +00:00
ALyraPlayerStart::ALyraPlayerStart(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}
ELyraPlayerStartLocationOccupancy ALyraPlayerStart::GetLocationOccupancy(AController* const ControllerPawnToFit) const
{
UWorld* const World = GetWorld();
if (HasAuthority() && World)
{
if (AGameModeBase* AuthGameMode = World->GetAuthGameMode())
{
TSubclassOf<APawn> PawnClass = AuthGameMode->GetDefaultPawnClassForController(ControllerPawnToFit);
const APawn* const PawnToFit = PawnClass ? GetDefault<APawn>(PawnClass) : nullptr;
FVector ActorLocation = GetActorLocation();
const FRotator ActorRotation = GetActorRotation();
if (!World->EncroachingBlockingGeometry(PawnToFit, ActorLocation, ActorRotation, nullptr))
{
return ELyraPlayerStartLocationOccupancy::Empty;
}
else if (World->FindTeleportSpot(PawnToFit, ActorLocation, ActorRotation))
{
return ELyraPlayerStartLocationOccupancy::Partial;
}
}
}
return ELyraPlayerStartLocationOccupancy::Full;
}
bool ALyraPlayerStart::IsClaimed() const
{
return ClaimingController != nullptr;
}
bool ALyraPlayerStart::TryClaim(AController* OccupyingController)
{
if (OccupyingController != nullptr && !IsClaimed())
{
ClaimingController = OccupyingController;
if (UWorld* World = GetWorld())
{
World->GetTimerManager().SetTimer(ExpirationTimerHandle, FTimerDelegate::CreateUObject(this, &ALyraPlayerStart::CheckUnclaimed), ExpirationCheckInterval, true);
}
return true;
}
return false;
}
void ALyraPlayerStart::CheckUnclaimed()
{
if (ClaimingController != nullptr && ClaimingController->GetPawn() != nullptr && GetLocationOccupancy(ClaimingController) == ELyraPlayerStartLocationOccupancy::Empty)
{
ClaimingController = nullptr;
if (UWorld* World = GetWorld())
{
World->GetTimerManager().ClearTimer(ExpirationTimerHandle);
}
}
}