Skip to content

Commit

Permalink
[#9] [#53] Implement GetDamageTypeForDamageAttribute Utility Method
Browse files Browse the repository at this point in the history
This makes it easy to map from a damage attribute back to a damage tag.
  • Loading branch information
GuyPaddock committed Dec 28, 2023
1 parent e49a75f commit 1279d91
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Source/OpenPF2Core/Private/Abilities/PF2AttackAttributeStatics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Abilities/PF2AttributeSetMacros.h"

#include "Utilities/PF2ArrayUtilities.h"
#include "Utilities/PF2GameplayAbilityUtilities.h"

TArray<const FGameplayEffectAttributeCaptureDefinition*> FPF2AttackAttributeStatics::GetAllDamageCaptures() const
{
Expand Down Expand Up @@ -44,6 +45,22 @@ const FGameplayEffectAttributeCaptureDefinition* FPF2AttackAttributeStatics::Get
return Result;
}

FGameplayTag FPF2AttackAttributeStatics::GetDamageTypeForDamageAttribute(const FGameplayAttribute& Attribute) const
{
FGameplayTag FoundTag;

for (const auto& Pair : this->DamageTypeToTransientDamageAttributeMap)
{
if (Pair.Value == Attribute.AttributeName)
{
FoundTag = PF2GameplayAbilityUtilities::GetTag(Pair.Key);
break;
}
}

return FoundTag;
}

FPF2AttackAttributeStatics::FPF2AttackAttributeStatics():
TmpAttackRollCountProperty(nullptr),
TmpAttackRollSizeProperty(nullptr),
Expand Down
12 changes: 12 additions & 0 deletions Source/OpenPF2Core/Public/Abilities/PF2AttackAttributeStatics.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ struct OPENPF2CORE_API FPF2AttackAttributeStatics : FPF2AttributeStaticsBase
const FGameplayEffectAttributeCaptureDefinition* GetDamageCaptureForDamageType(
const FName& DamageTypeName) const;

/**
* Gets the damage type tag that corresponds to the specified transient damage attribute.
*
* @param Attribute
* The attribute for which a damage type is desired.
*
* @return
* Either the tag for the type of damage that was provided; or, a gameplay tag that is not valid if there is no
* damage type that corresponds to the given attribute.
*/
FGameplayTag GetDamageTypeForDamageAttribute(const FGameplayAttribute& Attribute) const;

protected:
// =================================================================================================================
// Protected Constructors
Expand Down

0 comments on commit 1279d91

Please sign in to comment.