Skip to content

Commit

Permalink
[#60] Move FGameplayAbilityUtilities::HasTag() into PF2TagLibrary...
Browse files Browse the repository at this point in the history
...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.
  • Loading branch information
GuyPaddock committed Jul 19, 2024
1 parent 0283bf8 commit 680aef6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "CharacterStats/PF2TemlCalculation.h"

#include "Libraries/PF2AbilitySystemLibrary.h"
#include "Libraries/PF2TagLibrary.h"

#include "Utilities/PF2GameplayAbilityUtilities.h"

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "CharacterStats/PF2TemlCalculation.h"

#include "Libraries/PF2TagLibrary.h"

#include "Utilities/PF2GameplayAbilityUtilities.h"

FPF2TemlCalculation::FPF2TemlCalculation(const FString& TagPrefix, const FGameplayEffectSpec& Spec) :
Expand Down Expand Up @@ -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;
Expand Down
37 changes: 37 additions & 0 deletions Source/OpenPF2GameFramework/Public/Libraries/PF2TagLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <GameplayEffect.h>
#include <GameplayEffectTypes.h>
#include <GameplayTagContainer.h>

#include "PF2CharacterConstants.h"

Expand All @@ -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.
*
Expand Down

0 comments on commit 680aef6

Please sign in to comment.