ActionRPG-1-RPGAbilitySystemComponent
技能系统组件(AbilitySystemComponent)是整个GAS的核心,用于管理各种技能和处理技能系统的所有交互
该组件附加在需要拥有技能的角色上,并可以把技能赋予角色
#pragma once
#include "ActionRPG.h"
#include "AbilitySystemComponent.h"
#include "Abilities/RPGAbilityTypes.h"
#include "RPGAbilitySystemComponent.generated.h"
class URPGGameplayAbility;
/**
* Subclass of ability system component with game-specific data
* Most games will need to make a game-specific subclass to provide utility functions
*/
UCLASS()
class ACTIONRPG_API URPGAbilitySystemComponent : public UAbilitySystemComponent
{
GENERATED_BODY()
public:
// Constructors and overrides
URPGAbilitySystemComponent();
/**
* @brief Returns a list of currently active ability instances that match the tags
* @brief 返回与标记匹配的当前活动能力实例的列表
* @param GameplayTagContainer
* @param ActiveAbilities
*/
void GetActiveAbilitiesWithTags(const FGameplayTagContainer& GameplayTagContainer, TArray<URPGGameplayAbility*>& ActiveAbilities);
/**
* @brief Returns the default level used for ability activations, derived from the character
* @brief 返回用于从角色派生的能力激活的默认级别
*/
int32 GetDefaultAbilityLevel() const;
/**
* @brief Version of function in AbilitySystemGlobals that returns correct type
* @brief AbilitySystemGlobals中返回正确类型的函数的版本
*/
static URPGAbilitySystemComponent* GetAbilitySystemComponentFromActor(const AActor* Actor, bool LookForComponent = false);
};
#include "Abilities/RPGAbilitySystemComponent.h"
#include "RPGCharacterBase.h"
#include "Abilities/RPGGameplayAbility.h"
#include "AbilitySystemGlobals.h"
URPGAbilitySystemComponent::URPGAbilitySystemComponent() {}
void URPGAbilitySystemComponent::GetActiveAbilitiesWithTags(const FGameplayTagContainer& GameplayTagContainer, TArray<URPGGameplayAbility*>& ActiveAbilities) {
TArray<FGameplayAbilitySpec*> AbilitiesToActivate;
// 通过匹配标签获取可激活的GA列表。第一个参数表示协议匹配的标签契合,第二个参数表示函数输出的结果,第三个参数表示知否只查找已激活的GA
GetActivatableGameplayAbilitySpecsByAllMatchingTags(GameplayTagContainer, AbilitiesToActivate, false);
// Iterate the list of all ability specs
for (FGameplayAbilitySpec* Spec : AbilitiesToActivate) {
// Iterate all instances on this ability spec
TArray<UGameplayAbility*> AbilityInstances = Spec->GetAbilityInstances();
for (UGameplayAbility* ActiveAbility : AbilityInstances) {
ActiveAbilities.Add(Cast<URPGGameplayAbility>(ActiveAbility));
}
}
}
int32 URPGAbilitySystemComponent::GetDefaultAbilityLevel() const {
ARPGCharacterBase* OwningCharacter = Cast<ARPGCharacterBase>(GetOwnerActor());
if (OwningCharacter) {
return OwningCharacter->GetCharacterLevel();
}
return 1;
}
URPGAbilitySystemComponent* URPGAbilitySystemComponent::GetAbilitySystemComponentFromActor(const AActor* Actor, bool LookForComponent) {
return Cast<URPGAbilitySystemComponent>(UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(Actor, LookForComponent));
}

浙公网安备 33010602011771号