From 2cd1c7572ac43ec63bf5f60f881b3724ef76fee7 Mon Sep 17 00:00:00 2001 From: Guy Elsmore-Paddock Date: Mon, 18 Dec 2023 00:49:07 -0500 Subject: [PATCH] [#9] [#53] Implement `GetDamageTypeForDamageAttribute` Utility Method This makes it easy to map from a damage attribute back to a damage tag. --- .../Abilities/PF2AttackAttributeStatics.cpp | 17 +++++++++++++++++ .../Abilities/PF2AttackAttributeStatics.h | 12 ++++++++++++ 2 files changed, 29 insertions(+) diff --git a/Source/OpenPF2Core/Private/Abilities/PF2AttackAttributeStatics.cpp b/Source/OpenPF2Core/Private/Abilities/PF2AttackAttributeStatics.cpp index 1f61f3a8a..b563aafbc 100644 --- a/Source/OpenPF2Core/Private/Abilities/PF2AttackAttributeStatics.cpp +++ b/Source/OpenPF2Core/Private/Abilities/PF2AttackAttributeStatics.cpp @@ -9,6 +9,7 @@ #include "Abilities/PF2AttributeSetMacros.h" #include "Utilities/PF2ArrayUtilities.h" +#include "Utilities/PF2GameplayAbilityUtilities.h" TArray FPF2AttackAttributeStatics::GetAllDamageCaptures() const { @@ -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), diff --git a/Source/OpenPF2Core/Public/Abilities/PF2AttackAttributeStatics.h b/Source/OpenPF2Core/Public/Abilities/PF2AttackAttributeStatics.h index 5aef12972..7eec771d6 100644 --- a/Source/OpenPF2Core/Public/Abilities/PF2AttackAttributeStatics.h +++ b/Source/OpenPF2Core/Public/Abilities/PF2AttackAttributeStatics.h @@ -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