74. Modifier Magnitude Calculations

This commit is contained in:
Edward R. Gonzalez 2024-10-22 18:12:31 -04:00
parent 7e27f708cf
commit 001a542521
8 changed files with 122 additions and 11 deletions

View File

@ -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<ICombat>(Spec.GetContext().GetSourceObject());
int32 PlayerLevel = Combat->GetPlayerLevel();
float Calculation = 80.f + 2.5 * Vigor + 10.f * PlayerLevel;
return Calculation;
}

View File

@ -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;
};

View File

@ -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<ICombat>(Spec.GetContext().GetSourceObject()); check(Combat);
int32 PlayerLevel = Combat->GetPlayerLevel();
float Calculation = 50.f + 2.5 * Intelligence + 15.f * PlayerLevel;
return Calculation;
}

View File

@ -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;
};

View File

@ -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 );

View File

@ -14,9 +14,9 @@ APlayerCharacter::APlayerCharacter()
}
#pragma region ICombat
int32 APlayerCharacter::GetLevel()
int32 APlayerCharacter::GetPlayerLevel()
{
return GetPlayerState<AGasaPlayerState>()->Level;
return GetPlayerState<AGasaPlayerState>()->PlayerLevel;
}
#pragma endregion ICombat

View File

@ -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

View File

@ -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<UGasaAbilitySystemComp>("Ability System");
AbilitySystem->SetIsReplicated(true);
@ -96,6 +96,6 @@ void AGasaPlayerState::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& Out
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(AGasaPlayerState, Level);
DOREPLIFETIME(AGasaPlayerState, PlayerLevel);
}
#pragma endregion UObject