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

UE5多人MOBA+GAS 番外篇:将冷却缩减属性应用到技能冷却中

在技能基类CGameplayAbility中添加浮点数

	// 技能冷却UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Cooldown")FScalableFloat CooldownDuration;

技能的冷却时长就不放在GE里了,放在技能的里面去设置
在这里插入图片描述

创建一个MMC我就废物利用把之前MMC伤害的直接拿来用了

#pragma once#include "CoreMinimal.h"
#include "GameplayModMagnitudeCalculation.h"
#include "MMC_BaseAttackDamage.generated.h"/*** */
UCLASS()
class UMMC_BaseAttackDamage : public UGameplayModMagnitudeCalculation
{GENERATED_BODY()public:UMMC_BaseAttackDamage();virtual float CalculateBaseMagnitude_Implementation(const FGameplayEffectSpec& Spec) const override;
private:FGameplayEffectAttributeCaptureDefinition CooldownReductionCaptureDef;
};
#include "GAS/MMC/MMC_BaseAttackDamage.h"#include "GAS/Core/CAttributeSet.h"
#include "GAS/Core/CGameplayAbility.h"
#include "GAS/Core/CHeroAttributeSet.h"UMMC_BaseAttackDamage::UMMC_BaseAttackDamage()
{// 获取冷却缩减属性CooldownReductionCaptureDef.AttributeToCapture = UCHeroAttributeSet::GetCooldownReductionAttribute();CooldownReductionCaptureDef.AttributeSource = EGameplayEffectAttributeCaptureSource::Source;// 添加捕获属性RelevantAttributesToCapture.Add(CooldownReductionCaptureDef);
}float UMMC_BaseAttackDamage::CalculateBaseMagnitude_Implementation(const FGameplayEffectSpec& Spec) const
{FAggregatorEvaluateParameters EvalParams;// 绑定源/目标标签EvalParams.SourceTags = Spec.CapturedSourceTags.GetAggregatedTags();EvalParams.TargetTags = Spec.CapturedTargetTags.GetAggregatedTags();// 获取Ability实例const UCGameplayAbility* Ability = Cast<UCGameplayAbility>(Spec.GetContext().GetAbilityInstance_NotReplicated());if (!Ability) return 0.0f;// 获取基础冷却时间float BaseCooldown = Ability->CooldownDuration.GetValueAtLevel(Ability->GetAbilityLevel());// 获取冷却缩减属性值float CooldownReduction = 0.f;//(通过CooldownReductionCaptureDef定义的捕获规则)GetCapturedAttributeMagnitude(CooldownReductionCaptureDef, Spec, EvalParams, CooldownReduction);	// 获取源的属性值// 计算冷却float ActualCooldown = BaseCooldown * (1.0f - CooldownReduction/100.0f);return FMath::Max(0.1f, ActualCooldown);
}

修改一下函数库CAbilitySystemStatics中获取技能冷却的函数GetCooldownDurationFor

float UCAbilitySystemStatics::GetCooldownDurationFor(const UGameplayAbility* AbilityCDO,const UAbilitySystemComponent& ASC, int AbilityLevel)
{float CooldownDuration = 0.f;if (AbilityCDO){const UCGameplayAbility* Ability = Cast<UCGameplayAbility>(AbilityCDO);if (!Ability) return CooldownDuration;// 获取基础冷却时间float BaseCooldown = Ability->CooldownDuration.GetValueAtLevel(AbilityLevel);// 获取冷却缩减属性值bool bFound;float CooldownReduction = ASC.GetGameplayAttributeValue(UCHeroAttributeSet::GetCooldownReductionAttribute(), bFound);if (bFound){// 计算最终冷却时间CooldownDuration = BaseCooldown * (1.0f - CooldownReduction/100.0f);}}// 返回绝对值(确保冷却时间始终为正数)return FMath::Abs(CooldownDuration);
}

冷却的GE的持续时间然后调用计算类把做好的mmc放进去
在这里插入图片描述

初始化的时候修改一下这里
在这里插入图片描述
如此一来算是成功了吗
在这里插入图片描述

在这里插入图片描述

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

相关文章:

  • 常见CMS
  • MCP提示词工程:上下文注入的艺术与科学
  • Visual Studio Code 使用指南 (2025年版)
  • 从硬编码到自主智能体:营销AI的20年技术演进与未来展望
  • LeetCode 283 - 移动零
  • Python 程序设计讲义(27):字符串的用法——字符串的常用操作
  • 三步给小智ESP32S3智能语音硬件接入小程序打通MCP服务
  • 【Linux】pthread学习笔记
  • 专业Python爬虫实战教程:逆向加密接口与验证码突破完整案例
  • ubuntu18.04制作raid0
  • 51c大模型~合集161
  • 代码随想录算法训练营第三十五天
  • 车载刷写架构 --- 整车刷写中为何增加了ECU 队列刷写策略?
  • idea运行tomcat日志乱码问题
  • PostgreSQL锁机制详解:从并发控制到死锁检测
  • STM32——HAL库
  • LangChain和LangGraph 里面的 `create_react_agent`有什么不同
  • 基于SpringBoot和Leaflet集成在线天气服务的区县当前天气WebGIS实战
  • VUE -- 基础知识讲解(一)
  • RabbitMQ工作模式
  • 【C#|C++】C#调用C++导出的dll之非托管的方式
  • C# _泛型
  • python线性回归:从原理到实战应用
  • 在 Vue 中,如何在回调函数中正确使用 this?
  • 单片机学习笔记.PWM
  • linux——ps命令
  • 【tips】小程序css ➕号样式
  • 站点到站点-主模式
  • cartographer 点云数据的预处理
  • 第二十四章:深入CLIP的“心脏”:Vision Transformer (ViT)架构全解析