document.write("
// Fill out your copyright notice in the Description page of Project Settings.
#include "DandelionGameplayAbility.h"
#include "AbilitySystemComponent.h"
#include "Dandelion/Sandbox/Pawns/DandelionCharacter.h"
DEFINE_LOG_CATEGORY(LogGameplayAbility);
AActor* UDandelionGameplayAbility::GetASCOwnerActor(
const FGameplayAbilityActorInfo* ActorInfo
)
{
const ADandelionCharacter* AvatarCharacter = ActorInfo ?
Cast<ADandelionCharacter>(ActorInfo->AvatarActor.Get()) :
nullptr;
const UAbilitySystemComponent* AvatarASC = AvatarCharacter ? AvatarCharacter->GetAbilitySystemComponent() : nullptr;
return AvatarASC ? AvatarASC->GetOwnerActor() : nullptr;
}
void UDandelionGameplayAbility::RestartAbility(
const FGameplayAbilitySpecHandle Handle,
const FGameplayAbilityActorInfo* ActorInfo,
const FGameplayAbilityActivationInfo ActivationInfo,
const bool bReplicateRestartAbility,
const bool bCancelAbility,
const bool bAllowRemoteActivation
)
{
if (!ensure(IsActive()))
{
UE_LOG(
LogGameplayAbility,
Error,
TEXT("%s: [Key: %d] RestartAbility got called on an inactive ability."),
*GetFullNameSafe(this),
ActivationInfo.GetActivationPredictionKey().Current
);
return;
}
UAbilitySystemComponent* OwnerASC = GetAbilitySystemComponentFromActorInfo();
if (!ensure(IsValid(OwnerASC)))
{
UE_LOG(
LogGameplayAbility,
Error,
TEXT("%s: [Key: %d] RestartAbility called on GA with an invalid ASC."),
*GetFullNameSafe(this),
ActivationInfo.GetActivationPredictionKey().Current
);
return;
}
if (!CanRestartAbility(Handle, ActorInfo, ActivationInfo))
{
UE_LOG(
LogGameplayAbility,
VeryVerbose,
TEXT("%s: [Key: %d] RestartAbility got called on an ability that failed CanRestart check."),
*GetFullNameSafe(this),
ActivationInfo.GetActivationPredictionKey().Current
);
return;
}
const FGameplayAbilitySpec* CurrentAbilitySpec = GetCurrentAbilitySpec();
const FGameplayAbilitySpecHandle AbilitySpecHandle = CurrentAbilitySpec ?
CurrentAbilitySpec->Handle :
FGameplayAbilitySpecHandle();
if (!ensure(AbilitySpecHandle.IsValid()))
{
UE_LOG(
LogGameplayAbility,
Error,
TEXT("%s: [Key: %d] RestartAbility called on GA with an invalid AbilitySpecHandle."),
*GetFullNameSafe(this),
ActivationInfo.GetActivationPredictionKey().Current
);
return;
}
UE_LOG(
LogGameplayAbility,
Verbose,
TEXT("%s: [Key: %d] RestartAbility succssfully called on ASC with OwnerActor: %s"),
*GetFullNameSafe(this),
ActivationInfo.GetActivationPredictionKey().Current,
*GetNameSafe(GetASCOwnerActor(ActorInfo))
);
if (bCancelAbility) { CancelAbility(Handle, ActorInfo, ActivationInfo, bReplicateRestartAbility); }
else { EndAbility(Handle, ActorInfo, ActivationInfo, bReplicateRestartAbility, false); }
OwnerASC->TryActivateAbility(AbilitySpecHandle, bAllowRemoteActivation);
}
void UDandelionGameplayAbility::K2_RestartAbility(
const bool bReplicateRestartAbility,
const bool bCancelAbility,
const bool bAllowRemoteActivation
)
{
check(CurrentActorInfo);
RestartAbility(
CurrentSpecHandle,
CurrentActorInfo,
CurrentActivationInfo,
bReplicateRestartAbility,
bCancelAbility,
bAllowRemoteActivation
);
}
bool UDandelionGameplayAbility::CanRestartAbility(
const FGameplayAbilitySpecHandle Handle,
const FGameplayAbilityActorInfo* ActorInfo,
const FGameplayAbilityActivationInfo& ActivationInfo
) { return IsActive() && CanActivateAbility(Handle, ActorInfo) && CommitCheck(Handle, ActorInfo, ActivationInfo); }
void UDandelionGameplayAbility::OnGiveAbility(
const FGameplayAbilityActorInfo* ActorInfo,
const FGameplayAbilitySpec& Spec
)
{
UE_LOG(
LogGameplayAbility,
Verbose,
TEXT("%s: OnGiveAbility called on ASC with OwnerActor: %s"),
*GetFullNameSafe(this),
*GetNameSafe(GetASCOwnerActor(ActorInfo))
);
Super::OnGiveAbility(ActorInfo, Spec);
}
void UDandelionGameplayAbility::ActivateAbility(
const FGameplayAbilitySpecHandle Handle,
const FGameplayAbilityActorInfo* ActorInfo,
const FGameplayAbilityActivationInfo ActivationInfo,
const FGameplayEventData* TriggerEventData
)
{
UE_LOG(
LogGameplayAbility,
Verbose,
TEXT("%s: [Key: %d] ActivateAbility called on ASC with OwnerActor: %s"),
*GetFullNameSafe(this),
ActivationInfo.GetActivationPredictionKey().Current,
*GetNameSafe(GetASCOwnerActor(ActorInfo))
);
Super::ActivateAbility(Handle, ActorInfo, ActivationInfo, TriggerEventData);
}
bool UDandelionGameplayAbility::CommitAbility(
const FGameplayAbilitySpecHandle Handle,
const FGameplayAbilityActorInfo* ActorInfo,
const FGameplayAbilityActivationInfo ActivationInfo,
FGameplayTagContainer* OptionalRelevantTags
)
{
const bool Result = Super::CommitAbility(Handle, ActorInfo, ActivationInfo, OptionalRelevantTags);
UE_LOG(
LogGameplayAbility,
Verbose,
TEXT("%s: [Key: %d] CommitAbility %s on ASC with OwnerActor: %s"),
*GetFullNameSafe(this),
ActivationInfo.GetActivationPredictionKey().Current,
*FString(Result ? "succeeded" : "failed"),
*GetNameSafe(GetASCOwnerActor(ActorInfo))
);
return Result;
}
void UDandelionGameplayAbility::EndAbility(
const FGameplayAbilitySpecHandle Handle,
const FGameplayAbilityActorInfo* ActorInfo,
const FGameplayAbilityActivationInfo ActivationInfo,
const bool bReplicateEndAbility,
const bool bWasCancelled
)
{
// No need for a second log line since this will get called right after CancelAbility.
if (!bWasCancelled)
{
UE_LOG(
LogGameplayAbility,
Verbose,
TEXT("%s: [Key: %d] EndAbility called on ASC with OwnerActor: %s"),
*GetFullNameSafe(this),
ActivationInfo.GetActivationPredictionKey().Current,
*GetNameSafe(GetASCOwnerActor(ActorInfo))
);
}
Super::EndAbility(Handle, ActorInfo, ActivationInfo, bReplicateEndAbility, bWasCancelled);
}
void UDandelionGameplayAbility::CancelAbility(
const FGameplayAbilitySpecHandle Handle,
const FGameplayAbilityActorInfo* ActorInfo,
const FGameplayAbilityActivationInfo ActivationInfo,
const bool bReplicateCancelAbility
)
{
UE_LOG(
LogGameplayAbility,
Verbose,
TEXT("%s: [Key: %d] CancelAbility called on ASC with OwnerActor: %s"),
*GetFullNameSafe(this),
ActivationInfo.GetActivationPredictionKey().Current,
*GetNameSafe(GetASCOwnerActor(ActorInfo))
);
Super::CancelAbility(Handle, ActorInfo, ActivationInfo, bReplicateCancelAbility);
}
DandelionGameplayAbility.cpp - Snippet hosted by \"Cacher\"
");