2025-01-04 16:41:49 +00:00
|
|
|
|
// © 2024 Long Ly. All rights reserved. Any unauthorized use, reproduction, or distribution of this trademark is strictly prohibited and may result in legal action.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "CoreMinimal.h"
|
|
|
|
|
#include "AbilitySystemComponent.h"
|
2025-01-16 23:04:14 +00:00
|
|
|
|
#include "NativeGameplayTags.h"
|
2025-01-20 18:59:57 +00:00
|
|
|
|
#include "Abilities/OLSGameplayAbility.h"
|
2025-01-04 16:41:49 +00:00
|
|
|
|
#include "OLSAbilitySystemComponent.generated.h"
|
|
|
|
|
|
2025-01-16 19:05:19 +00:00
|
|
|
|
DECLARE_LOG_CATEGORY_EXTERN(LogOLSAbilitySystemComponent, Verbose, All);
|
|
|
|
|
|
2025-01-16 23:04:14 +00:00
|
|
|
|
OLS_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(TAG_Gameplay_AbilityInputBlocked);
|
|
|
|
|
|
2025-01-04 16:41:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* CVAR to control the "Play Montage" flow.
|
|
|
|
|
* Example: OLS.EnableDefaultPlayMontage true
|
|
|
|
|
*/
|
|
|
|
|
static bool GEnableDefaultPlayMontage = false;
|
|
|
|
|
static FAutoConsoleVariableRef CVarEnableDefaultPlayMontage(
|
|
|
|
|
TEXT("OLS.EnableDefaultPlayMontage"),
|
|
|
|
|
GEnableDefaultPlayMontage,
|
|
|
|
|
TEXT("Enables or disables the PlayMontage default behavior."),
|
|
|
|
|
ECVF_Default
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
UCLASS(ClassGroup=(OLS), meta=(BlueprintSpawnableComponent))
|
|
|
|
|
class OLS_API UOLSAbilitySystemComponent : public UAbilitySystemComponent
|
|
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
// Sets default values for this component's properties
|
|
|
|
|
UOLSAbilitySystemComponent();
|
|
|
|
|
|
|
|
|
|
// -- Begin Ability System Component implementation
|
|
|
|
|
virtual void InitAbilityActorInfo(
|
|
|
|
|
AActor* ownerActor,
|
|
|
|
|
AActor* avatarActor) override;
|
|
|
|
|
virtual bool ShouldDoServerAbilityRPCBatch() const override;
|
|
|
|
|
virtual float PlayMontage(
|
|
|
|
|
UGameplayAbility* animatingAbility,
|
|
|
|
|
FGameplayAbilityActivationInfo activationInfo,
|
|
|
|
|
UAnimMontage* montage,
|
|
|
|
|
float playRate,
|
|
|
|
|
FName startSectionName,
|
|
|
|
|
float startTimeSeconds) override;
|
|
|
|
|
// -- End Ability System Component implementation
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Obtains the Anim Instance from the Actor Info.
|
|
|
|
|
*
|
|
|
|
|
* Takes into consideration the pointer in the Actor Info, before calling the
|
|
|
|
|
* Getter function that will always attempt to retrieve it from the mesh.
|
|
|
|
|
*/
|
|
|
|
|
UFUNCTION(BlueprintPure, Category = "OLS Ability System")
|
|
|
|
|
virtual UAnimInstance* GetAnimInstanceFromActorInfo() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Grants a new effect to the owner.
|
|
|
|
|
*
|
|
|
|
|
* @param effectClass Effect class being granted to the owner.
|
|
|
|
|
* @param level Initial level for the effect.
|
|
|
|
|
* @return The handle that can be used for maintenance.
|
|
|
|
|
*/
|
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "OLS Ability System")
|
|
|
|
|
FActiveGameplayEffectHandle ApplyGameplayEffectClassToSelf(
|
|
|
|
|
TSubclassOf<UGameplayEffect> effectClass,
|
|
|
|
|
float level = 1);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Grants a new ability to the owner.
|
|
|
|
|
*
|
|
|
|
|
* @param abilityClass Ability class being granted to the owner.
|
|
|
|
|
* @param level Initial level for the ability.
|
|
|
|
|
* @param input An Input ID for the old input system.
|
|
|
|
|
* @return The handle that can be used for activation.
|
|
|
|
|
*/
|
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "OLS Ability System")
|
|
|
|
|
FGameplayAbilitySpecHandle GiveAbilityFromClass(
|
|
|
|
|
const TSubclassOf<UGameplayAbility> abilityClass,
|
|
|
|
|
int32 level = 1,
|
|
|
|
|
int32 input = -1);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tries to activate the ability by the handle, aggregating all RPCs that happened in the same frame.
|
|
|
|
|
*
|
|
|
|
|
* @param abilityHandle
|
|
|
|
|
* Handle used to identify the ability.
|
|
|
|
|
*
|
|
|
|
|
* @param shouldEndAbilityImmediately
|
|
|
|
|
* Determines if the EndAbility is triggered right away or later, with its own RPC. This requires the Ability
|
|
|
|
|
* to either implement IBatchGameplayAbilityInterface or be a subclass of NinjaGASGameplayAbility.
|
|
|
|
|
*/
|
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "OLS Ability System")
|
|
|
|
|
virtual bool TryBatchActivateAbility(
|
|
|
|
|
FGameplayAbilitySpecHandle abilityHandle,
|
|
|
|
|
bool shouldEndAbilityImmediately);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cancels Gameplay Abilities by their matching tags.
|
|
|
|
|
*
|
|
|
|
|
* @param abilityTags Gameplay Tags used to target abilities to cancel.
|
|
|
|
|
* @param cancelFilterTags A filter that excludes an ability from being cancelled.
|
|
|
|
|
*/
|
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "OLS Ability System")
|
|
|
|
|
virtual void CancelAbilitiesByTags(
|
|
|
|
|
FGameplayTagContainer abilityTags,
|
|
|
|
|
FGameplayTagContainer cancelFilterTags);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Locally executes a <b>Static<b> Gameplay Cue.
|
|
|
|
|
*
|
|
|
|
|
* @param gameplayCueTag Gameplay Tag for the Gameplay Cue.
|
|
|
|
|
* @param gameplayCueParameters Parameters for the Gameplay Cue.
|
|
|
|
|
*/
|
|
|
|
|
UFUNCTION(BlueprintCallable, BlueprintCosmetic, Category = "OLS Ability System", meta = (AutoCreateRefTerm = "GameplayCueParameters", GameplayTagFilter = "GameplayCue"))
|
|
|
|
|
void ExecuteGameplayCueLocal(
|
|
|
|
|
const FGameplayTag gameplayCueTag,
|
|
|
|
|
const FGameplayCueParameters& gameplayCueParameters) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Locally adds an <b>Actor<b> Gameplay Cue.
|
|
|
|
|
*
|
|
|
|
|
* When adding this Gameplay Cue locally, make sure to also remove it locally.
|
|
|
|
|
*
|
|
|
|
|
* @param gameplayCueTag Gameplay Tag for the Gameplay Cue.
|
|
|
|
|
* @param gameplayCueParameters Parameters for the Gameplay Cue.
|
|
|
|
|
*/
|
|
|
|
|
UFUNCTION(BlueprintCallable, BlueprintCosmetic, Category = "OLS Ability System", meta = (AutoCreateRefTerm = "GameplayCueParameters"))
|
|
|
|
|
void AddGameplayCueLocally(
|
|
|
|
|
UPARAM(meta = (Categories = "GameplayCue")) const FGameplayTag gameplayCueTag,
|
|
|
|
|
const FGameplayCueParameters& gameplayCueParameters) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Locally removes an <b>Actor<b> Gameplay Cue.
|
|
|
|
|
*
|
|
|
|
|
* @param gameplayCueTag Gameplay Tag for the Gameplay Cue.
|
|
|
|
|
* @param gameplayCueParameters Parameters for the Gameplay Cue.
|
|
|
|
|
*/
|
|
|
|
|
UFUNCTION(BlueprintCallable, BlueprintCosmetic, Category = "OLS Ability System", meta = (AutoCreateRefTerm = "GameplayCueParameters"))
|
|
|
|
|
void RemoveGameplayCueLocally(
|
|
|
|
|
UPARAM(meta = (Categories = "GameplayCue")) const FGameplayTag gameplayCueTag,
|
|
|
|
|
const FGameplayCueParameters& gameplayCueParameters) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Attempts to activate any abilities that are set to automatically trigger upon the actor's spawn.
|
|
|
|
|
* Typically used for gameplay abilities that need to be initialized or activated as soon as the actor is created.
|
|
|
|
|
*/
|
|
|
|
|
void TryActivateAbilitiesOnSpawn();
|
2025-01-16 23:04:14 +00:00
|
|
|
|
|
|
|
|
|
virtual void AbilitySpecInputPressed(FGameplayAbilitySpec& spec) override;
|
|
|
|
|
virtual void AbilitySpecInputReleased(FGameplayAbilitySpec& spec) override;
|
|
|
|
|
|
2025-01-20 18:59:57 +00:00
|
|
|
|
virtual void NotifyAbilityActivated(const FGameplayAbilitySpecHandle handle, class UGameplayAbility* ability) override;
|
|
|
|
|
virtual void NotifyAbilityFailed(const FGameplayAbilitySpecHandle handle, class UGameplayAbility* ability, const FGameplayTagContainer& failureReason) override;
|
2025-01-20 21:08:07 +00:00
|
|
|
|
virtual void NotifyAbilityEnded(FGameplayAbilitySpecHandle handle, class UGameplayAbility* ability, bool bWasCancelled) override;
|
2025-01-20 18:59:57 +00:00
|
|
|
|
virtual void ApplyAbilityBlockAndCancelTags(const FGameplayTagContainer& abilityTags, class UGameplayAbility* requestingAbility, bool shouldEnableBlockTags, const FGameplayTagContainer& blockTags, bool shouldExecuteCancelTags, const FGameplayTagContainer& cancelTags) override;
|
|
|
|
|
virtual void HandleChangeAbilityCanBeCanceled(const FGameplayTagContainer& abilityTags, class UGameplayAbility* requestingAbility, bool canBeCanceled) override;
|
2025-01-16 23:04:14 +00:00
|
|
|
|
|
|
|
|
|
/** Notify client that an ability failed to activate */
|
|
|
|
|
UFUNCTION(Client, Unreliable)
|
2025-01-20 18:59:57 +00:00
|
|
|
|
void ClientNotifyAbilityFailed(const class UGameplayAbility* ability, const FGameplayTagContainer& failureReason);
|
2025-01-16 23:04:14 +00:00
|
|
|
|
|
2025-01-20 18:59:57 +00:00
|
|
|
|
void HandleAbilityFailed(const class UGameplayAbility* ability, const FGameplayTagContainer& failureReason);
|
2025-01-04 16:41:49 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Conveniently separates the code that sets the animation to replicate, so it can be further modified.
|
|
|
|
|
*/
|
|
|
|
|
virtual void SetReplicatedMontageInfo(FGameplayAbilityRepAnimMontage& mutableRepAnimMontageInfo, UAnimMontage* newMontageToPlay, const FName& startSectionName);
|
|
|
|
|
|
2025-01-16 23:04:14 +00:00
|
|
|
|
public:
|
|
|
|
|
|
2025-01-20 18:59:57 +00:00
|
|
|
|
typedef TFunctionRef<bool(const UOLSGameplayAbility* ability, FGameplayAbilitySpecHandle handle)> TShouldCancelAbilityFunc;
|
2025-01-16 23:04:14 +00:00
|
|
|
|
void CancelAbilitiesByFunc(TShouldCancelAbilityFunc shouldCancelFunc, bool shouldReplicateCancelAbility);
|
|
|
|
|
|
|
|
|
|
void CancelInputActivatedAbilities(bool shouldReplicateCancelAbility);
|
|
|
|
|
|
|
|
|
|
void AbilityInputTagPressed(const FGameplayTag& inputTag);
|
|
|
|
|
void AbilityInputTagReleased(const FGameplayTag& inputTag);
|
|
|
|
|
|
|
|
|
|
void ProcessAbilityInput(float deltaTime, bool shouldGamePaused);
|
|
|
|
|
void ClearAbilityInput();
|
|
|
|
|
|
2025-01-20 18:59:57 +00:00
|
|
|
|
bool IsActivationGroupBlocked(EOLSAbilityActivationGroup Group) const;
|
|
|
|
|
void AddAbilityToActivationGroup(EOLSAbilityActivationGroup group, UOLSGameplayAbility* ability);
|
|
|
|
|
void RemoveAbilityFromActivationGroup(EOLSAbilityActivationGroup group, UOLSGameplayAbility* ability);
|
|
|
|
|
void CancelActivationGroupAbilities(EOLSAbilityActivationGroup group, UOLSGameplayAbility* ignoreAbility, bool shouldReplicateCancelAbility);
|
2025-01-16 23:04:14 +00:00
|
|
|
|
|
|
|
|
|
// 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(class UOLSAbilityTagRelationshipMappingDataAsset* newMapping);
|
|
|
|
|
|
|
|
|
|
/** Looks at ability tags and gathers additional required and blocking tags */
|
|
|
|
|
void GetAdditionalActivationTagRequirements(const FGameplayTagContainer& abilityTags, FGameplayTagContainer& outActivationRequired, FGameplayTagContainer& outActivationBlocked) const;
|
|
|
|
|
|
2025-01-04 16:41:49 +00:00
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "OLS Ability System", DisplayName = "Enable Ability Batch RPCs", meta = (AllowPrivateAccess = true))
|
|
|
|
|
uint8 bShouldEnableBatchRPC : 1 = true;
|
2025-01-16 23:04:14 +00:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
// If set, this table is used to look up tag relationships for activate and cancel
|
|
|
|
|
UPROPERTY()
|
|
|
|
|
TObjectPtr<class UOLSAbilityTagRelationshipMappingDataAsset> TagRelationshipMapping = nullptr;
|
|
|
|
|
|
|
|
|
|
// 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;
|
2025-01-20 18:59:57 +00:00
|
|
|
|
|
|
|
|
|
// Number of abilities running in each activation group.
|
|
|
|
|
int32 ActivationGroupCounts[(uint8)EOLSAbilityActivationGroup::MAX];
|
2025-01-04 16:41:49 +00:00
|
|
|
|
};
|