首页 > 其他分享 >ActionRPG-3-RPGGameAbility

ActionRPG-3-RPGGameAbility

时间:2023-05-20 15:01:13浏览次数:35  
标签:include const OverrideGameplayLevel RPGGameAbility ActionRPG EventData FRPGGamep

#pragma once

#include "ActionRPG.h"
#include "Abilities/GameplayAbility.h"
#include "Abilities/RPGAbilityTypes.h"
#include "RPGGameplayAbility.generated.h"

/**
 * Subclass of ability blueprint type with game-specific data
 * This class uses GameplayEffectContainers to allow easier execution of gameplay effects based on a triggering tag
 * Most games will need to implement a subclass to support their game-specific code
 */
UCLASS()
class ACTIONRPG_API URPGGameplayAbility : public UGameplayAbility
{
	GENERATED_BODY()

public:
	// Constructor and overrides
	URPGGameplayAbility();

	/**
     * Map of gameplay tags to gameplay effect containers
     * 游戏标签到游戏效果容器的map
     */
	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = GameplayEffects)
	TMap<FGameplayTag, FRPGGameplayEffectContainer> EffectContainerMap;

	/**
     * @brief Make gameplay effect container spec to be applied later, using the passed in container
     *        根据给定的GE容器创建GE容器的规范
     * @param Container 给定的容器,包含一组GE
     * @param EventData 传递的游戏事件的数据
     */
	UFUNCTION(BlueprintCallable, Category = Ability, meta=(AutoCreateRefTerm = "EventData"))
	virtual FRPGGameplayEffectContainerSpec MakeEffectContainerSpecFromContainer(const FRPGGameplayEffectContainer& Container, const FGameplayEventData& EventData, int32 OverrideGameplayLevel = -1);

	/**
     * @brief Search for and make a gameplay effect container spec to be applied later, from the EffectContainerMap
     *        从EffectContainerMap中搜索并制作稍后应用的游戏效果容器规范
     */
	UFUNCTION(BlueprintCallable, Category = Ability, meta = (AutoCreateRefTerm = "EventData"))
	virtual FRPGGameplayEffectContainerSpec MakeEffectContainerSpec(FGameplayTag ContainerTag, const FGameplayEventData& EventData, int32 OverrideGameplayLevel = -1);

	/**
     * @brief Applies a gameplay effect container spec that was previously created
     *        应用先前创建的游戏效果容器规范
     */
	UFUNCTION(BlueprintCallable, Category = Ability)
	virtual TArray<FActiveGameplayEffectHandle> ApplyEffectContainerSpec(const FRPGGameplayEffectContainerSpec& ContainerSpec);

	/**
     * @brief Applies a gameplay effect container, by creating and then applying the spec
     *        通过创建并应用规范,应用游戏效果容器
     */
	UFUNCTION(BlueprintCallable, Category = Ability, meta = (AutoCreateRefTerm = "EventData"))
	virtual TArray<FActiveGameplayEffectHandle> ApplyEffectContainer(FGameplayTag ContainerTag, const FGameplayEventData& EventData, int32 OverrideGameplayLevel = -1);
};

 

#include "Abilities/RPGGameplayAbility.h"
#include "Abilities/RPGAbilitySystemComponent.h"
#include "Abilities/RPGTargetType.h"
#include "RPGCharacterBase.h"

URPGGameplayAbility::URPGGameplayAbility() {}

FRPGGameplayEffectContainerSpec URPGGameplayAbility::MakeEffectContainerSpecFromContainer(const FRPGGameplayEffectContainer& Container,
                                                                                          const FGameplayEventData& EventData,
                                                                                          int32 OverrideGameplayLevel) {
	// First figure out our actor info
	FRPGGameplayEffectContainerSpec ReturnSpec;
	AActor* OwningActor = GetOwningActorFromActorInfo();
	ARPGCharacterBase* OwningCharacter = Cast<ARPGCharacterBase>(OwningActor);
	URPGAbilitySystemComponent* OwningASC = URPGAbilitySystemComponent::GetAbilitySystemComponentFromActor(OwningActor);

	if (OwningASC) {
		// If we have a target type, run the targeting logic. This is optional, targets can be added later
        // // 如果我们有一个目标类型,那么运行目标逻辑。这是可选的,以后可以添加目标
		if (Container.TargetType.Get()) {
			TArray<FHitResult> HitResults;
			TArray<AActor*> TargetActors;
			const URPGTargetType* TargetTypeCDO = Container.TargetType.GetDefaultObject();
			AActor* AvatarActor = GetAvatarActorFromActorInfo();
			TargetTypeCDO->GetTargets(OwningCharacter, AvatarActor, EventData, HitResults, TargetActors);
			ReturnSpec.AddTargets(HitResults, TargetActors);
		}
		// If we don't have an override level, use the default on the ability itself
        // 如果我们没有覆盖级别,请对功能本身使用默认级别
		if (OverrideGameplayLevel == INDEX_NONE) {
			OverrideGameplayLevel = OverrideGameplayLevel = this->GetAbilityLevel(); //OwningASC->GetDefaultAbilityLevel();
		}
		// Build GameplayEffectSpecs for each applied effect
        // 为每个应用的效果构建GESpecs
		for (const TSubclassOf<UGameplayEffect>& EffectClass : Container.TargetGameplayEffectClasses)
		{
			ReturnSpec.TargetGameplayEffectSpecs.Add(MakeOutgoingGameplayEffectSpec(EffectClass, OverrideGameplayLevel));
		}
	}
	return ReturnSpec;
}

