RealtimeStyleTransferRuntime/Source/LyraGame/AbilitySystem/Abilities/LyraGameplayAbility_Reset.cpp

76 lines
3.0 KiB
C++
Raw Permalink Normal View History

2022-05-23 18:41:30 +00:00
// Copyright Epic Games, Inc. All Rights Reserved.
#include "AbilitySystem/Abilities/LyraGameplayAbility_Reset.h"
2022-09-13 07:18:28 +00:00
#include "Abilities/GameplayAbility.h"
#include "Abilities/GameplayAbilityTypes.h"
2022-05-23 18:41:30 +00:00
#include "AbilitySystem/LyraAbilitySystemComponent.h"
2022-09-13 07:18:28 +00:00
#include "AbilitySystemComponent.h"
2022-05-23 18:41:30 +00:00
#include "Character/LyraCharacter.h"
2022-09-13 07:18:28 +00:00
#include "Containers/Array.h"
#include "Containers/EnumAsByte.h"
#include "Delegates/Delegate.h"
#include "GameFramework/Actor.h"
#include "GameFramework/GameplayMessageSubsystem.h"
#include "GameplayTagContainer.h"
#include "GameplayTagsManager.h"
#include "LyraGameplayTags.h"
#include "Misc/AssertionMacros.h"
#include "Templates/Casts.h"
#include "UObject/WeakObjectPtr.h"
#include "UObject/WeakObjectPtrTemplates.h"
2022-05-23 18:41:30 +00:00
ULyraGameplayAbility_Reset::ULyraGameplayAbility_Reset(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
InstancingPolicy = EGameplayAbilityInstancingPolicy::InstancedPerActor;
NetExecutionPolicy = EGameplayAbilityNetExecutionPolicy::ServerInitiated;
UGameplayTagsManager::Get().CallOrRegister_OnDoneAddingNativeTagsDelegate(FSimpleDelegate::CreateUObject(this, &ThisClass::DoneAddingNativeTags));
}
void ULyraGameplayAbility_Reset::DoneAddingNativeTags()
{
if (HasAnyFlags(RF_ClassDefaultObject))
{
// Add the ability trigger tag as default to the CDO.
FAbilityTriggerData TriggerData;
TriggerData.TriggerTag = FLyraGameplayTags::Get().GameplayEvent_RequestReset;
TriggerData.TriggerSource = EGameplayAbilityTriggerSource::GameplayEvent;
AbilityTriggers.Add(TriggerData);
}
}
void ULyraGameplayAbility_Reset::ActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEventData* TriggerEventData)
{
check(ActorInfo);
ULyraAbilitySystemComponent* LyraASC = CastChecked<ULyraAbilitySystemComponent>(ActorInfo->AbilitySystemComponent.Get());
FGameplayTagContainer AbilityTypesToIgnore;
AbilityTypesToIgnore.AddTag(FLyraGameplayTags::Get().Ability_Behavior_SurvivesDeath);
// Cancel all abilities and block others from starting.
LyraASC->CancelAbilities(nullptr, &AbilityTypesToIgnore, this);
SetCanBeCanceled(false);
// Execute the reset from the character
if (ALyraCharacter* LyraChar = Cast<ALyraCharacter>(CurrentActorInfo->AvatarActor.Get()))
{
LyraChar->Reset();
}
// Let others know a reset has occurred
FLyraPlayerResetMessage Message;
Message.OwnerPlayerState = CurrentActorInfo->OwnerActor.Get();
UGameplayMessageSubsystem& MessageSystem = UGameplayMessageSubsystem::Get(this);
MessageSystem.BroadcastMessage(FLyraGameplayTags::Get().GameplayEvent_Reset, Message);
Super::ActivateAbility(Handle, ActorInfo, ActivationInfo, TriggerEventData);
const bool bReplicateEndAbility = true;
const bool bWasCanceled = false;
EndAbility(CurrentSpecHandle, CurrentActorInfo, CurrentActivationInfo, bReplicateEndAbility, bWasCanceled);
}