2022-05-23 18:41:30 +00:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-09-13 07:18:28 +00:00
|
|
|
#include "Abilities/LyraGameplayAbility.h"
|
2022-05-23 18:41:30 +00:00
|
|
|
#include "AbilitySystemComponent.h"
|
2022-09-13 07:18:28 +00:00
|
|
|
#include "Containers/Array.h"
|
|
|
|
#include "Engine/EngineTypes.h"
|
|
|
|
#include "GameplayAbilitySpec.h"
|
|
|
|
#include "GameplayTagContainer.h"
|
|
|
|
#include "HAL/Platform.h"
|
2022-05-23 18:41:30 +00:00
|
|
|
#include "NativeGameplayTags.h"
|
2022-09-13 07:18:28 +00:00
|
|
|
#include "Templates/Function.h"
|
|
|
|
#include "UObject/UObjectGlobals.h"
|
2022-05-23 18:41:30 +00:00
|
|
|
|
2022-09-13 07:18:28 +00:00
|
|
|
#include "LyraAbilitySystemComponent.generated.h"
|
2022-05-23 18:41:30 +00:00
|
|
|
|
2022-09-13 07:18:28 +00:00
|
|
|
class AActor;
|
|
|
|
class UGameplayAbility;
|
2022-05-23 18:41:30 +00:00
|
|
|
class ULyraAbilityTagRelationshipMapping;
|
2022-09-13 07:18:28 +00:00
|
|
|
class UObject;
|
|
|
|
struct FFrame;
|
|
|
|
struct FGameplayAbilityTargetDataHandle;
|
2022-05-23 18:41:30 +00:00
|
|
|
|
|
|
|
LYRAGAME_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(TAG_Gameplay_AbilityInputBlocked);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ULyraAbilitySystemComponent
|
|
|
|
*
|
|
|
|
* Base ability system component class used by this project.
|
|
|
|
*/
|
|
|
|
UCLASS()
|
2022-09-13 07:18:28 +00:00
|
|
|
class LYRAGAME_API ULyraAbilitySystemComponent : public UAbilitySystemComponent
|
2022-05-23 18:41:30 +00:00
|
|
|
{
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
ULyraAbilitySystemComponent(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
|
|
|
|
|
|
|
|
//~UActorComponent interface
|
|
|
|
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
|
|
|
|
//~End of UActorComponent interface
|
|
|
|
|
|
|
|
virtual void InitAbilityActorInfo(AActor* InOwnerActor, AActor* InAvatarActor) override;
|
|
|
|
|
|
|
|
typedef TFunctionRef<bool(const ULyraGameplayAbility* LyraAbility, FGameplayAbilitySpecHandle Handle)> TShouldCancelAbilityFunc;
|
|
|
|
void CancelAbilitiesByFunc(TShouldCancelAbilityFunc ShouldCancelFunc, bool bReplicateCancelAbility);
|
|
|
|
|
|
|
|
void CancelInputActivatedAbilities(bool bReplicateCancelAbility);
|
|
|
|
|
|
|
|
void AbilityInputTagPressed(const FGameplayTag& InputTag);
|
|
|
|
void AbilityInputTagReleased(const FGameplayTag& InputTag);
|
|
|
|
|
|
|
|
void ProcessAbilityInput(float DeltaTime, bool bGamePaused);
|
|
|
|
void ClearAbilityInput();
|
|
|
|
|
|
|
|
bool IsActivationGroupBlocked(ELyraAbilityActivationGroup Group) const;
|
|
|
|
void AddAbilityToActivationGroup(ELyraAbilityActivationGroup Group, ULyraGameplayAbility* LyraAbility);
|
|
|
|
void RemoveAbilityFromActivationGroup(ELyraAbilityActivationGroup Group, ULyraGameplayAbility* LyraAbility);
|
|
|
|
void CancelActivationGroupAbilities(ELyraAbilityActivationGroup Group, ULyraGameplayAbility* IgnoreLyraAbility, bool bReplicateCancelAbility);
|
|
|
|
|
|
|
|
// Uses a gameplay effect to add the specified dynamic granted tag.
|
|
|
|
void AddDynamicTagGameplayEffect(const FGameplayTag& Tag);
|
|
|
|
|
|
|
|
// Removes all active instances of the gameplay effect that was used to add the specified dynamic granted tag.
|
|
|
|
void RemoveDynamicTagGameplayEffect(const FGameplayTag& Tag);
|
|
|
|
|
|
|
|
/** Gets the ability target data associated with the given ability handle and activation info */
|
|
|
|
void GetAbilityTargetData(const FGameplayAbilitySpecHandle AbilityHandle, FGameplayAbilityActivationInfo ActivationInfo, FGameplayAbilityTargetDataHandle& OutTargetDataHandle);
|
|
|
|
|
|
|
|
/** Sets the current tag relationship mapping, if null it will clear it out */
|
|
|
|
void SetTagRelationshipMapping(ULyraAbilityTagRelationshipMapping* NewMapping);
|
|
|
|
|
|
|
|
/** Looks at ability tags and gathers additional required and blocking tags */
|
|
|
|
void GetAdditionalActivationTagRequirements(const FGameplayTagContainer& AbilityTags, FGameplayTagContainer& OutActivationRequired, FGameplayTagContainer& OutActivationBlocked) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void TryActivateAbilitiesOnSpawn();
|
|
|
|
|
|
|
|
virtual void AbilitySpecInputPressed(FGameplayAbilitySpec& Spec) override;
|
|
|
|
virtual void AbilitySpecInputReleased(FGameplayAbilitySpec& Spec) override;
|
|
|
|
|
|
|
|
virtual void NotifyAbilityActivated(const FGameplayAbilitySpecHandle Handle, UGameplayAbility* Ability) override;
|
|
|
|
virtual void NotifyAbilityFailed(const FGameplayAbilitySpecHandle Handle, UGameplayAbility* Ability, const FGameplayTagContainer& FailureReason) override;
|
|
|
|
virtual void NotifyAbilityEnded(FGameplayAbilitySpecHandle Handle, UGameplayAbility* Ability, bool bWasCancelled) override;
|
|
|
|
virtual void ApplyAbilityBlockAndCancelTags(const FGameplayTagContainer& AbilityTags, UGameplayAbility* RequestingAbility, bool bEnableBlockTags, const FGameplayTagContainer& BlockTags, bool bExecuteCancelTags, const FGameplayTagContainer& CancelTags) override;
|
|
|
|
virtual void HandleChangeAbilityCanBeCanceled(const FGameplayTagContainer& AbilityTags, UGameplayAbility* RequestingAbility, bool bCanBeCanceled) override;
|
|
|
|
|
|
|
|
/** Notify client that an ability failed to activate */
|
|
|
|
UFUNCTION(Client, Unreliable)
|
|
|
|
void ClientNotifyAbilityFailed(const UGameplayAbility* Ability, const FGameplayTagContainer& FailureReason);
|
|
|
|
|
|
|
|
void HandleAbilityFailed(const UGameplayAbility* Ability, const FGameplayTagContainer& FailureReason);
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// If set, this table is used to look up tag relationships for activate and cancel
|
|
|
|
UPROPERTY()
|
2022-09-13 07:18:28 +00:00
|
|
|
TObjectPtr<ULyraAbilityTagRelationshipMapping> TagRelationshipMapping;
|
2022-05-23 18:41:30 +00:00
|
|
|
|
|
|
|
// Handles to abilities that had their input pressed this frame.
|
|
|
|
TArray<FGameplayAbilitySpecHandle> InputPressedSpecHandles;
|
|
|
|
|
|
|
|
// Handles to abilities that had their input released this frame.
|
|
|
|
TArray<FGameplayAbilitySpecHandle> InputReleasedSpecHandles;
|
|
|
|
|
|
|
|
// Handles to abilities that have their input held.
|
|
|
|
TArray<FGameplayAbilitySpecHandle> InputHeldSpecHandles;
|
|
|
|
|
|
|
|
// Number of abilities running in each activation group.
|
|
|
|
int32 ActivationGroupCounts[(uint8)ELyraAbilityActivationGroup::MAX];
|
|
|
|
};
|