2022-11-01 15:14:34 -04:00
|
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
|
|
#include "GameplayInteractionSendSlotEventTask.h"
|
|
|
|
|
|
#include "StateTreeExecutionContext.h"
|
|
|
|
|
|
#include "SmartObjectSubsystem.h"
|
|
|
|
|
|
#include "StateTreeLinker.h"
|
|
|
|
|
|
#include "VisualLogger/VisualLogger.h"
|
|
|
|
|
|
|
2022-11-18 08:38:31 -05:00
|
|
|
|
#define LOCTEXT_NAMESPACE "GameplayInteractions"
|
|
|
|
|
|
|
2022-11-01 15:14:34 -04:00
|
|
|
|
FGameplayInteractionSendSlotEventTask::FGameplayInteractionSendSlotEventTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
// No tick needed.
|
|
|
|
|
|
bShouldCallTick = false;
|
|
|
|
|
|
bShouldCopyBoundPropertiesOnTick = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool FGameplayInteractionSendSlotEventTask::Link(FStateTreeLinker& Linker)
|
|
|
|
|
|
{
|
|
|
|
|
|
Linker.LinkExternalData(SmartObjectSubsystemHandle);
|
|
|
|
|
|
|
|
|
|
|
|
// Copy properties on exit state if the event is sent then.
|
|
|
|
|
|
bShouldCopyBoundPropertiesOnExitState = (Trigger == EGameplayInteractionTaskTrigger::OnExitState);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-18 08:38:31 -05:00
|
|
|
|
EDataValidationResult FGameplayInteractionSendSlotEventTask::Compile(FStateTreeDataView InstanceDataView, TArray<FText>& ValidationMessages)
|
|
|
|
|
|
{
|
|
|
|
|
|
EDataValidationResult Result = EDataValidationResult::Valid;
|
|
|
|
|
|
|
|
|
|
|
|
if (!EventTag.IsValid() && !Payload.IsValid())
|
|
|
|
|
|
{
|
|
|
|
|
|
ValidationMessages.Add(LOCTEXT("MissingEventData", "EventTag and Payload properties are empty, expecting valid tag."));
|
|
|
|
|
|
Result = EDataValidationResult::Invalid;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-01 15:14:34 -04:00
|
|
|
|
EStateTreeRunStatus FGameplayInteractionSendSlotEventTask::EnterState(FStateTreeExecutionContext& Context, const FStateTreeTransitionResult& Transition) const
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Trigger == EGameplayInteractionTaskTrigger::OnEnterState)
|
|
|
|
|
|
{
|
|
|
|
|
|
USmartObjectSubsystem& SmartObjectSubsystem = Context.GetExternalData(SmartObjectSubsystemHandle);
|
|
|
|
|
|
const FInstanceDataType& InstanceData = Context.GetInstanceData(*this);
|
|
|
|
|
|
|
|
|
|
|
|
if (InstanceData.TargetSlot.IsValid())
|
|
|
|
|
|
{
|
|
|
|
|
|
// Send the event
|
|
|
|
|
|
SmartObjectSubsystem.SendSlotEvent(InstanceData.TargetSlot, EventTag, Payload);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
UE_VLOG_UELOG(Context.GetOwner(), LogStateTree, Error, TEXT("[GameplayInteractionSendSlotEventTask] Expected valid TargetSlot handle."));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return EStateTreeRunStatus::Running;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FGameplayInteractionSendSlotEventTask::ExitState(FStateTreeExecutionContext& Context, const FStateTreeTransitionResult& Transition) const
|
|
|
|
|
|
{
|
|
|
|
|
|
const bool bLastStateFailed = Transition.CurrentRunStatus == EStateTreeRunStatus::Failed;
|
|
|
|
|
|
|
|
|
|
|
|
if (Trigger == EGameplayInteractionTaskTrigger::OnExitState
|
|
|
|
|
|
|| (bLastStateFailed && Trigger == EGameplayInteractionTaskTrigger::OnExitStateFailed)
|
|
|
|
|
|
|| (!bLastStateFailed && Trigger == EGameplayInteractionTaskTrigger::OnExitStateSucceeded))
|
|
|
|
|
|
{
|
|
|
|
|
|
USmartObjectSubsystem& SmartObjectSubsystem = Context.GetExternalData(SmartObjectSubsystemHandle);
|
|
|
|
|
|
const FInstanceDataType& InstanceData = Context.GetInstanceData(*this);
|
|
|
|
|
|
|
|
|
|
|
|
if (InstanceData.TargetSlot.IsValid())
|
|
|
|
|
|
{
|
|
|
|
|
|
// Send the event
|
|
|
|
|
|
SmartObjectSubsystem.SendSlotEvent(InstanceData.TargetSlot, EventTag, Payload);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
UE_VLOG_UELOG(Context.GetOwner(), LogStateTree, Error, TEXT("[GameplayInteractionSendSlotEventTask] Expected valid TargetSlot handle."));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-11-18 08:38:31 -05:00
|
|
|
|
|
|
|
|
|
|
#undef LOCTEXT_NAMESPACE
|