当前位置: 首页 > web >正文

UE5多人MOBA+GAS 19、创建升龙技能,以及带力的被动,为升龙技能添加冷却和消耗

文章目录

  • 创建升龙拳的Tag以及受力被动的Tag
  • 创建升龙技能
    • 将升龙技能添加到角色中
    • 创建一个击飞被动,供升龙激活技能
  • 为技能添加冷却以及消耗


创建升龙拳的Tag以及受力被动的Tag

给这个技能添加标签

CRUNCH_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(Ability_Uppercut_Launch)
CRUNCH_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(Ability_Passive_Launch_Activate)
UE_DEFINE_GAMEPLAY_TAG_COMMENT(Ability_Uppercut_Launch, "Ability.Uppercut.Launch", "升龙拳攻击")
UE_DEFINE_GAMEPLAY_TAG_COMMENT(Ability_Passive_Launch_Activate, "Ability.Passive.Launch.Activate", "击飞被动技能激活")

CGameplayAbility中添加绘制Debug的布尔变量(暂时对我没的没什么用)

	UFUNCTION()FORCEINLINE bool ShouldDrawDebug() const { return bShouldDrawDebug; }
private:UPROPERTY(EditDefaultsOnly, Category = "Debug")bool bShouldDrawDebug = false;

创建升龙技能

添加上勾拳(升龙拳)技能,命名为UpperCut
在这里插入图片描述

