54 lines
1.3 KiB
C++
54 lines
1.3 KiB
C++
|
|
// Copyright Echo Devgroup
|
||
|
|
|
||
|
|
|
||
|
|
#include "AbilitySystem/Tasks/TargetDataUnderMouse.h"
|
||
|
|
|
||
|
|
#include "AbilitySystemComponent.h"
|
||
|
|
|
||
|
|
UTargetDataUnderMouse* UTargetDataUnderMouse::CreateTargetDataUnderMouse(UGameplayAbility* OwningAbility)
|
||
|
|
{
|
||
|
|
UTargetDataUnderMouse* MyObj = NewAbilityTask<UTargetDataUnderMouse>(OwningAbility);
|
||
|
|
return MyObj;
|
||
|
|
}
|
||
|
|
|
||
|
|
void UTargetDataUnderMouse::Activate()
|
||
|
|
{
|
||
|
|
const bool bIsLocallyControlled = Ability->GetCurrentActorInfo()->IsLocallyControlled();
|
||
|
|
if (bIsLocallyControlled)
|
||
|
|
{
|
||
|
|
SendMouseCursorData();
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
//TODO: We are on the server, so listen for target data
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
void UTargetDataUnderMouse::SendMouseCursorData()
|
||
|
|
{
|
||
|
|
FScopedPredictionWindow ScopedPrediction(AbilitySystemComponent.Get());
|
||
|
|
|
||
|
|
APlayerController* PC = Ability->GetCurrentActorInfo()->PlayerController.Get();
|
||
|
|
FHitResult CursorHit;
|
||
|
|
PC->GetHitResultUnderCursor(ECC_Visibility, false, CursorHit);
|
||
|
|
|
||
|
|
FGameplayAbilityTargetDataHandle DataHandle;
|
||
|
|
FGameplayAbilityTargetData_SingleTargetHit* Data = new FGameplayAbilityTargetData_SingleTargetHit();
|
||
|
|
Data->HitResult = CursorHit;
|
||
|
|
DataHandle.Add(Data);
|
||
|
|
|
||
|
|
AbilitySystemComponent->ServerSetReplicatedTargetData(
|
||
|
|
GetAbilitySpecHandle(),
|
||
|
|
GetActivationPredictionKey(),
|
||
|
|
DataHandle, FGameplayTag(),
|
||
|
|
AbilitySystemComponent->ScopedPredictionKey
|
||
|
|
);
|
||
|
|
|
||
|
|
if (ShouldBroadcastAbilityTaskDelegates())
|
||
|
|
{
|
||
|
|
ValidData.Broadcast(DataHandle);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|