From 680aef6819b8418d6718a0a54b24ca718885373f Mon Sep 17 00:00:00 2001 From: Guy Elsmore-Paddock Date: Tue, 16 Jul 2024 00:05:33 -0400 Subject: [PATCH] [#60] Move `FGameplayAbilityUtilities::HasTag()` into `PF2TagLibrary`... ...as `ContainerHasTag()`. This makes more sense with the other tag-related utility methods in the library. We're also able to expose it to Blueprint, as long as we take in a const reference instead of a pointer. --- .../PF2KeyAbilityTemlCalculationBase.cpp | 5 +-- .../CharacterStats/PF2TemlCalculation.cpp | 10 +++-- .../Public/Libraries/PF2TagLibrary.h | 37 +++++++++++++++++++ .../Utilities/PF2GameplayAbilityUtilities.h | 37 ------------------- 4 files changed, 45 insertions(+), 44 deletions(-) diff --git a/Source/OpenPF2GameFramework/Private/CharacterStats/PF2KeyAbilityTemlCalculationBase.cpp b/Source/OpenPF2GameFramework/Private/CharacterStats/PF2KeyAbilityTemlCalculationBase.cpp index 4b4a37f0..241ce109 100644 --- a/Source/OpenPF2GameFramework/Private/CharacterStats/PF2KeyAbilityTemlCalculationBase.cpp +++ b/Source/OpenPF2GameFramework/Private/CharacterStats/PF2KeyAbilityTemlCalculationBase.cpp @@ -18,6 +18,7 @@ #include "CharacterStats/PF2TemlCalculation.h" #include "Libraries/PF2AbilitySystemLibrary.h" +#include "Libraries/PF2TagLibrary.h" #include "Utilities/PF2GameplayAbilityUtilities.h" @@ -144,9 +145,7 @@ FGameplayEffectAttributeCaptureDefinition UPF2KeyAbilityTemlCalculationBase::Det for (auto PairIterator = this->KeyAbilityCaptureDefinitions.CreateConstIterator(); PairIterator; ++PairIterator) { - const FString TagName = PairIterator.Key(); - - if (PF2GameplayAbilityUtilities::HasTag(SourceTags, TagName)) + if (const FString TagName = PairIterator.Key(); UPF2TagLibrary::ContainerHasTag(*SourceTags, TagName)) { KeyAbilityCaptureDefinition = PairIterator.Value(); break; diff --git a/Source/OpenPF2GameFramework/Private/CharacterStats/PF2TemlCalculation.cpp b/Source/OpenPF2GameFramework/Private/CharacterStats/PF2TemlCalculation.cpp index 302e7fed..c98538e7 100644 --- a/Source/OpenPF2GameFramework/Private/CharacterStats/PF2TemlCalculation.cpp +++ b/Source/OpenPF2GameFramework/Private/CharacterStats/PF2TemlCalculation.cpp @@ -12,6 +12,8 @@ #include "CharacterStats/PF2TemlCalculation.h" +#include "Libraries/PF2TagLibrary.h" + #include "Utilities/PF2GameplayAbilityUtilities.h" FPF2TemlCalculation::FPF2TemlCalculation(const FString& TagPrefix, const FGameplayEffectSpec& Spec) : @@ -50,22 +52,22 @@ FPF2TemlCalculation::FPF2TemlCalculation(const FGameplayTag TagPrefix, // // Source: Pathfinder 2E Core Rulebook, page 444, "Step 1: Roll D20 and Identify The Modifiers, Bonuses, and // Penalties That Apply". - if (PF2GameplayAbilityUtilities::HasTag(CharacterTags, TagPrefixString + ".Legendary")) + if (UPF2TagLibrary::ContainerHasTag(*CharacterTags, TagPrefixString + ".Legendary")) { // Legendary -> Your level + 8 ProficiencyBonus = CharacterLevel + 8; } - else if (PF2GameplayAbilityUtilities::HasTag(CharacterTags, TagPrefixString + ".Master")) + else if (UPF2TagLibrary::ContainerHasTag(*CharacterTags, TagPrefixString + ".Master")) { // Master -> Your level + 6 ProficiencyBonus = CharacterLevel + 6; } - else if (PF2GameplayAbilityUtilities::HasTag(CharacterTags, TagPrefixString + ".Expert")) + else if (UPF2TagLibrary::ContainerHasTag(*CharacterTags, TagPrefixString + ".Expert")) { // Expert -> Your level + 4 ProficiencyBonus = CharacterLevel + 4; } - else if (PF2GameplayAbilityUtilities::HasTag(CharacterTags, TagPrefixString + ".Trained")) + else if (UPF2TagLibrary::ContainerHasTag(*CharacterTags, TagPrefixString + ".Trained")) { // Trained -> Your level + 2 ProficiencyBonus = CharacterLevel + 2; diff --git a/Source/OpenPF2GameFramework/Public/Libraries/PF2TagLibrary.h b/Source/OpenPF2GameFramework/Public/Libraries/PF2TagLibrary.h index 8805e6dc..3a204e7b 100644 --- a/Source/OpenPF2GameFramework/Public/Libraries/PF2TagLibrary.h +++ b/Source/OpenPF2GameFramework/Public/Libraries/PF2TagLibrary.h @@ -24,6 +24,43 @@ class OPENPF2GAMEFRAMEWORK_API UPF2TagLibrary final : public UBlueprintFunctionL GENERATED_BODY() public: + /** + * Checks if a tag with the given name or prefix is present in the given container. + * + * @param Tags + * The list of tags in which to search. + * @param TagNameOrPrefix + * The name of the tag or the prefix; as an FName. + * + * @return + * - TRUE if given a tag name, and a tag with the specified name is present in the tag list. + * - TRUE if given a tag prefix, and there is a tag present in the tag list that starts with that prefix. + * - FALSE, otherwise. + */ + UFUNCTION(BlueprintCallable, BlueprintPure, meta=(AutoCreateRefTerm="ParentTag"), Category="OpenPF2|Gameplay Tags") + static FORCEINLINE bool ContainerHasTag(const FGameplayTagContainer& Tags, const FName& TagNameOrPrefix) + { + return Tags.HasTag(FGameplayTag::RequestGameplayTag(TagNameOrPrefix)); + } + + /** + * Checks if a tag with the given name or prefix is present in the given container. + * + * @param Tags + * The list of tags in which to search. + * @param TagNameOrPrefix + * The name of the tag or the prefix; as a string. + * + * @return + * - TRUE if given a tag name, and a tag with the specified name is present in the tag list. + * - TRUE if given a tag prefix, and there is a tag present in the tag list that starts with that prefix. + * - FALSE, otherwise. + */ + static FORCEINLINE bool ContainerHasTag(const FGameplayTagContainer& Tags, const FString& TagNameOrPrefix) + { + return Tags.HasTag(FGameplayTag::RequestGameplayTag(FName(TagNameOrPrefix))); + } + /** * Locates the tag within the specified tag container that is a child of another tag. * diff --git a/Source/OpenPF2GameFramework/Public/Utilities/PF2GameplayAbilityUtilities.h b/Source/OpenPF2GameFramework/Public/Utilities/PF2GameplayAbilityUtilities.h index a514aa2d..0702f105 100644 --- a/Source/OpenPF2GameFramework/Public/Utilities/PF2GameplayAbilityUtilities.h +++ b/Source/OpenPF2GameFramework/Public/Utilities/PF2GameplayAbilityUtilities.h @@ -7,7 +7,6 @@ #include #include -#include #include "PF2CharacterConstants.h" @@ -26,42 +25,6 @@ class UPF2CharacterAttributeSet; */ namespace PF2GameplayAbilityUtilities { - /** - * Checks if a tag with the given name or prefix is present. - * - * @param Tags - * The list of tags in which to search. - * @param TagNameOrPrefix - * The name of the tag or the prefix; as an FName. - * - * @return - * - TRUE if given a tag name, and a tag with the specified name is present in the tag list. - * - TRUE if given a tag prefix, and there is a tag present in the tag list that starts with that prefix. - * - FALSE, otherwise. - */ - FORCEINLINE OPENPF2GAMEFRAMEWORK_API bool HasTag(const FGameplayTagContainer* Tags, const FName TagNameOrPrefix) - { - return Tags->HasTag(GetTag(TagNameOrPrefix)); - } - - /** - * Checks if a tag with the given name or prefix is present. - * - * @param Tags - * The list of tags in which to search. - * @param TagNameOrPrefix - * The name of the tag or the prefix; as a string. - * - * @return - * - TRUE if given a tag name, and a tag with the specified name is present in the tag list. - * - TRUE if given a tag prefix, and there is a tag present in the tag list that starts with that prefix. - * - FALSE, otherwise. - */ - FORCEINLINE OPENPF2GAMEFRAMEWORK_API bool HasTag(const FGameplayTagContainer* Tags, const FString& TagNameOrPrefix) - { - return Tags->HasTag(GetTag(TagNameOrPrefix)); - } - /** * Creates an attribute capture definition for the specified Gameplay Attribute. *