第一次提交

This commit is contained in:
不明不惑
2026-03-03 01:23:02 +08:00
commit 3e434877e8
1053 changed files with 102411 additions and 0 deletions

View File

@@ -0,0 +1,540 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "AbilitySystemComponent.h"
#include "GameplayEffectExecutionCalculation.h"
#include "GGA_AbilitySystemComponent.h"
#include "Abilities/GameplayAbilityTypes.h"
#include "GGA_AbilitySystemFunctionLibrary.generated.h"
/**
* Blueprint function library for ability system operations.
* 用于技能系统操作的蓝图函数库。
* @details Provides utility functions for managing ability system components, abilities, and attributes.
* @细节 提供管理技能系统组件、技能和属性的实用函数。
*/
UCLASS()
class GENERICGAMEPLAYABILITIES_API UGGA_AbilitySystemFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
#pragma region AbilitySystem
/**
* Finds an ability system component on an actor.
* 在演员上查找技能系统组件。
* @param Actor The actor to search. 要搜索的演员。
* @param DesiredClass The desired class of the component. 所需的组件类。
* @param ASC The found ability system component (output). 找到的技能系统组件(输出)。
* @return True if the component was found, false otherwise. 如果找到组件则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem",
meta=(DisplayName="Find Typed Ability System Component", DefaultToSelf="Actor", DynamicOutputParam="ASC", DeterminesOutputType="DesiredClass", ExpandBoolAsExecs="ReturnValue"))
static bool FindAbilitySystemComponent(AActor* Actor, TSubclassOf<UAbilitySystemComponent> DesiredClass, UAbilitySystemComponent*& ASC);
/**
* Retrieves an ability system component from an actor.
* 从演员获取技能系统组件。
* @param Actor The actor to search. 要搜索的演员。
* @param DesiredClass The desired class of the component. 所需的组件类。
* @return The found ability system component, or nullptr if not found. 找到的技能系统组件未找到时为nullptr。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem",
meta=(DisplayName="Get Typed Ability System Component", DefaultToSelf="Actor", DynamicOutputParam="ReturnValue", DeterminesOutputType="DesiredClass"))
static UAbilitySystemComponent* GetAbilitySystemComponent(AActor* Actor, TSubclassOf<UAbilitySystemComponent> DesiredClass);
/**
* Initializes the actor info for an ability system component.
* 初始化技能系统组件的Actor信息。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param InOwnerActor The owner actor. 拥有者演员。
* @param InAvatarActor The avatar actor. 化身演员。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static void InitAbilityActorInfo(UAbilitySystemComponent* AbilitySystem, AActor* InOwnerActor, AActor* InAvatarActor);
/**
* Retrieves the owner actor of an ability system component.
* 获取技能系统组件的拥有者演员。
* @param AbilitySystem The ability system component. 技能系统组件。
* @return The owner actor. 拥有者演员。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem")
static AActor* GetOwnerActor(UAbilitySystemComponent* AbilitySystem);
/**
* Retrieves the avatar actor of an ability system component.
* 获取技能系统组件的化身演员。
* @param AbilitySystem The ability system component. 技能系统组件。
* @return The avatar actor. 化身演员。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem")
static AActor* GetAvatarActor(UAbilitySystemComponent* AbilitySystem);
/**
* Handles a gameplay event on an ability system component.
* 在技能系统组件上处理游戏事件。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param EventTag The event tag. 事件标签。
* @param Payload The event data payload. 事件数据负载。
* @return The number of successful ability activations. 成功激活的技能数量。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static int32 HandleGameplayEvent(UAbilitySystemComponent* AbilitySystem, FGameplayTag EventTag, const FGameplayEventData& Payload);
/**
* Attempts to activate abilities one by one.
* 尝试逐一激活技能。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param AbilitiesToActivate Array of abilities to activate. 要激活的技能数组。
* @param bAllowRemoteActivation Whether to allow remote activation. 是否允许远程激活。
* @param bFirstOnly Whether to stop after the first successful activation. 是否在第一次成功激活后停止。
* @return True if at least one ability was activated, false otherwise. 如果至少激活一个技能则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem", meta=(DisplayName="Try Activate Abilities(one by one)"))
static bool TryActivateAbilities(UAbilitySystemComponent* AbilitySystem, TArray<FGameplayAbilitySpecHandle> AbilitiesToActivate, bool bAllowRemoteActivation = true, bool bFirstOnly = true);
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
bool HasActivatableTriggeredAbility(UAbilitySystemComponent* AbilitySystem, FGameplayTag Tag);
/**
* Retrieves activatable ability specs matching all tags.
* 获取与所有标签匹配的可激活技能规格。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param Tags The tags to match. 要匹配的标签。
* @param MatchingGameplayAbilities Array to store matching ability specs (output). 存储匹配技能规格的数组(输出)。
* @param bOnlyAbilitiesThatSatisfyTagRequirements Whether to include only abilities satisfying tag requirements. 是否仅包括满足标签要求的技能。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static void GetActivatableGameplayAbilitySpecsByAllMatchingTags(const UAbilitySystemComponent* AbilitySystem, const FGameplayTagContainer& Tags,
TArray<FGameplayAbilitySpecHandle>& MatchingGameplayAbilities, bool bOnlyAbilitiesThatSatisfyTagRequirements = true);
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static void GetActivatableGameplayAbilitySpecs(const UAbilitySystemComponent* AbilitySystem, const FGameplayTagContainer& Tags, const UObject* SourceObject,
TArray<FGameplayAbilitySpecHandle>& MatchingGameplayAbilities, bool bOnlyAbilitiesThatSatisfyTagRequirements = true);
/**
* Retrieves the first activatable ability matching all tags.
* 获取与所有标签匹配的第一个可激活技能。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param Tags The tags to match. 要匹配的标签。
* @param MatchingGameplayAbility The matching ability spec handle (output). 匹配的技能句柄(输出)。
* @param bOnlyAbilitiesThatSatisfyTagRequirements Whether to include only abilities satisfying tag requirements. 是否仅包括满足标签要求的技能。
* @return True if a matching ability was found, false otherwise. 如果找到匹配技能则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure=false, Category = "GGA|AbilitySystem", meta=(ExpandBoolAsExecs="ReturnValue"))
static bool GetFirstActivatableAbilityByAllMatchingTags(const UAbilitySystemComponent* AbilitySystem, FGameplayTagContainer Tags, FGameplayAbilitySpecHandle& MatchingGameplayAbility,
bool bOnlyAbilitiesThatSatisfyTagRequirements = true);
UFUNCTION(BlueprintCallable, BlueprintPure=false, Category = "GGA|AbilitySystem", meta=(ExpandBoolAsExecs="ReturnValue"))
static bool GetFirstActivatableAbility(const UAbilitySystemComponent* AbilitySystem, FGameplayTagContainer Tags, FGameplayAbilitySpecHandle& MatchingGameplayAbility, const UObject* SourceObject,
bool bOnlyAbilitiesThatSatisfyTagRequirements = true);
/**
* Retrieves active ability instances matching the specified tags.
* 获取与指定标签匹配的激活技能实例。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param Tags The tags to match. 要匹配的标签。
* @param MatchingAbilityInstances Array to store matching ability instances. 存储匹配技能实例的数组。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static void GetActiveAbilityInstancesWithTags(const UAbilitySystemComponent* AbilitySystem, const FGameplayTagContainer& Tags, TArray<UGameplayAbility*>& MatchingAbilityInstances);
/**
* Sends a gameplay event to an actor.
* 向演员发送游戏事件。
* @param Actor The actor to send the event to. 要发送事件的演员。
* @param EventTag The event tag. 事件标签。
* @param Payload The event data payload. 事件数据负载。
* @return True if any abilities were activated, false otherwise. 如果激活了任何技能则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem", Meta = (Tooltip = "This function can be used to trigger an ability on the actor in question with useful payload data."))
static bool SendGameplayEventToActor(AActor* Actor, FGameplayTag EventTag, FGameplayEventData Payload);
/**
* Breaks down ability ended data into its components.
* 将技能结束数据分解为其组件。
* @param AbilityEndedData The ability ended data. 技能结束数据。
* @param AbilityThatEnded The ability that ended (output). 结束的技能(输出)。
* @param AbilitySpecHandle The ability spec handle (output). 技能句柄(输出)。
* @param bReplicateEndAbility Whether to replicate the end ability (output). 是否复制结束技能(输出)。
* @param bWasCancelled Whether the ability was cancelled (output). 技能是否被取消(输出)。
*/
UFUNCTION(BlueprintPure, Category = "GGA|AbilitySystem")
static void BreakAbilityEndedData(const FAbilityEndedData& AbilityEndedData, UGameplayAbility*& AbilityThatEnded, FGameplayAbilitySpecHandle& AbilitySpecHandle, bool& bReplicateEndAbility,
bool& bWasCancelled);
/**
* Finds all abilities matching the provided tags in order.
* 按顺序查找与提供的标签匹配的所有技能。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param Tags The tags to match. 要匹配的标签。
* @param OutAbilityHandles Array to store matching ability handles (output). 存储匹配技能句柄的数组(输出)。
* @param bExactMatch Whether to require an exact tag match. 是否要求完全标签匹配。
* @return True if any abilities were found, false otherwise. 如果找到任何技能则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "GGA|AbilitySystem", meta=(ExpandBoolAsExecs="ReturnValue"))
static bool FindAllAbilitiesWithTagsInOrder(const UAbilitySystemComponent* AbilitySystem, TArray<FGameplayTag> Tags, TArray<FGameplayAbilitySpecHandle>& OutAbilityHandles,
bool bExactMatch = true);
/**
* Finds the first ability matching a gameplay tag query.
* 查找与游戏标签查询匹配的第一个技能。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param OutAbilityHandle The matching ability handle (output). 匹配的技能句柄(输出)。
* @param Query The gameplay tag query. 游戏标签查询。
* @param SourceObject Optional source object filter. 可选的源对象过滤只会返回源对象与之匹配的Ability
* @return True if a matching ability was found, false otherwise. 如果找到匹配技能则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "GGA|AbilitySystem", meta=(ExpandBoolAsExecs="ReturnValue"))
static bool FindAbilityMatchingQuery(const UAbilitySystemComponent* AbilitySystem, FGameplayAbilitySpecHandle& OutAbilityHandle, FGameplayTagQuery Query, const UObject* SourceObject = nullptr);
static FGameplayAbilitySpec* FindAbilitySpecFromClass(const UAbilitySystemComponent* AbilitySystem, TSubclassOf<UGameplayAbility> AbilityClass, const UObject* SourceObject = nullptr);
UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "GGA|AbilitySystem", meta=(ExpandBoolAsExecs="ReturnValue"))
static bool FindAbilityFromClass(const UAbilitySystemComponent* AbilitySystem, FGameplayAbilitySpecHandle& OutAbilityHandle, TSubclassOf<UGameplayAbility> AbilityClass,
const UObject* SourceObject = nullptr);
/**
* Finds the first ability matching the provided tags.
* 查找与提供的标签匹配的第一个技能。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param OutAbilityHandle The matching ability handle (output). 匹配的技能句柄(输出)。
* @param Tags The tags to match. 要匹配的标签。
* @param bExactMatch Whether to require an exact tag match. 是否要求完全标签匹配。
* @param SourceObject Optional source object filter. 可选的源对象过滤只会返回源对象与之匹配的Ability
* @return True if a matching ability was found, false otherwise. 如果找到匹配技能则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "GGA|AbilitySystem", meta=(ExpandBoolAsExecs="ReturnValue"))
static bool FindAbilityWithTags(const UAbilitySystemComponent* AbilitySystem, FGameplayAbilitySpecHandle& OutAbilityHandle, FGameplayTagContainer Tags, bool bExactMatch = true,
const UObject* SourceObject = nullptr);
/**
* Adds a non-replicated gameplay tag to an ability system component.
* 向技能系统组件添加非复制的游戏标签。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param GameplayTag The tag to add. 要添加的标签。
* @param Count The number of times to add the tag. 添加标签的次数。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static void AddLooseGameplayTag(UAbilitySystemComponent* AbilitySystem, const FGameplayTag& GameplayTag, int32 Count = 1);
/**
* Adds multiple non-replicated gameplay tags to an ability system component.
* 向技能系统组件添加多个非复制的游戏标签。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param GameplayTags The tags to add. 要添加的标签。
* @param Count The number of times to add the tags. 添加标签的次数。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static void AddLooseGameplayTags(UAbilitySystemComponent* AbilitySystem, const FGameplayTagContainer& GameplayTags, int32 Count = 1);
/**
* Removes a non-replicated gameplay tag from an ability system component.
* 从技能系统组件移除非复制的游戏标签。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param GameplayTag The tag to remove. 要移除的标签。
* @param Count The number of times to remove the tag. 移除标签的次数。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static void RemoveLooseGameplayTag(UAbilitySystemComponent* AbilitySystem, const FGameplayTag& GameplayTag, int32 Count = 1);
/**
* Removes multiple non-replicated gameplay tags from an ability system component.
* 从技能系统组件移除多个非复制的游戏标签。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param GameplayTags The tags to remove. 要移除的标签。
* @param Count The number of times to remove the tags. 移除标签的次数。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static void RemoveLooseGameplayTags(UAbilitySystemComponent* AbilitySystem, const FGameplayTagContainer& GameplayTags, int32 Count = 1);
/**
* Removes all gameplay cues from an ability system component.
* 从技能系统组件移除所有游戏反馈。
* @param AbilitySystem The ability system component. 技能系统组件。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static void RemoveAllGameplayCues(UAbilitySystemComponent* AbilitySystem);
#pragma endregion AbilitySystem
#pragma region AnimMontage Support
/** Plays a montage and handles replication and prediction based on passed in ability/activation info */
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static float PlayMontage(UAbilitySystemComponent* AbilitySystem, UGameplayAbility* AnimatingAbility, FGameplayAbilityActivationInfo ActivationInfo, UAnimMontage* Montage, float InPlayRate,
FName StartSectionName = NAME_None,
float StartTimeSeconds = 0.0f);
/** Stops whatever montage is currently playing. Expectation is caller should only be stopping it if they are the current animating ability (or have good reason not to check) */
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static void CurrentMontageStop(UAbilitySystemComponent* AbilitySystem, float OverrideBlendOutTime = -1.0f);
/** Stops current montage if it's the one given as the Montage param */
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static void StopMontageIfCurrent(UAbilitySystemComponent* AbilitySystem, const UAnimMontage* Montage, float OverrideBlendOutTime = -1.0f);
/** Clear the animating ability that is passed in, if it's still currently animating */
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static void ClearAnimatingAbility(UAbilitySystemComponent* AbilitySystem, UGameplayAbility* Ability);
/** Jumps current montage to given section. Expectation is caller should only be stopping it if they are the current animating ability (or have good reason not to check) */
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static void CurrentMontageJumpToSection(UAbilitySystemComponent* AbilitySystem, FName SectionName);
/** Sets current montages next section name. Expectation is caller should only be stopping it if they are the current animating ability (or have good reason not to check) */
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static void CurrentMontageSetNextSectionName(UAbilitySystemComponent* AbilitySystem, FName FromSectionName, FName ToSectionName);
/** Sets current montage's play rate */
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static void CurrentMontageSetPlayRate(UAbilitySystemComponent* AbilitySystem, float InPlayRate);
/**
* Checks if the specified ability is the current animating ability.
* 检查指定技能是否为当前播放动画的技能。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param Ability The ability to check. 要检查的技能。
* @return True if the ability is animating, false otherwise. 如果技能正在播放动画则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem")
static bool IsAnimatingAbility(UAbilitySystemComponent* AbilitySystem, UGameplayAbility* Ability);
/**
* Retrieves the ability instance playing the specified animation.
* 获取播放指定动画的技能实例。
* @param AbilitySystem The ability system component. 技能系统组件。
* @return The ability instance, or nullptr if not found. 技能实例未找到时为nullptr。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem")
static UGameplayAbility* GetAnimatingAbility(UAbilitySystemComponent* AbilitySystem);
/**
* Retrieves the ability instance playing the specified animation on an actor.
* 获取在演员上播放指定动画的技能实例。
* @param Actor The actor to search. 要搜索的演员。
* @param Animation The animation to check. 要检查的动画。
* @return The ability instance, or nullptr if not found. 技能实例未找到时为nullptr。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem", meta=(DefaultToSelf="Actor"))
static UGameplayAbility* GetAnimatingAbilityFromActor(AActor* Actor, UAnimSequenceBase* Animation);
/**
* Finds the ability instance playing the specified animation with a desired class.
* 查找播放指定动画且具有所需类的技能实例。
* @param Actor The actor to search. 要搜索的演员。
* @param Animation The animation to check. 要检查的动画。
* @param DesiredClass The desired ability class. 所需的技能类。
* @param AbilityInstance The found ability instance. 找到的技能实例。
* @return True if an ability was found, false otherwise. 如果找到技能则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem",
meta=(DefaultToSelf="Actor", DisplayName="Get Animating Ability from Actor", DeterminesOutputType=DesiredClass, DynamicOutputParam=AbilityInstance, ExpandBoolAsExecs=ReturnValue))
static bool FindAnimatingAbilityFromActor(AActor* Actor, UAnimSequenceBase* Animation, TSubclassOf<UGameplayAbility> DesiredClass, UGameplayAbility*& AbilityInstance);
/** Returns montage that is currently playing */
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem")
static UAnimMontage* GetCurrentMontage(UAbilitySystemComponent* AbilitySystem);
/** Get SectionID of currently playing AnimMontage */
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem")
static int32 GetCurrentMontageSectionID(UAbilitySystemComponent* AbilitySystem);
/** Get SectionName of currently playing AnimMontage */
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem")
static FName GetCurrentMontageSectionName(UAbilitySystemComponent* AbilitySystem);
/** Get length in time of current section */
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem")
static float GetCurrentMontageSectionLength(UAbilitySystemComponent* AbilitySystem);
/** Returns amount of time left in current section */
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem")
static float GetCurrentMontageSectionTimeLeft(UAbilitySystemComponent* AbilitySystem);
#pragma endregion
#pragma region Ability
/**
* Sets the input pressed state for an ability.
* 为技能设置输入按下状态。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param Ability The ability spec handle. 技能句柄。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static void SetAbilityInputPressed(UAbilitySystemComponent* AbilitySystem, FGameplayAbilitySpecHandle Ability);
/**
* Sets the input released state for an ability.
* 为技能设置输入释放状态。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param Ability The ability spec handle. 技能句柄。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static void SetAbilityInputReleased(UAbilitySystemComponent* AbilitySystem, FGameplayAbilitySpecHandle Ability);
/**
* Checks if an ability can be activated.
* 检查技能是否可以激活。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param AbilityToActivate The ability to activate. 要激活的技能。
* @param RelevantTags Tags relevant to the activation check (output). 与激活检查相关的标签(输出)。
* @return True if the ability can be activated, false otherwise. 如果技能可以激活则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure=false, Category = "GGA|AbilitySystem", meta=(ExpandBoolAsExecs="ReturnValue"))
static bool CanActivateAbility(const UAbilitySystemComponent* AbilitySystem, FGameplayAbilitySpecHandle AbilityToActivate, FGameplayTagContainer& RelevantTags);
/**
* Selects the first ability that can be activated from a list.
* 从列表中选择第一个可以激活的技能。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param Abilities Array of abilities to check. 要检查的技能数组。
* @param OutAbilityHandle The selected ability handle (output). 选中的技能句柄(输出)。
* @return True if an ability was selected, false otherwise. 如果选中技能则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem", meta=(ExpandBoolAsExecs="ReturnValue"))
static bool SelectFirstCanActivateAbility(const UAbilitySystemComponent* AbilitySystem, TArray<FGameplayAbilitySpecHandle> Abilities, FGameplayAbilitySpecHandle& OutAbilityHandle);
/**
* Cancels an ability.
* 取消一个技能。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param Ability The ability spec handle to cancel. 要取消的技能句柄。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static void CancelAbility(UAbilitySystemComponent* AbilitySystem, FGameplayAbilitySpecHandle Ability);
/**
* Cancels abilities based on tags.
* 根据标签取消技能。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param WithTags Tags to include for cancellation. 要包含的标签。
* @param WithoutTags Tags to exclude from cancellation. 要排除的标签。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|AbilitySystem")
static void CancelAbilities(UAbilitySystemComponent* AbilitySystem, FGameplayTagContainer WithTags, FGameplayTagContainer WithoutTags);
/**
* Checks if an ability's primary instance is active.
* 检查技能的主要实例是否激活。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param Ability The ability spec handle. 技能句柄。
* @return True if the ability instance is active, false otherwise. 如果技能实例激活则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem", meta=(DisplayName="Is Ability Primary Instance Active"))
static bool IsAbilityInstanceActive(const UAbilitySystemComponent* AbilitySystem, FGameplayAbilitySpecHandle Ability);
/**
* Retrieves all ability instances from ability spec, including replicated and non-replicated instances.
* 从技能规格获取所有技能实例(含复制的和未网络复制的)。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param Ability The ability spec handle. 技能句柄。
* @return Array of spec's replicated and non-replicated ability instances. 复制以及非复制技能实例的组合。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem")
static TArray<UGameplayAbility*> GetAbilityInstances(UAbilitySystemComponent* AbilitySystem, FGameplayAbilitySpecHandle Ability);
/**
* Retrieves the ability definition from ability spec.
* 从技能规格获取技能定义。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param Ability The ability spec handle. 技能句柄。
* @return The ability CDO. 技能CDO。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem")
static const UGameplayAbility* GetAbilityCDO(UAbilitySystemComponent* AbilitySystem, FGameplayAbilitySpecHandle Ability);
/**
* Retrieves the level from ability spec.
* 从技能规格获取技能的等级。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param Ability The ability spec handle. 技能句柄。
* @return The ability level. 技能等级。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem")
static int32 GetAbilityLevel(UAbilitySystemComponent* AbilitySystem, FGameplayAbilitySpecHandle Ability);
/**
* Retrieves the input ID from ability spec, if bound.
* 从技能规格获取技能的输入ID如果已绑定
* @param AbilitySystem The ability system component. 技能系统组件。
* @param Ability The ability spec handle. 技能句柄。
* @return The input ID. 输入ID。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem")
static int32 GetAbilityInputId(UAbilitySystemComponent* AbilitySystem, FGameplayAbilitySpecHandle Ability);
/**
* Retrieves the source object from ability spec.
* 从技能规格获取技能的源对象。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param Ability The ability spec handle. 技能句柄。
* @return The source object. 源对象。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem")
static UObject* GetAbilitySourceObject(UAbilitySystemComponent* AbilitySystem, FGameplayAbilitySpecHandle Ability);
/**
* Retrieves the dynamic tags from ability spec.
* 从技能规格获取技能的动态标签。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param Ability The ability spec handle. 技能句柄。
* @return The dynamic tag container. 动态标签容器。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem")
static FGameplayTagContainer GetAbilityDynamicTags(UAbilitySystemComponent* AbilitySystem, FGameplayAbilitySpecHandle Ability);
/**
* Retrieves the primary instance from ability spec.
* 从技能规格获取技能的主要实例。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param Ability The ability spec handle. 技能句柄。
* @return The primary ability instance. 主要技能实例。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem")
static UGameplayAbility* GetAbilityPrimaryInstance(UAbilitySystemComponent* AbilitySystem, FGameplayAbilitySpecHandle Ability);
/**
* Checks if an ability specs active count > 0.
* 检查技能规格的激活计数是否>0。
* @attention Only available on server side,The spec's active acount are not replicated! 仅在服务端有效实例的ActiveCount未网络同步。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param Ability The ability spec handle. 技能句柄。
* @return True if the ability is active, false otherwise. 如果技能激活则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem")
static bool IsAbilityActive(const UAbilitySystemComponent* AbilitySystem, FGameplayAbilitySpecHandle Ability);
#pragma endregion Ability
#pragma region AttributeSet
/**
* Finds an attribute set by class.
* 通过类查找属性集。
* @param AbilitySystem The ability system component. 技能系统组件。
* @param AttributeSetClass The attribute set class to find. 要查找的属性集类。
* @return The found attribute set, or nullptr if not found. 找到的属性集未找到时为nullptr。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|AbilitySystem")
static UAttributeSet* GetAttributeSetByClass(const UAbilitySystemComponent* AbilitySystem, const TSubclassOf<UAttributeSet> AttributeSetClass);
#pragma endregion
#pragma region ScalableFloat
/**
* Retrieves the value of a scalable float at a specific level.
* 获取特定级别下可扩展浮点数的值。
* @param ScalableFloat The scalable float. 可扩展浮点数。
* @param Level The level to evaluate. 要评估的级别。
* @param ContextString Context string for debugging. 用于调试的上下文字符串。
* @return The evaluated value. 评估值。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|Extensions|ScalableFloat")
static float GetValueAtLevel(const FScalableFloat& ScalableFloat, float Level, FString ContextString);
#pragma endregion
};

View File

@@ -0,0 +1,113 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameplayAbilitySpecHandle.h"
#include "GameplayTagContainer.h"
#include "Abilities/GameplayAbilityTypes.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "GGA_GameplayAbilityFunctionLibrary.generated.h"
class UGameplayAbility;
/**
* Blueprint function library for gameplay ability operations.
* 用于游戏技能操作的蓝图函数库。
*/
UCLASS()
class GENERICGAMEPLAYABILITIES_API UGGA_GameplayAbilityFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
/**
* Checks if an ability spec handle is valid.
* 检查技能规格句柄是否有效。
* @param Handle The ability spec handle. 技能规格句柄。
* @return True if the handle is valid, false otherwise. 如果句柄有效则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayAbility")
static bool IsAbilitySpecHandleValid(FGameplayAbilitySpecHandle Handle);
/**
* Retrieves the default object for an ability class.
* 获取技能类的默认对象。
* @param AbilityClass The ability class. 技能类。
* @return The default object for the ability class. 技能类的默认对象。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayAbility")
static const UGameplayAbility* GetAbilityCDOFromClass(TSubclassOf<UGameplayAbility> AbilityClass);
/**
* Retrieves the current ability spec handle.
* 获取当前技能规格句柄。
* @param Ability The gameplay ability. 游戏技能。
* @return The ability spec handle. 技能规格句柄。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category= "GGA|GameplayAbility", meta = (DefaultToSelf="Ability"))
static FGameplayAbilitySpecHandle GetCurrentAbilitySpecHandle(const UGameplayAbility* Ability);
/**
* Checks if an ability is currently active.
* 检查技能是否当前激活。
* @param Ability The gameplay ability. 游戏技能。
* @return True if the ability is active, false otherwise. 如果技能激活则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category= "GGA|GameplayAbility", meta = (DefaultToSelf="Ability"))
static bool IsAbilityActive(const UGameplayAbility* Ability);
/**
* Retrieves the replication policy for an ability.
* 获取技能的复制策略。
* @param Ability The gameplay ability. 游戏技能。
* @return The replication policy. 复制策略。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category= "GGA|GameplayAbility", meta = (DefaultToSelf="Ability"))
static EGameplayAbilityReplicationPolicy::Type GetReplicationPolicy(const UGameplayAbility* Ability);
/**
* Retrieves the instancing policy for an ability.
* 获取技能的实例化策略。
* @param Ability The gameplay ability. 游戏技能。
* @return The instancing policy. 实例化策略。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category= "GGA|GameplayAbility", meta = (DefaultToSelf="Ability"))
static EGameplayAbilityInstancingPolicy::Type GetInstancingPolicy(const UGameplayAbility* Ability);
/**
* Retrieves the tags associated with an ability.
* 获取与技能关联的标签。
* @param Ability The gameplay ability. 游戏技能。
* @return The gameplay tag container. 游戏标签容器。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayAbility", meta = (DefaultToSelf="Ability"))
static FGameplayTagContainer GetAbilityTags(const UGameplayAbility* Ability);
/**
* Checks if the ability is running on a predicting client.
* 检查技能是否在预测客户端上运行。
* @param Ability The gameplay ability. 游戏技能。
* @return True if running on a predicting client, false otherwise. 如果在预测客户端上运行则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayAbility", meta = (DefaultToSelf="Ability"))
static bool IsPredictingClient(const UGameplayAbility* Ability);
/**
* Checks if the ability is for a remote client.
* 检查技能是否用于远程客户端。
* @param Ability The gameplay ability. 游戏技能。
* @return True if for a remote client, false otherwise. 如果用于远程客户端则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayAbility", meta = (DefaultToSelf="Ability"))
static bool IsForRemoteClient(const UGameplayAbility* Ability);
/**
* Checks if the ability has authority or a valid prediction key.
* 检查技能是否具有权限或有效预测键。
* @param Ability The gameplay ability. 游戏技能。
* @return True if it has authority or a valid prediction key, false otherwise. 如果具有权限或有效预测键则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayAbility", meta = (DefaultToSelf="Ability"))
static bool HasAuthorityOrPredictionKey(const UGameplayAbility* Ability);
};

View File

@@ -0,0 +1,48 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Abilities/GameplayAbilityTargetTypes.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "StructUtils/InstancedStruct.h"
#include "GGA_GameplayAbilityTargetDataFunctionLibrary.generated.h"
/**
* Blueprint function library for gameplay ability target data operations.
* 用于游戏技能目标数据操作的蓝图函数库。
*/
UCLASS()
class GENERICGAMEPLAYABILITIES_API UGGA_GameplayAbilityTargetDataFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|TargetData")
static FGameplayAbilityTargetDataHandle AbilityTargetDataFromPayload(const FInstancedStruct& Payload);
/** Returns the hit result for a given index if it exists */
UFUNCTION(BlueprintPure, Category = "Ability|TargetData")
static FInstancedStruct GetPayloadFromTargetData(const FGameplayAbilityTargetDataHandle& TargetData, int32 Index);
/**
* Creates a target data handle from hit results.
* 从命中结果创建目标数据句柄。
* @param HitResults Array of hit results. 命中结果数组。
* @param OneTargetPerHandle Whether to create one target per handle. 是否每个句柄一个目标。
* @return The target data handle. 目标数据句柄。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|TargetData")
static FGameplayAbilityTargetDataHandle AbilityTargetDataFromHitResults(const TArray<FHitResult>& HitResults, bool OneTargetPerHandle);
/**
* Adds target data to an effect context.
* 将目标数据添加到效果上下文。
* @param TargetData The target data to add. 要添加的目标数据。
* @param EffectContext The effect context to modify. 要修改的效果上下文。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|TargetData")
static void AddTargetDataToContext(UPARAM(ref)
FGameplayAbilityTargetDataHandle TargetData, UPARAM(ref)
FGameplayEffectContextHandle EffectContext);
};

View File

@@ -0,0 +1,50 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameplayEffectTypes.h"
#include "GameplayTagContainer.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "GGA_GameplayCueFunctionLibrary.generated.h"
/**
* Blueprint function library for gameplay cue operations.
* 用于游戏反馈操作的蓝图函数库。
*/
UCLASS()
class GENERICGAMEPLAYABILITIES_API UGGA_GameplayCueFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
/**
* Executes a local gameplay cue on an actor.
* 在演员上执行本地游戏反馈。
* @param Actor The actor to execute the cue on. 要执行反馈的演员。
* @param GameplayCueTag The gameplay cue tag. 游戏反馈标签。
* @param GameplayCueParameters Parameters for the gameplay cue. 游戏反馈参数。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|GameplayCue", Meta = (DefaultToSelf="Actor", AutoCreateRefTerm = "GameplayCueParameters", GameplayTagFilter = "GameplayCue"))
static void ExecuteGameplayCueLocal(AActor* Actor, const FGameplayTag GameplayCueTag, const FGameplayCueParameters& GameplayCueParameters);
/**
* Adds a local gameplay cue to an actor.
* 向演员添加本地游戏反馈。
* @param Actor The actor to add the cue to. 要添加反馈的演员。
* @param GameplayCueTag The gameplay cue tag. 游戏反馈标签。
* @param GameplayCueParameters Parameters for the gameplay cue. 游戏反馈参数。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|GameplayCue", Meta = (DefaultToSelf="Actor", AutoCreateRefTerm = "GameplayCueParameters", GameplayTagFilter = "GameplayCue"))
static void AddGameplayCueLocal(AActor* Actor, const FGameplayTag GameplayCueTag, const FGameplayCueParameters& GameplayCueParameters);
/**
* Removes a local gameplay cue from an actor.
* 从演员移除本地游戏反馈。
* @param Actor The actor to remove the cue from. 要移除反馈的演员。
* @param GameplayCueTag The gameplay cue tag. 游戏反馈标签。
* @param GameplayCueParameters Parameters for the gameplay cue. 游戏反馈参数。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|GameplayCue", Meta = (DefaultToSelf="Actor", AutoCreateRefTerm = "GameplayCueParameters", GameplayTagFilter = "GameplayCue"))
static void RemoveGameplayCueLocal(AActor* Actor, const FGameplayTag GameplayCueTag, const FGameplayCueParameters& GameplayCueParameters);
};

View File

@@ -0,0 +1,233 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameplayEffectExecutionCalculation.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "GGA_GameplayEffectCalculationFunctionLibrary.generated.h"
/**
* Blueprint function library for gameplay effect calculation operations.
* 用于游戏效果计算操作的蓝图函数库。
*/
UCLASS()
class GENERICGAMEPLAYABILITIES_API UGGA_GameplayEffectCalculationFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
/**
* Retrieves the owning gameplay effect spec.
* 获取拥有的游戏效果规格。
* @param InParams The execution parameters. 执行参数。
* @return The owning gameplay effect spec. 拥有的游戏效果规格。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GGA|Calculation")
static const FGameplayEffectSpec& GetOwningSpec(const FGameplayEffectCustomExecutionParameters& InParams);
/** Simple accessor to the Passed In Tags to this execution */
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GGA|Calculation")
static const FGameplayTagContainer& GetPassedInTags(const FGameplayEffectCustomExecutionParameters& InParams);
/**
* Retrieves the effect context from execution parameters.
* 从执行参数获取效果上下文。
* @param InParams The execution parameters. 执行参数。
* @return The effect context handle. 效果上下文句柄。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GGA|Calculation")
static FGameplayEffectContextHandle GetEffectContext(const FGameplayEffectCustomExecutionParameters& InParams);
/**
* Retrieves the SetByCaller magnitude by tag from execution parameters.
* 从执行参数通过标签获取SetByCaller大小。
* @param InParams The execution parameters. 执行参数。
* @param Tag The tag to query. 要查询的标签。
* @param WarnIfNotFound Whether to warn if not found. 如果未找到是否警告。
* @param DefaultIfNotFound Default value if not found. 如果未找到的默认值。
* @return The magnitude value, or default if not found. 大小值,未找到时返回默认值。
*/
UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "GGA|Calculation")
static float GetSetByCallerMagnitudeByTag(const FGameplayEffectCustomExecutionParameters& InParams, const FGameplayTag& Tag, bool WarnIfNotFound = false, float DefaultIfNotFound = 0.f);
/**
* Retrieves the SetByCaller magnitude by name from execution parameters.
* 从执行参数通过名称获取SetByCaller大小。
* @param InParams The execution parameters. 执行参数。
* @param MagnitudeName The name to query. 要查询的名称。
* @param WarnIfNotFound Whether to warn if not found. 如果未找到是否警告。
* @param DefaultIfNotFound Default value if not found. 如果未找到的默认值。
* @return The magnitude value, or default if not found. 大小值,未找到时返回默认值。
*/
UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "GGA|Calculation")
static float GetSetByCallerMagnitudeByName(const FGameplayEffectCustomExecutionParameters& InParams, const FName& MagnitudeName, bool WarnIfNotFound = false, float DefaultIfNotFound = 0.f);
/**
* Retrieves source aggregated tags from the owning spec.
* 从拥有规格获取源聚合标签。
* @param InParams The execution parameters. 执行参数。
* @return The source aggregated tags. 源聚合标签。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GGA|Calculation")
static FGameplayTagContainer GetSourceAggregatedTags(const FGameplayEffectCustomExecutionParameters& InParams);
/**
* Retrieves target aggregated tags from the owning spec.
* 从拥有规格获取目标聚合标签。
* @param InParams The execution parameters. 执行参数。
* @return The target aggregated tags. 目标聚合标签。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GGA|Calculation")
static FGameplayTagContainer GetTargetAggregatedTags(const FGameplayEffectCustomExecutionParameters& InParams);
/**
* Retrieves the target ability system component.
* 获取目标技能系统组件。
* @param InParams The execution parameters. 执行参数。
* @return The target ability system component. 目标技能系统组件。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GGA|Calculation")
static UAbilitySystemComponent* GetTargetASC(const FGameplayEffectCustomExecutionParameters& InParams);
/**
* Retrieves the target actor.
* 获取目标演员。
* @param InParams The execution parameters. 执行参数。
* @return The target actor. 目标演员。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GGA|Calculation")
static AActor* GetTargetActor(const FGameplayEffectCustomExecutionParameters& InParams);
/**
* Retrieves the source ability system component.
* 获取源技能系统组件。
* @param InParams The execution parameters. 执行参数。
* @return The source ability system component. 源技能系统组件。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GGA|Calculation")
static UAbilitySystemComponent* GetSourceASC(const FGameplayEffectCustomExecutionParameters& InParams);
/**
* Retrieves the source actor.
* 获取源演员。
* @param InParams The execution parameters. 执行参数。
* @return The source actor. 源演员。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GGA|Calculation")
static AActor* GetSourceActor(const FGameplayEffectCustomExecutionParameters& InParams);
/**
* Attempts to calculate the magnitude of a captured attribute.
* 尝试计算捕获属性的值。
* @param InParams The execution parameters. 执行参数。
* @param InAttributeCaptureDefinitions Attribute capture definitions. 属性捕获定义。
* @param InAttribute The attribute to calculate. 要计算的属性。
* @param OutMagnitude The calculated magnitude (output). 计算出的大小(输出)。
* @return True if calculation was successful, false otherwise. 如果计算成功则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GGA|Calculation")
static bool AttemptCalculateCapturedAttributeMagnitude(const FGameplayEffectCustomExecutionParameters& InParams, TArray<FGameplayEffectAttributeCaptureDefinition> InAttributeCaptureDefinitions,
FGameplayAttribute InAttribute,
float& OutMagnitude);
/**
* Attempts to calculate the magnitude of a captured attribute with source and target tags.
* 尝试使用源和目标标签计算捕获属性的值。
* @param InParams The execution parameters. 执行参数。
* @param SourceTags Source tags for the calculation. 用于计算的源标签。
* @param TargetTags Target tags for the calculation. 用于计算的目标标签。
* @param InAttributeCaptureDefinitions Attribute capture definitions. 属性捕获定义。
* @param InAttribute The attribute to calculate. 要计算的属性。
* @param OutMagnitude The calculated magnitude (output). 计算出的大小(输出)。
* @return True if calculation was successful, false otherwise. 如果计算成功则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GGA|Calculation")
static bool AttemptCalculateCapturedAttributeMagnitudeExt(const FGameplayEffectCustomExecutionParameters& InParams, const FGameplayTagContainer& SourceTags,
const FGameplayTagContainer& TargetTags, TArray<FGameplayEffectAttributeCaptureDefinition> InAttributeCaptureDefinitions,
FGameplayAttribute InAttribute,
float& OutMagnitude);
/**
* Attempts to calculate the magnitude of a captured attribute with a base value.
* 使用基础值尝试计算捕获属性的值。
* @param InParams The execution parameters. 执行参数。
* @param InAttributeCaptureDefinitions Attribute capture definitions. 属性捕获定义。
* @param InAttribute The attribute to calculate. 要计算的属性。
* @param InBaseValue The base value for the calculation. 计算的基础值。
* @param OutMagnitude The calculated magnitude (output). 计算出的大小(输出)。
* @return True if calculation was successful, false otherwise. 如果计算成功则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GGA|Calculation")
static bool AttemptCalculateCapturedAttributeMagnitudeWithBase(const FGameplayEffectCustomExecutionParameters& InParams,
TArray<FGameplayEffectAttributeCaptureDefinition> InAttributeCaptureDefinitions,
FGameplayAttribute InAttribute, float InBaseValue, float& OutMagnitude);
/**
* Adds an output modifier to the execution output.
* 将输出修改器添加到执行输出。
* @param InExecutionOutput The execution output to modify. 要修改的执行输出。
* @param InAttribute The attribute to modify. 要修改的属性。
* @param InModifierOp The modifier operation type. 修改器操作类型。
* @param InMagnitude The magnitude of the modifier. 修改器的大小。
* @return The modified execution output. 修改后的执行输出。
*/
UFUNCTION(BlueprintCallable, Category="GGA|Calculation")
static FGameplayEffectCustomExecutionOutput AddOutputModifier(UPARAM(ref)
FGameplayEffectCustomExecutionOutput& InExecutionOutput, FGameplayAttribute InAttribute,
EGameplayModOp::Type InModifierOp, float InMagnitude);
/**
* Marks conditional gameplay effects to trigger.
* 标记条件游戏效果以触发。
* @param InExecutionOutput The execution output to modify. 要修改的执行输出。
*/
UFUNCTION(BlueprintCallable, Category="GGA|Calculation")
static void MarkConditionalGameplayEffectsToTrigger(UPARAM(ref)
FGameplayEffectCustomExecutionOutput& InExecutionOutput);
/**
* Marks gameplay cues as handled manually.
* 将游戏反馈标记为手动处理。
* @param InExecutionOutput The execution output to modify. 要修改的执行输出。
*/
UFUNCTION(BlueprintCallable, Category="GGA|Calculation")
static void MarkGameplayCuesHandledManually(UPARAM(ref)
FGameplayEffectCustomExecutionOutput& InExecutionOutput);
/**
* Marks the stack count as handled manually.
* 将堆叠计数标记为手动处理。
* @param InExecutionOutput The execution output to modify. 要修改的执行输出。
*/
UFUNCTION(BlueprintCallable, Category="GGA|Calculation")
static void MarkStackCountHandledManually(UPARAM(ref)
FGameplayEffectCustomExecutionOutput& InExecutionOutput);
/**
* Retrieves the effect context from a gameplay effect spec.
* 从游戏效果规格获取效果上下文。
* @param EffectSpec The gameplay effect spec. 游戏效果规格。
* @return The effect context handle. 效果上下文句柄。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|Calculation")
static FGameplayEffectContextHandle GetEffectContextFromSpec(const FGameplayEffectSpec& EffectSpec);
/**
* Adds a tag to the spec before applying modifiers.
* 在应用修改器前向规格添加标签。
* @param InParams The execution parameters. 执行参数。
* @param NewGameplayTag The tag to add. 要添加的标签。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|Calculation")
static void AddAssetTagForPreMod(const FGameplayEffectCustomExecutionParameters& InParams, FGameplayTag NewGameplayTag);
/**
* Adds multiple tags to the spec before applying modifiers.
* 在应用修改器前向规格添加多个标签。
* @param InParams The execution parameters. 执行参数。
* @param NewGameplayTags The tags to add. 要添加的标签。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|Calculation")
static void AddAssetTagsForPreMod(const FGameplayEffectCustomExecutionParameters& InParams, FGameplayTagContainer NewGameplayTags);
};

View File

@@ -0,0 +1,90 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GGA_AbilitySystemStructLibrary.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "GGA_GameplayEffectContainerFunctionLibrary.generated.h"
/**
* Blueprint function library for gameplay effect container operations.
* 用于游戏效果容器操作的蓝图函数库。
*/
UCLASS()
class GENERICGAMEPLAYABILITIES_API UGGA_GameplayEffectContainerFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
/**
* Checks if the gameplay effect container is valid.
* 检查游戏效果容器是否有效。
* @param Container The gameplay effect container. 游戏效果容器。
* @return True if the container is valid, false otherwise. 如果容器有效则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayEffect|Container")
static bool IsValidContainer(const FGGA_GameplayEffectContainer& Container);
/**
* Checks if the container spec has valid effects.
* 检查容器规格是否具有有效效果。
* @param ContainerSpec The gameplay effect container spec. 游戏效果容器规格。
* @return True if the spec has valid effects, false otherwise. 如果规格有有效效果则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayEffect|Container")
static bool HasValidEffects(const FGGA_GameplayEffectContainerSpec& ContainerSpec);
/**
* Checks if the container spec has valid targets.
* 检查容器规格是否具有有效目标。
* @param ContainerSpec The gameplay effect container spec. 游戏效果容器规格。
* @return True if the spec has valid targets, false otherwise. 如果规格有有效目标则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayEffect|Container")
static bool HasValidTargets(const FGGA_GameplayEffectContainerSpec& ContainerSpec);
/**
* Adds targets to a copy of the effect container spec.
* 将目标添加到效果容器规格的副本。
* @param ContainerSpec The gameplay effect container spec. 游戏效果容器规格。
* @param HitResults Array of hit results to add. 要添加的命中结果数组。
* @param TargetActors Array of target actors to add. 要添加的目标演员数组。
* @return The modified container spec. 修改后的容器规格。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|GameplayEffect|Container", meta = (AutoCreateRefTerm = "HitResults,TargetActors"))
static FGGA_GameplayEffectContainerSpec AddTargets(const FGGA_GameplayEffectContainerSpec& ContainerSpec, const TArray<FHitResult>& HitResults,
const TArray<AActor*>& TargetActors);
/**
* Creates a gameplay effect container spec from a container and event data.
* 从容器和事件数据创建游戏效果容器规格。
* @param Container The gameplay effect container. 游戏效果容器。
* @param EventData Event data for creating the spec. 用于创建规格的事件数据。
* @param OverrideGameplayLevel Optional override for gameplay effect level. 可选的游戏效果等级覆盖。
* @param SourceAbility Optional ability to derive source data. 可选的技能以获取源数据。
* @return The created container spec. 创建的容器规格。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|GameplayEffect|Container", meta=(AutoCreateRefTerm = "EventData"))
static FGGA_GameplayEffectContainerSpec MakeEffectContainerSpec(UPARAM(ref) const FGGA_GameplayEffectContainer& Container, const FGameplayEventData& EventData,
int32 OverrideGameplayLevel = -1, UGameplayAbility* SourceAbility = nullptr);
/**
* Applies a gameplay effect container spec.
* 应用游戏效果容器规格。
* @param ExecutingAbility The ability executing the spec. 执行规格的技能。
* @param ContainerSpec The container spec to apply. 要应用的容器规格。
* @return Array of active gameplay effect handles. 活动游戏效果句柄数组。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|Ability|EffectContainer",meta=(DefaultToSelf="ExecutingAbility"))
static TArray<FActiveGameplayEffectHandle> ApplyEffectContainerSpec(UGameplayAbility* ExecutingAbility, const FGGA_GameplayEffectContainerSpec& ContainerSpec);
/**
* Applies a gameplay effect container spec to all targets in its target data.
* 将游戏效果容器规格应用于其目标数据中的所有目标。
* @param ContainerSpec The container spec to apply. 要应用的容器规格。
* @return Array of active gameplay effect handles. 活动游戏效果句柄数组。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|GameplayEffect|Container")
static TArray<FActiveGameplayEffectHandle> ApplyExternalEffectContainerSpec(const FGGA_GameplayEffectContainerSpec& ContainerSpec);
};

View File

@@ -0,0 +1,226 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameplayEffectTypes.h"
#include "GGA_GameplayEffectContext.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Runtime/Launch/Resources/Version.h"
#if ENGINE_MINOR_VERSION < 5
#include "InstancedStruct.h"
#else
#include "StructUtils/InstancedStruct.h"
#endif
#include "GGA_GameplayEffectFunctionLibrary.generated.h"
UENUM()
enum class EGGA_ContextPayloadResult : uint8
{
Valid,
NotValid,
};
/**
* Blueprint function library for gameplay effect operations.
* 用于游戏效果操作的蓝图函数库。
*/
UCLASS()
class GENERICGAMEPLAYABILITIES_API UGGA_GameplayEffectFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
#pragma region EffectSpecHandle
/**
* Retrieves the magnitude of a SetByCaller modifier by tag.
* 通过标签获取SetByCaller修改器的大小。
* @param SpecHandle The gameplay effect spec handle. 游戏效果规格句柄。
* @param DataTag The tag to query. 要查询的标签。
* @param WarnIfNotFound Whether to warn if the tag is not found. 如果未找到标签是否警告。
* @param DefaultIfNotFound Default value if the tag is not found. 如果未找到标签的默认值。
* @return The magnitude value, or default if not found. 大小值,未找到时返回默认值。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayEffect")
static float GetSetByCallerMagnitudeByTag(FGameplayEffectSpecHandle SpecHandle, FGameplayTag DataTag, bool WarnIfNotFound = false, float DefaultIfNotFound = 0.0f);
/**
* Retrieves the magnitude of a SetByCaller modifier by name.
* 通过名称获取SetByCaller修改器的大小。
* @param SpecHandle The gameplay effect spec handle. 游戏效果规格句柄。
* @param DataName The name to query. 要查询的名称。
* @return The magnitude value, or zero if not found. 大小值,未找到时返回零。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayEffect")
static float GetSetByCallerMagnitudeByName(FGameplayEffectSpecHandle SpecHandle, FName DataName);
/**
* Checks if the active gameplay effect handle is valid.
* 检查活动游戏效果句柄是否有效。
* @param Handle The active gameplay effect handle. 活动游戏效果句柄。
* @return True if the handle is valid, false otherwise. 如果句柄有效则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayEffect")
static bool IsActiveGameplayEffectHandleValid(FActiveGameplayEffectHandle Handle);
#pragma endregion
#pragma region EffectSpec
/**
* Retrieves the magnitude of a SetByCaller modifier by tag.
* 通过标签获取SetByCaller修改器的大小。
* @param EffectSpec The gameplay effect spec . 游戏效果规格。
* @param DataTag The tag to query. 要查询的标签。
* @param WarnIfNotFound Whether to warn if the tag is not found. 如果未找到标签是否警告。
* @param DefaultIfNotFound Default value if the tag is not found. 如果未找到标签的默认值。
* @return The magnitude value, or default if not found. 大小值,未找到时返回默认值。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayEffect")
static float GetSetByCallerMagnitudeByTagFromSpec(const FGameplayEffectSpec& EffectSpec, FGameplayTag DataTag, bool WarnIfNotFound = false, float DefaultIfNotFound = 0.0f);
#pragma endregion
#pragma region Effect Context
/**
* Retrieves gameplay tags from the effect context.
* 从效果上下文中获取游戏标签。
* @param EffectContext The effect context handle. 效果上下文句柄。
* @param ActorTagContainer Container for actor tags. 演员标签容器。
* @param SpecTagContainer Container for spec tags. 规格标签容器。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|GameplayEffect|Context")
static void GetOwnedGameplayTags(FGameplayEffectContextHandle EffectContext, FGameplayTagContainer& ActorTagContainer, FGameplayTagContainer& SpecTagContainer);
/**
* Sets the instigator and effect causer in the effect context.
* 在效果上下文中设置发起者和效果原因。
* @param EffectContext The effect context handle. 效果上下文句柄。
* @param InInstigator The instigator actor. 发起者演员。
* @param InEffectCauser The effect causer actor. 效果原因演员。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|GameplayEffect|Context")
static void AddInstigator(FGameplayEffectContextHandle EffectContext, AActor* InInstigator, AActor* InEffectCauser);
/**
* Sets the effect causer in the effect context.
* 在效果上下文中设置效果原因。
* @param EffectContext The effect context handle. 效果上下文句柄。
* @param InEffectCauser The effect causer actor. 效果原因演员。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|GameplayEffect|Context")
static void SetEffectCauser(FGameplayEffectContextHandle EffectContext, AActor* InEffectCauser);
/**
* Sets the ability in the effect context.
* 在效果上下文中设置技能。
* @param EffectContext The effect context handle. 效果上下文句柄。
* @param InGameplayAbility The gameplay ability to set. 要设置的游戏技能。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|GameplayEffect|Context")
static void SetAbility(FGameplayEffectContextHandle EffectContext, const UGameplayAbility* InGameplayAbility);
/**
* Retrieves the ability CDO from the effect context.
* 从效果上下文中获取技能CDO。
* @param EffectContext The effect context handle. 效果上下文句柄。
* @return The ability CDO. 技能CDO。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayEffect|Context")
static const UGameplayAbility* GetAbilityCDO(FGameplayEffectContextHandle EffectContext);
/**
* Retrieves the ability instance from the effect context.
* 从效果上下文中获取技能实例。
* @attention The ability instance is not replicated so it's only valid on server side. 技能实例未网络复制,因此仅服务端可用。
* @param EffectContext The effect context handle. 效果上下文句柄。
* @return The ability instance. 技能实例。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayEffect|Context")
static const UGameplayAbility* GetAbilityInstance(FGameplayEffectContextHandle EffectContext);
/**
* Retrieves the ability level from the effect context.
* 从效果上下文中获取技能等级。
* @param EffectContext The effect context handle. 效果上下文句柄。
* @return The ability level. 技能等级。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayEffect|Context")
static int32 GetAbilityLevel(FGameplayEffectContextHandle EffectContext);
/**
* Retrieves the instigator's ability system component.
* 获取发起者的技能系统组件。
* @param EffectContext The effect context handle. 效果上下文句柄。
* @return The instigator's ability system component. 发起者的技能系统组件。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayEffect|Context")
static UAbilitySystemComponent* GetInstigatorAbilitySystemComponent(FGameplayEffectContextHandle EffectContext);
/**
* Retrieves the original instigator's ability system component.
* 获取原始发起者的技能系统组件。
* @param EffectContext The effect context handle. 效果上下文句柄。
* @return The original instigator's ability system component. 原始发起者的技能系统组件。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayEffect|Context")
static UAbilitySystemComponent* GetOriginalInstigatorAbilitySystemComponent(FGameplayEffectContextHandle EffectContext);
/**
* Sets the source object in the effect context.
* 在效果上下文中设置源对象。
* @param EffectContext The effect context handle. 效果上下文句柄。
* @param NewSourceObject The source object to set. 要设置的源对象。
*/
UFUNCTION(BlueprintCallable, Category = "GGA|GameplayEffect|Context")
static void AddSourceObject(FGameplayEffectContextHandle EffectContext, const UObject* NewSourceObject);
/**
* Checks if the effect context has an origin.
* 检查效果上下文是否具有起源。
* @param EffectContext The effect context handle. 效果上下文句柄。
* @return True if the context has an origin, false otherwise. 如果上下文有起源则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayEffect|Context")
static bool HasOrigin(FGameplayEffectContextHandle EffectContext);
#pragma endregion
#pragma region Custom Effect Context
/**
* Helper method to safely get the pointer of GGA_GameplayEffectContext.
* 用于安全地获取GGA_GameplayEffectContext的实用函数。
* @param EffectContext The gameplay effect context handle 游戏效果上下文句柄。
* @return The actually FGGA_GameplayEffectContext pointer.
*/
static FGGA_GameplayEffectContext* GetEffectContextPtr(FGameplayEffectContextHandle EffectContext);
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayEffect|Context")
static bool HasContextPayload(FGameplayEffectContextHandle EffectContext, const UScriptStruct* PayloadType);
static bool GetContextPayload(FGameplayEffectContextHandle EffectContext, const UScriptStruct* PayloadType, FInstancedStruct& OutPayload);
/**
* Do not call this,It's for blueprint only.
* 不要调用这个,这是给蓝图专用的。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|GameplayEffect|Context", meta=(BlueprintInternalUseOnly="true"))
static FInstancedStruct GetValidContextPayload(FGameplayEffectContextHandle EffectContext, const UScriptStruct* PayloadType, bool& bValid);
/**
* Do not call this,It's for blueprint only.
* 不要调用这个,这是给蓝图专用的。
*/
UFUNCTION(BlueprintCallable, CustomThunk, Category = "GGA|GameplayEffect|Context", meta=(CustomStructureParam = "Value", ExpandEnumAsExecs = "ExecResult", BlueprintInternalUseOnly="true"))
static void GetContextPayload(FGameplayEffectContextHandle EffectContext, const UScriptStruct* PayloadType, EGGA_ContextPayloadResult& ExecResult, int32& Value);
UFUNCTION(BlueprintCallable, CustomThunk, Category = "GGA|GameplayEffect|Context",
meta=(CustomStructureParam = "Value", ExpandEnumAsExecs = "ExecResult", BlueprintInternalUseOnly="true"))
static void SetContextPayload(FGameplayEffectContextHandle EffectContext, EGGA_ContextPayloadResult& ExecResult, const int32& Value);
private:
DECLARE_FUNCTION(execGetContextPayload);
DECLARE_FUNCTION(execSetContextPayload);
#pragma endregion
};