// 幻雨喜欢小猫咪#pragma once#include "CoreMinimal.h"
#include "GAS/Core/CGameplayAbility.h"
#include "UpperCut.generated.h"/*** */
UCLASS()
class CRUNCH_API UUpperCut : public UCGameplayAbility
{GENERATED_BODY()
public:	// 激活技能时调用virtual void ActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEventData* TriggerEventData) override;
private:// 上勾拳动画MontageUPROPERTY(EditDefaultsOnly, Category = "Animation")TObjectPtr<UAnimMontage> UpperCutMontage;// 启动击飞效果UFUNCTION()void StartLaunching(FGameplayEventData EventData);
};
// 幻雨喜欢小猫咪#include "UpperCut.h"#include "Abilities/Tasks/AbilityTask_PlayMontageAndWait.h"void UUpperCut::ActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo,const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEventData* TriggerEventData)
{if (!K2_CommitAbility()){K2_EndAbility();return;}// 服务器执行if (HasAuthorityOrPredictionKey(ActorInfo, &ActivationInfo)){UAbilityTask_PlayMontageAndWait* PlayUpperCutMontageTask = UAbilityTask_PlayMontageAndWait::CreatePlayMontageAndWaitProxy(this, NAME_None, UpperCutMontage);PlayUpperCutMontageTask->OnBlendOut.AddDynamic(this, &UUpperCut::K2_EndAbility);PlayUpperCutMontageTask->OnCancelled.AddDynamic(this, &UUpperCut::K2_EndAbility);PlayUpperCutMontageTask->OnCompleted.AddDynamic(this, &UUpperCut::K2_EndAbility);PlayUpperCutMontageTask->OnInterrupted.AddDynamic(this, &UUpperCut::K2_EndAbility);PlayUpperCutMontageTask->ReadyForActivation();UAbilityTask_WaitGameplayEvent* WaitLaunchEventTask = UAbilityTask_WaitGameplayEvent::WaitGameplayEvent(this, TGameplayTags::Ability_Uppercut_Launch);WaitLaunchEventTask->EventReceived.AddDynamic(this, &UUpperCut::StartLaunching);WaitLaunchEventTask->ReadyForActivation();}
}void UUpperCut::StartLaunching(FGameplayEventData EventData)
{if (K2_HasAuthority()){// 获取命中目标的数量int32 HitResultCount = UAbilitySystemBlueprintLibrary::GetDataCountFromTargetData(EventData.TargetData);for (int32 i = 0; i < HitResultCount; ++i){// 获取每个命中的HitResultFHitResult HitResult = UAbilitySystemBlueprintLibrary::GetHitResultFromTargetData(EventData.TargetData, i);UE_LOG(LogTemp, Warning, TEXT("HitActorName:  %s"), *HitResult.GetActor()->GetName())}}
}

将升龙技能添加到角色中

蓝图继承并创建
在这里插入图片描述
在这里插入图片描述
直接复制基础攻击增加一个技能一
在这里插入图片描述
添加到映射中
在这里插入图片描述

将技能添加到角色中
在这里插入图片描述

创建一个击飞被动,供升龙激活技能

添加一个新的类GAP_Launched,作为击飞的被动技能
在这里插入图片描述

// 幻雨喜欢小猫咪#pragma once#include "CoreMinimal.h"
#include "GAS/Core/CGameplayAbility.h"
#include "GAP_Launched.generated.h"/*** 被击飞能力类* 用于处理角色被击飞时的特殊能力逻辑*/
UCLASS()
class UGAP_Launched : public UCGameplayAbility
{GENERATED_BODY()
public:// 构造函数UGAP_Launched();// 激活能力时调用virtual void ActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEventData* TriggerEventData) override;// 获取击飞激活事件Tagstatic FGameplayTag GetLaunchedAbilityActivationTag();
};
// 幻雨喜欢小猫咪#include "GAP_Launched.h"#include "GAS/Core/TGameplayTags.h"UGAP_Launched::UGAP_Launched()
{// 设置网络执行策略为仅在服务器端执行NetExecutionPolicy = EGameplayAbilityNetExecutionPolicy::ServerOnly;// 创建一个新的触发数据对象FAbilityTriggerData TriggerData;// 设置触发数据的触发源为游戏事件TriggerData.TriggerSource = EGameplayAbilityTriggerSource::GameplayEvent;// 设置触发数据的触发标签为击飞被动技能激活标签TriggerData.TriggerTag = TGameplayTags::Ability_Passive_Launch_Activate;// 将创建好的触发数据添加到能力触发器列表中AbilityTriggers.Add(TriggerData);
}void UGAP_Launched::ActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo,const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEventData* TriggerEventData)
{if (!K2_CommitAbility()){K2_EndAbility();return;}if (K2_HasAuthority()){// 推自己PushSelf(TriggerEventData->TargetData.Get(0)->GetHitResult()->ImpactNormal);K2_EndAbility();}
}FGameplayTag UGAP_Launched::GetLaunchedAbilityActivationTag()
{return TGameplayTags::Ability_Passive_Launch_Activate;
}

CGameplayAbility中添加推动自身的力

	// 推动自己(如击退/击飞)void PushSelf(const FVector& PushVel);void PushTarget(AActor* Target, const FVector& PushVel);// 获取拥有者角色指针ACharacter* GetOwningAvatarCharacter();
private:// 缓存的拥有者角色指针UPROPERTY()TObjectPtr<ACharacter> AvatarCharacter;
void UCGameplayAbility::PushSelf(const FVector& PushVel)
{ACharacter* OwningAvatarCharacter = GetOwningAvatarCharacter();if (OwningAvatarCharacter){OwningAvatarCharacter->LaunchCharacter(PushVel, true, true);}
}void UCGameplayAbility::PushTarget(AActor* Target, const FVector& PushVel)
{// 目标为空则返回if (!Target) return;FGameplayEventData EventData;// 创建单目标命中数据对象FGameplayAbilityTargetData_SingleTargetHit* HitData = new FGameplayAbilityTargetData_SingleTargetHit;// 配置命中结果参数FHitResult HitResult;HitResult.ImpactNormal = PushVel; // 设置冲击方向为力的方向HitData->HitResult = HitResult;EventData.TargetData.Add(HitData);// 用标签激活技能UAbilitySystemBlueprintLibrary::SendGameplayEventToActor(Target, UGAP_Launched::GetLaunchedAbilityActivationTag(), EventData);
}ACharacter* UCGameplayAbility::GetOwningAvatarCharacter()
{if (!AvatarCharacter){AvatarCharacter = Cast<ACharacter>(GetAvatarActorFromActorInfo());}return AvatarCharacter;
}

回到升龙技能中,实现力技能的添加,再添加一个伤害效果

    // 上勾拳击飞阶段的伤害效果UPROPERTY(EditDefaultsOnly, Category = "Launch")TSubclassOf<UGameplayEffect> LaunchDamageEffect;// 上勾拳击飞速度UPROPERTY(EditDefaultsOnly, Category = "Launch", meta = (DisplayName = "击飞力的大小"))float UpperCutLaunchSpeed = 1000.f;
void UUpperCut::StartLaunching(FGameplayEventData EventData)
{if (K2_HasAuthority()){// 获取命中目标的数量int32 HitResultCount = UAbilitySystemBlueprintLibrary::GetDataCountFromTargetData(EventData.TargetData);// 推动自己向上PushTarget(GetAvatarActorFromActorInfo(), FVector::UpVector * UpperCutLaunchSpeed);for (int32 i = 0; i < HitResultCount; ++i){// 获取每个命中的HitResultFHitResult HitResult = UAbilitySystemBlueprintLibrary::GetHitResultFromTargetData(EventData.TargetData, i);PushTarget(HitResult.GetActor(), FVector::UpVector * UpperCutLaunchSpeed);ApplyGameplayEffectToHitResultActor(HitResult, LaunchDamageEffect, GetAbilityLevel(CurrentSpecHandle, CurrentActorInfo));}}
}

为角色添加基础技能,因为是通过tag触发的,所以不用管输入
在这里插入图片描述
创建一个GE
在这里插入图片描述
在这里插入图片描述
然后一个升龙拳双方都起飞了
在这里插入图片描述

为技能添加冷却以及消耗

创建一个tag表示升龙的冷却,在冷却标签存在的时间内是无法再次使用此技能。

CRUNCH_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(Ability_Uppercut_Cooldown)
UE_DEFINE_GAMEPLAY_TAG_COMMENT(Ability_Uppercut_Cooldown, "Ability.Uppercut.Cooldown", "升龙拳技能冷却")

创建一个GE来设置拥有持续时间,在GA的冷却中添加该GE
在这里插入图片描述
将CD添加到GA中
在这里插入图片描述
创建一个GE作为开销
在这里插入图片描述
在这里插入图片描述
用技能就会耗蓝了
在这里插入图片描述

http://www.xdnf.cn/news/15364.html

相关文章:

  • 【408考研知识点全面讲解计算机学科专业基础综合(408)】——数据结构之排序
  • SELECT ... INTO OUTFILE和LOAD DATA INFILE
  • 请求服务端获取broker的机房归属信息异常
  • 【C#】GraphicsPath的用法
  • ai批量抠图win和mac都可以用
  • 数据库连接池及其核心特点
  • Spring Boot整合MyBatis+MySQL+Redis单表CRUD教程
  • OneCode 3.0 DDD领域模型开放接口:基于DSMFactory的架构解析与实践指南
  • 创建 UIKit 项目教程
  • 浅谈npm,cnpm,pnpm,npx,nvm,yarn之间的区别
  • 周末总结(2024/07/12)
  • 小架构step系列12:单元测试
  • 为什么有些PDF无法复制文字?原理分析与解决方案
  • 知识宇宙-思考篇:AI大模型如何重塑软件开发流程?
  • MCP选型指南:AWS vs Azure vs GCP vs 国内云厂商深度对比
  • openGauss 的列式存储表时遇到的排序和聚合查询性能问题
  • mybatis模糊匹配采用concat与#{},动态sql讲解
  • Flutter、React Native、Uni-App 的比较与分析
  • 80. 删除有序数组中的重复项 II
  • brpc中bthread_start_urgent和tls_task_group详细机制分析
  • 使用python 实现一个http server
  • 传感器WSNs TheDataLinkLayer——X-MAC
  • 基于随机森林的金融时间序列预测系统:从数据处理到实时预测的完整流水线
  • [特殊字符] 实时数据洪流突围战:Flink+Paimon实现毫秒级分析的架构革命(附压测报告)——日均百亿级数据处理成本降低60%的工业级方案
  • 【离线数仓项目】——电商域DWS层开发实战
  • 使用FastAdmin框架开发
  • 蒙特卡洛树搜索方法实践
  • 【云端深度学习训练与部署平台】AutoDL连接VSCode运行深度学习项目的全流程
  • C# 接口(派生成员作为实现)
  • 钉钉企业应用开发实战:从零构建组织级业务工具