From 001a54252115db0f165b0c6fa5ab73ac9d9491e8 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Tue, 22 Oct 2024 18:12:31 -0400 Subject: [PATCH] 74. Modifier Magnitude Calculations --- .../Gasa/AbilitySystem/MMC/MMC_MaxHealth.cpp | 35 +++++++++++++++++++ .../Gasa/AbilitySystem/MMC/MMC_MaxHealth.h | 19 ++++++++++ .../Gasa/AbilitySystem/MMC/MMC_MaxMana.cpp | 34 ++++++++++++++++++ .../Gasa/AbilitySystem/MMC/MMC_MaxMana.h | 19 ++++++++++ .../Source/Gasa/Characters/GasaCharacter.cpp | 12 ++++--- .../Gasa/Characters/PlayerCharacter.cpp | 4 +-- .../Source/Gasa/Characters/PlayerCharacter.h | 4 +-- Project/Source/Gasa/Game/GasaPlayerState.cpp | 6 ++-- 8 files changed, 122 insertions(+), 11 deletions(-) create mode 100644 Project/Source/Gasa/AbilitySystem/MMC/MMC_MaxHealth.cpp create mode 100644 Project/Source/Gasa/AbilitySystem/MMC/MMC_MaxHealth.h create mode 100644 Project/Source/Gasa/AbilitySystem/MMC/MMC_MaxMana.cpp create mode 100644 Project/Source/Gasa/AbilitySystem/MMC/MMC_MaxMana.h diff --git a/Project/Source/Gasa/AbilitySystem/MMC/MMC_MaxHealth.cpp b/Project/Source/Gasa/AbilitySystem/MMC/MMC_MaxHealth.cpp new file mode 100644 index 0000000..d4c405a --- /dev/null +++ b/Project/Source/Gasa/AbilitySystem/MMC/MMC_MaxHealth.cpp @@ -0,0 +1,35 @@ +#include "MMC_MaxHealth.h" + +#include "AbilitySystem/GasaAttributeSet.h" +#include "Interfaces/CombatInterface.h" + +UMMC_MaxHealth::UMMC_MaxHealth() +{ + VigorDef.AttributeToCapture = UGasaAttributeSet::GetVigorAttribute(); + VigorDef.AttributeSource = EGameplayEffectAttributeCaptureSource::Target; + VigorDef.bSnapshot = false; + + RelevantAttributesToCapture.Add( VigorDef); +} + +float UMMC_MaxHealth::CalculateBaseMagnitude_Implementation( FGameplayEffectSpec const& Spec ) const +{ + // Gather tags from source and target + FGameplayTagContainer const* SourceTags = Spec.CapturedSourceTags.GetAggregatedTags(); + FGameplayTagContainer const* TargetTags = Spec.CapturedTargetTags.GetAggregatedTags(); + + FAggregatorEvaluateParameters EvaluationParamters; + EvaluationParamters.SourceTags = SourceTags; + EvaluationParamters.TargetTags = TargetTags; + + float Vigor = 0.f; + GetCapturedAttributeMagnitude(VigorDef, Spec, EvaluationParamters, Vigor); + Vigor = FMath::Max(Vigor, 0.f); + + ICombat* Combat = Cast(Spec.GetContext().GetSourceObject()); + int32 PlayerLevel = Combat->GetPlayerLevel(); + + float Calculation = 80.f + 2.5 * Vigor + 10.f * PlayerLevel; + return Calculation; +} + diff --git a/Project/Source/Gasa/AbilitySystem/MMC/MMC_MaxHealth.h b/Project/Source/Gasa/AbilitySystem/MMC/MMC_MaxHealth.h new file mode 100644 index 0000000..56735a6 --- /dev/null +++ b/Project/Source/Gasa/AbilitySystem/MMC/MMC_MaxHealth.h @@ -0,0 +1,19 @@ +#pragma once + +#include "GameplayModMagnitudeCalculation.h" + +#include "MMC_MaxHealth.generated.h" + +UCLASS() +class GASA_API UMMC_MaxHealth : public UGameplayModMagnitudeCalculation +{ + GENERATED_BODY() + +public: + + UMMC_MaxHealth(); + + FGameplayEffectAttributeCaptureDefinition VigorDef; + + float CalculateBaseMagnitude_Implementation( FGameplayEffectSpec const& Spec ) const override; +}; diff --git a/Project/Source/Gasa/AbilitySystem/MMC/MMC_MaxMana.cpp b/Project/Source/Gasa/AbilitySystem/MMC/MMC_MaxMana.cpp new file mode 100644 index 0000000..605ae1f --- /dev/null +++ b/Project/Source/Gasa/AbilitySystem/MMC/MMC_MaxMana.cpp @@ -0,0 +1,34 @@ +#include "MMC_MaxMana.h" + +#include "AbilitySystem/GasaAttributeSet.h" +#include "Interfaces/CombatInterface.h" + +UMMC_MaxMana::UMMC_MaxMana() +{ + IntelligenceDef.AttributeToCapture = UGasaAttributeSet::GetVigorAttribute(); + IntelligenceDef.AttributeSource = EGameplayEffectAttributeCaptureSource::Target; + IntelligenceDef.bSnapshot = false; + + RelevantAttributesToCapture.Add( IntelligenceDef); +} + +float UMMC_MaxMana::CalculateBaseMagnitude_Implementation( FGameplayEffectSpec const& Spec ) const +{ + // Gather tags from source and target + FGameplayTagContainer const* SourceTags = Spec.CapturedSourceTags.GetAggregatedTags(); + FGameplayTagContainer const* TargetTags = Spec.CapturedTargetTags.GetAggregatedTags(); + + FAggregatorEvaluateParameters EvaluationParamters; + EvaluationParamters.SourceTags = SourceTags; + EvaluationParamters.TargetTags = TargetTags; + + float Intelligence = 0.f; + GetCapturedAttributeMagnitude(IntelligenceDef, Spec, EvaluationParamters, Intelligence); + Intelligence = FMath::Max(Intelligence, 0.f); + + ICombat* Combat = Cast(Spec.GetContext().GetSourceObject()); check(Combat); + int32 PlayerLevel = Combat->GetPlayerLevel(); + + float Calculation = 50.f + 2.5 * Intelligence + 15.f * PlayerLevel; + return Calculation; +} diff --git a/Project/Source/Gasa/AbilitySystem/MMC/MMC_MaxMana.h b/Project/Source/Gasa/AbilitySystem/MMC/MMC_MaxMana.h new file mode 100644 index 0000000..742015d --- /dev/null +++ b/Project/Source/Gasa/AbilitySystem/MMC/MMC_MaxMana.h @@ -0,0 +1,19 @@ +#pragma once + +#include "GameplayModMagnitudeCalculation.h" + +#include "MMC_MaxMana.generated.h" + +UCLASS() +class GASA_API UMMC_MaxMana : public UGameplayModMagnitudeCalculation +{ + GENERATED_BODY() + +public: + + UMMC_MaxMana(); + + FGameplayEffectAttributeCaptureDefinition IntelligenceDef; + + float CalculateBaseMagnitude_Implementation( FGameplayEffectSpec const& Spec ) const override; +}; \ No newline at end of file diff --git a/Project/Source/Gasa/Characters/GasaCharacter.cpp b/Project/Source/Gasa/Characters/GasaCharacter.cpp index 75ad00a..291d02b 100644 --- a/Project/Source/Gasa/Characters/GasaCharacter.cpp +++ b/Project/Source/Gasa/Characters/GasaCharacter.cpp @@ -79,13 +79,17 @@ void AGasaCharacter::InitDefaultAttributes() { UAbilitySystemComponent* ASC = GetAbilitySystemComponent(); ensure(ASC); + ensure(DefaultVitalAttributes); ensure(DefaultPrimaryAttributes); ensure(DefaultSecondaryAttributes); - FGameplayEffectContextHandle Context = ASC->MakeEffectContext(); - FGameplayEffectSpecHandle SpecPrimary = ASC->MakeOutgoingSpec(DefaultPrimaryAttributes, 1.0f, Context ); - FGameplayEffectSpecHandle SpecSecondary = ASC->MakeOutgoingSpec(DefaultSecondaryAttributes, 1.0f, Context ); - FGameplayEffectSpecHandle SpecVital = ASC->MakeOutgoingSpec(DefaultVitalAttributes, 1.0f, Context ); + + FGameplayEffectContextHandle Context = ASC->MakeEffectContext(); + Context.AddSourceObject(this); + + FGameplayEffectSpecHandle SpecPrimary = ASC->MakeOutgoingSpec(DefaultPrimaryAttributes, 1.0f, Context ); + FGameplayEffectSpecHandle SpecSecondary = ASC->MakeOutgoingSpec(DefaultSecondaryAttributes, 1.0f, Context ); + FGameplayEffectSpecHandle SpecVital = ASC->MakeOutgoingSpec(DefaultVitalAttributes, 1.0f, Context ); ASC->ApplyGameplayEffectSpecToTarget( * SpecPrimary.Data, ASC ); ASC->ApplyGameplayEffectSpecToTarget( * SpecSecondary.Data, ASC ); ASC->ApplyGameplayEffectSpecToTarget( * SpecVital.Data, ASC ); diff --git a/Project/Source/Gasa/Characters/PlayerCharacter.cpp b/Project/Source/Gasa/Characters/PlayerCharacter.cpp index 4ec8319..865f54a 100644 --- a/Project/Source/Gasa/Characters/PlayerCharacter.cpp +++ b/Project/Source/Gasa/Characters/PlayerCharacter.cpp @@ -14,9 +14,9 @@ APlayerCharacter::APlayerCharacter() } #pragma region ICombat -int32 APlayerCharacter::GetLevel() +int32 APlayerCharacter::GetPlayerLevel() { - return GetPlayerState()->Level; + return GetPlayerState()->PlayerLevel; } #pragma endregion ICombat diff --git a/Project/Source/Gasa/Characters/PlayerCharacter.h b/Project/Source/Gasa/Characters/PlayerCharacter.h index ba47fb4..e70ac5f 100644 --- a/Project/Source/Gasa/Characters/PlayerCharacter.h +++ b/Project/Source/Gasa/Characters/PlayerCharacter.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "GasaCharacter.h" @@ -13,7 +13,7 @@ public: APlayerCharacter(); #pragma region ICombat - int32 GetLevel() override; + int32 GetPlayerLevel() override; #pragma endregion ICombat #pragma region Pawn diff --git a/Project/Source/Gasa/Game/GasaPlayerState.cpp b/Project/Source/Gasa/Game/GasaPlayerState.cpp index 0b3cca6..ee2c5e1 100644 --- a/Project/Source/Gasa/Game/GasaPlayerState.cpp +++ b/Project/Source/Gasa/Game/GasaPlayerState.cpp @@ -1,4 +1,4 @@ -#include "GasaPlayerState.h" +#include "GasaPlayerState.h" #include "Net/UnrealNetwork.h" @@ -12,7 +12,7 @@ AGasaPlayerState::AGasaPlayerState() { bAutoAbilitySystem = true; - Level = 1; + PlayerLevel = 1; AbilitySystem = CreateDefaultSubobject("Ability System"); AbilitySystem->SetIsReplicated(true); @@ -96,6 +96,6 @@ void AGasaPlayerState::GetLifetimeReplicatedProps(TArray& Out { Super::GetLifetimeReplicatedProps(OutLifetimeProps); - DOREPLIFETIME(AGasaPlayerState, Level); + DOREPLIFETIME(AGasaPlayerState, PlayerLevel); } #pragma endregion UObject