FRPGGameplayEffectContainerSpec URPGGameplayAbility::MakeEffectContainerSpec(FGameplayTag ContainerTag,
                                                                             const FGameplayEventData& EventData,
                                                                             int32 OverrideGameplayLevel) {
	FRPGGameplayEffectContainer* FoundContainer = EffectContainerMap.Find(ContainerTag);

	if (FoundContainer)
	{
		return MakeEffectContainerSpecFromContainer(*FoundContainer, EventData, OverrideGameplayLevel);
	}
	return FRPGGameplayEffectContainerSpec();
}

TArray<FActiveGameplayEffectHandle> URPGGameplayAbility::ApplyEffectContainerSpec(const FRPGGameplayEffectContainerSpec& ContainerSpec) {
	TArray<FActiveGameplayEffectHandle> AllEffects;
	// Iterate list of effect specs and apply them to their target data
    // 迭代效果规格列表,并将其应用于目标数据
	for (const FGameplayEffectSpecHandle& SpecHandle : ContainerSpec.TargetGameplayEffectSpecs) {
		AllEffects.Append(K2_ApplyGameplayEffectSpecToTarget(SpecHandle, ContainerSpec.TargetData));
	}
	return AllEffects;
}

TArray<FActiveGameplayEffectHandle> URPGGameplayAbility::ApplyEffectContainer(FGameplayTag ContainerTag,
                                                                              const FGameplayEventData& EventData,
                                                                              int32 OverrideGameplayLevel) {
	FRPGGameplayEffectContainerSpec Spec = MakeEffectContainerSpec(ContainerTag, EventData, OverrideGameplayLevel);
	return ApplyEffectContainerSpec(Spec);
}

 

标签:include,const,OverrideGameplayLevel,RPGGameAbility,ActionRPG,EventData,FRPGGamep
From: https://www.cnblogs.com/ikun-proto/p/17417237.html

相关文章

  • UE ActionRPG 项目拆解(一):熟悉 ActionRPG 有哪些功能
    依次点击“编辑”—>“项目设置“—>“输入”,查看游戏功能的默认快捷键。打开BP_PlayerCharacter蓝图重载IsAlive函数,使其始终返回true(这样我们操控的人物即使没血了也不会死亡,从而避免因为死亡导致游戏结束而影响我们游玩游戏的整个流程) ......
  • UE ActionRPG 项目拆解(三):默认武器斧子的 NormalAttack 技能对应哪个 GA ?
    参考官方文档:添加新的武器我们知道:每个武器都对应了 Items\Weapons文件下的某个“数据资产”(里面定义了该武器的名称、价格、技能等)。 在项目内容浏览器中找到默认武器(斧子)的蓝图GreateBladeActor,尝试删除它(可以看到它关联的“数据资产”是Weapon_Axe)打开“数据资产”......
  • UE ActionRPG 项目拆解(二):默认武器斧子的 Normal Attack 技能为着手点,了解 GAS 的使用
    按键触发技能绑定(按下NormalAttack绑定的快捷键时,调用DoMeleeAttack函数)DoMeleeAttack函数中,调用ActivateAbilitiesWithItemSlot函数ActivateAbilitiesWithItemSlot函数中,调用了 AbilitySystemComponent->TryActivateAbility()函数至此我们知道:按下NormalAttack绑......
  • ActionRPG 项目拆解
    准备工作(熟悉ActionRPG有哪些功能)(1)依次点击“编辑”—>“项目设置“—>“输入”,查看游戏功能的默认快捷键。 (2)打开BP_PlayerCharacter蓝图重载IsAlive函数,使其始终返回true(这样我们操控的人物即使没血了也不会死亡了,省得老死亡浪费时间) (3)打开BP_EnemyCharacte......
  • ActionRPG解读(开始游戏逻辑)
    ActionRPG解读(开始游戏逻辑)数据结构RPGItem先看数据类型。游戏中的右下角有一些图标,包括药剂、武器等,这些都可以抽象为RPGItem,根据类别不同,派生出更具体的RPGPotionI......
  • 官方ActionRPG案例浅析
    零、开篇ActionRPG(以下简称示例)是官方GAS系统的使用示例,可于虚幻商城免费下载。本篇教程将围绕UEGameplay框架,GAS做浅析,逐步了解在动作游戏中,官方对虚幻的Gameplay框架......