总结
- 记住Coefficient, Pre Multiply以及Post Multiply的计算顺序: (属性值+Pre Multiply) * Coefficient + Post Multiply
- 在选择Custom Calculation Class 后,依然可以使用Coefficient, Pre Multiply以及Post Multiply三个值
C++文件有更新,但是部分基础的东西不写出来了
文件结构
Source
-
Private
- AbilitySystem
- ModMagCalc
- MMC_MaxHealth.cpp
- MMC_MaxMana.cpp
- RPGAbilitySystemComponent.cpp
- RPGAttributeSet.cpp
- ModMagCalc
- Character
- PGGameCharacterBase.cpp
- RPGGameEnemy.cpp
- RPGGamePlayerCharacter.cpp
- Game
- RPGGameModeBase.cpp
- Interaction
- EnemyInterface.cpp
- CombatInterface.cpp
- Player
- RPGPlayerController.cpp
- RPGPlayerState.cpp
- Actor
- RPGEffectActor.cpp
- UI
- HUD
- RPGHUD.cpp
- WidgetController
- OverlayWidgetController.cpp
- RPGWidgetController.cpp
- Widgets
- RPGUserWidget.cpp
- HUD
- AbilitySystem
-
Public
-
AbilitySystem
-
ModMagCalc
- MMC_MaxHealth.h
- MMC_MaxMana.h
-
RPGAbilitySystemComponent.h
-
RPGAttributeSet.h
-
-
Character
- RPGGameCharacterBase.h
- RPGGameEnemy.h
- RPGGamePlayerCharacter.h
-
Game
- RPGGameModeBase.h
-
Interaction
- EnemyInterface.h
- CombatInterface.h
-
Player
- RPGPlayerController.h
- RPGPlayerState.h
-
Actor
- RPGEffectActor.h
-
UI
- HUD
- RPGHUD.h
- WidgetController
- OverlayWidgetController.h
- RPGWidgetController.h
- Widgets
- RPGUserWidget.h
- HUD
-
文件概述
由于MMC_MaxMana与MMC_MaxHealth长得除了监视参数以外,所有逻辑一模一样,故此处只记录MMC_MaxHelath
MMC_MaxHealth
.h文件
// Copyright KimiLiu
#pragma once
#include "CoreMinimal.h"
#include "GameplayModMagnitudeCalculation.h"
#include "MMC_MaxHealth.generated.h"
/**
*
*/
UCLASS()
class AURA_API UMMC_MaxHealth : public UGameplayModMagnitudeCalculation
{
GENERATED_BODY()
public:
UMMC_MaxHealth();
virtual float CalculateBaseMagnitude_Implementation(const FGameplayEffectSpec& Spec) const override;
private:
/** FGameplayEffectAttributeCaptureDefinition 有两个属性, 一个是GameplayAttribute就是我们需要捕获的Attribute
* 另一个是GameplayEffectAttributeCaptureSource就是我们需要捕获的Attribute的来源,例如Enemy的Attribute和
* PlayerCharacter的Attribute是不一样的
*/
FGameplayEffectAttributeCaptureDefinition ViggorDef;
};
.cpp文件
// Copyright KimiLiu
#include "AbilitySytstem/ModMagCalc/MMC_MaxHealth.h"
#include "AbilitySytstem/RPGAttributeSet.h"
#include "Interaction/CombatInterface.h"
UMMC_MaxHealth::UMMC_MaxHealth()
{
ViggorDef.AttributeToCapture = URPGAttributeSet::GetVigorAttribute();
ViggorDef.AttributeSource = EGameplayEffectAttributeCaptureSource::Target;
ViggorDef.bSnapshot = false;
RelevantAttributesToCapture.Add(ViggorDef);
}
float UMMC_MaxHealth::CalculateBaseMagnitude_Implementation(const FGameplayEffectSpec& Spec) const
{
// Gather tags from source and target
const FGameplayTagContainer* SourceTags = Spec.CapturedSourceTags.GetAggregatedTags();
const FGameplayTagContainer* TargetTags = Spec.CapturedTargetTags.GetAggregatedTags();
// 暂时未知FAggregatorEvaluateParameters是拿来干嘛用的
FAggregatorEvaluateParameters EvaluateParameters;
EvaluateParameters.SourceTags = SourceTags;
EvaluateParameters.TargetTags = TargetTags;
// 获取Vigor大小
float Vigor = 0.f;
GetCapturedAttributeMagnitude(ViggorDef, Spec, EvaluateParameters, Vigor);
Vigor = FMath::Max<float>(Vigor, 0.f);
//获取Level值
ICombatInterface* CombatInterface = Cast<ICombatInterface>(Spec.GetContext().GetSourceObject());
const int32 PlayerLevel = CombatInterface->GetPlayerLevel();
return 80.f + 2.5*Vigor + 10.f*PlayerLevel;
}
CombatInterface
定义了一个获取Level数值的接口,在CharacterBase中声明实现,在子类中具体实现(Enemy类和PlayerCharacter类),PlayerCharacter的Level存储在PlayerState里面,所以会通过获取到PlayerState再去取Level返回给接口