2022-05-23 18:41:30 +00:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
#include "LyraVerbMessageHelpers.h"
|
2022-09-13 07:18:28 +00:00
|
|
|
|
|
|
|
#include "Containers/UnrealString.h"
|
|
|
|
#include "GameFramework/Actor.h"
|
2022-05-23 18:41:30 +00:00
|
|
|
#include "GameFramework/Pawn.h"
|
2022-09-13 07:18:28 +00:00
|
|
|
#include "GameFramework/PlayerController.h"
|
|
|
|
#include "GameFramework/PlayerState.h"
|
|
|
|
#include "GameplayTagContainer.h"
|
|
|
|
#include "Messages/LyraVerbMessage.h"
|
|
|
|
#include "Templates/Casts.h"
|
|
|
|
#include "UObject/Class.h"
|
|
|
|
#include "UObject/Object.h"
|
|
|
|
#include "UObject/ObjectPtr.h"
|
|
|
|
#include "UObject/PropertyPortFlags.h"
|
|
|
|
#include "UObject/WeakObjectPtr.h"
|
|
|
|
#include "UObject/WeakObjectPtrTemplates.h"
|
2022-05-23 18:41:30 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// FLyraVerbMessage
|
|
|
|
|
|
|
|
FString FLyraVerbMessage::ToString() const
|
|
|
|
{
|
|
|
|
FString HumanReadableMessage;
|
|
|
|
FLyraVerbMessage::StaticStruct()->ExportText(/*out*/ HumanReadableMessage, this, /*Defaults=*/ nullptr, /*OwnerObject=*/ nullptr, PPF_None, /*ExportRootScope=*/ nullptr);
|
|
|
|
return HumanReadableMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
|
|
|
|
APlayerState* ULyraVerbMessageHelpers::GetPlayerStateFromObject(UObject* Object)
|
|
|
|
{
|
|
|
|
if (APlayerController* PC = Cast<APlayerController>(Object))
|
|
|
|
{
|
|
|
|
return PC->PlayerState;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (APlayerState* TargetPS = Cast<APlayerState>(Object))
|
|
|
|
{
|
|
|
|
return TargetPS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (APawn* TargetPawn = Cast<APawn>(Object))
|
|
|
|
{
|
|
|
|
if (APlayerState* TargetPS = TargetPawn->GetPlayerState())
|
|
|
|
{
|
|
|
|
return TargetPS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
APlayerController* ULyraVerbMessageHelpers::GetPlayerControllerFromObject(UObject* Object)
|
|
|
|
{
|
|
|
|
if (APlayerController* PC = Cast<APlayerController>(Object))
|
|
|
|
{
|
|
|
|
return PC;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (APlayerState* TargetPS = Cast<APlayerState>(Object))
|
|
|
|
{
|
|
|
|
return TargetPS->GetPlayerController();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (APawn* TargetPawn = Cast<APawn>(Object))
|
|
|
|
{
|
|
|
|
return Cast<APlayerController>(TargetPawn->GetController());
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
FGameplayCueParameters ULyraVerbMessageHelpers::VerbMessageToCueParameters(const FLyraVerbMessage& Message)
|
|
|
|
{
|
|
|
|
FGameplayCueParameters Result;
|
|
|
|
|
|
|
|
Result.OriginalTag = Message.Verb;
|
|
|
|
Result.Instigator = Cast<AActor>(Message.Instigator);
|
|
|
|
Result.EffectCauser = Cast<AActor>(Message.Target);
|
|
|
|
Result.AggregatedSourceTags = Message.InstigatorTags;
|
|
|
|
Result.AggregatedTargetTags = Message.TargetTags;
|
|
|
|
//@TODO: = Message.ContextTags;
|
|
|
|
Result.RawMagnitude = Message.Magnitude;
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
FLyraVerbMessage ULyraVerbMessageHelpers::CueParametersToVerbMessage(const FGameplayCueParameters& Params)
|
|
|
|
{
|
|
|
|
FLyraVerbMessage Result;
|
|
|
|
|
|
|
|
Result.Verb = Params.OriginalTag;
|
|
|
|
Result.Instigator = Params.Instigator.Get();
|
|
|
|
Result.Target = Params.EffectCauser.Get();
|
|
|
|
Result.InstigatorTags = Params.AggregatedSourceTags;
|
|
|
|
Result.TargetTags = Params.AggregatedTargetTags;
|
|
|
|
//@TODO: Result.ContextTags = ???;
|
|
|
|
Result.Magnitude = Params.RawMagnitude;
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|