第一次提交

This commit is contained in:
不明不惑
2026-03-03 01:23:02 +08:00
commit 3e434877e8
1053 changed files with 102411 additions and 0 deletions

View File

@@ -0,0 +1,411 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GGA_AbilitySystemGlobals.h"
#include "CombatFlow/GCS_AttackResult.h"
#include "GCS_CombatSystemComponent.generated.h"
class UGCS_CombatFlow;
/**
* Structure for requesting montage playback.
* 请求蒙太奇播放的结构。
*/
USTRUCT(BlueprintType)
struct GENERICCOMBATSYSTEM_API FGCS_PlayMontageRequest
{
GENERATED_BODY()
/**
* The animation montage to play.
* 要播放的动画蒙太奇。
*/
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="GCS")
TObjectPtr<UAnimMontage> AnimMontage{nullptr};
/**
* The playback rate for the montage.
* 蒙太奇的播放速率。
*/
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="GCS")
float PlayRate{1.0f};
/**
* The starting section name for the montage.
* 蒙太奇的起始片段名称。
*/
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="GCS")
FName StartSectionName{NAME_None};
/**
* The scale for root motion translation.
* 根运动平移的缩放。
*/
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="GCS")
float RootTranslationScale{1.0f};
/**
* The start time for the montage in seconds.
* 蒙太奇的起始时间(秒)。
*/
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="GCS")
float StartTimeSeconds{0.0f};
};
/**
* Structure for predicted montage information.
* 预测蒙太奇信息的结构。
*/
USTRUCT()
struct FGCS_PredictedMontageInfo
{
GENERATED_BODY()
/**
* The animation montage.
* 动画蒙太奇。
*/
UPROPERTY()
TObjectPtr<UAnimMontage> AnimMontage{nullptr};
/**
* The playback rate.
* 播放速率。
*/
UPROPERTY()
float PlayRate{1.0f};
/**
* The starting section name.
* 起始片段名称。
*/
UPROPERTY()
FName StartSectionName{NAME_None};
/**
* The time the montage was triggered.
* 蒙太奇触发的时间。
*/
UPROPERTY()
float TriggeredTime{0.0f};
};
/**
* Structure for replicated montage information.
* 复制蒙太奇信息的结构。
*/
USTRUCT()
struct FGCS_ReplicatedMontageInfo
{
GENERATED_BODY()
/**
* The animation montage.
* 动画蒙太奇。
*/
UPROPERTY()
TObjectPtr<UAnimMontage> AnimMontage{nullptr};
/**
* The playback rate.
* 播放速率。
*/
UPROPERTY()
float PlayRate{1.0f};
/**
* The starting section name.
* 起始片段名称。
*/
UPROPERTY()
FName StartSectionName{NAME_None};
/**
* The time the montage was triggered.
* 蒙太奇触发的时间。
*/
UPROPERTY()
float TriggeredTime{0.0f};
};
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FGCS_ComboStepChangedEventSignature, int32, PrevComboStep);
/**
* Component for handling offensive and defensive combat behaviors.
* 处理进攻和防御战斗行为的组件。
*/
UCLASS(ClassGroup=GCS, Blueprintable, BlueprintType, AutoExpandCategories=("GCS"), meta=(BlueprintSpawnableComponent))
class GENERICCOMBATSYSTEM_API UGCS_CombatSystemComponent : public UActorComponent, public IGGA_AbilitySystemGlobalsEventReceiver
{
GENERATED_BODY()
friend UGCS_CombatFlow;
public:
/**
* Default constructor.
* 默认构造函数。
*/
UGCS_CombatSystemComponent();
/**
* Initializes the component.
* 初始化组件。
*/
virtual void InitializeComponent() override;
/**
* Called when the game starts.
* 游戏开始时调用。
*/
virtual void BeginPlay() override;
/**
* Called when the game ends.
* 游戏结束时调用。
* @param EndPlayReason The reason for ending. 结束原因。
*/
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
/**
* Retrieves lifetime replicated properties.
* 获取生命周期复制属性。
* @param OutLifetimeProps The lifetime properties. 生命周期属性。
*/
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
/**
* Gets the combat system component for an actor.
* 获取演员的战斗系统组件。
* @param Actor The actor to query. 要查询的演员。
* @return The combat system component. 战斗系统组件。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GCS|Combat", Meta = (DefaultToSelf="Actor"))
static UGCS_CombatSystemComponent* GetCombatSystemComponent(const AActor* Actor);
/**
* Finds the combat system component for an actor.
* 查找演员的战斗系统组件。
* @param Actor The actor to query. 要查询的演员。
* @param CombatComponent The found component (output). 找到的组件(输出)。
* @return True if found. 如果找到返回true。
*/
UFUNCTION(BlueprintCallable, Category = "GCS|Combat", Meta = (DefaultToSelf="Actor", ExpandBoolAsExecs = "ReturnValue"))
static bool FindCombatSystemComponent(const AActor* Actor, UGCS_CombatSystemComponent*& CombatComponent);
/**
* Finds a typed combat system component for an actor.
* 查找演员的特定类型战斗系统组件。
* @param Actor The actor to query. 要查询的演员。
* @param DesiredClass The desired component class. 期望的组件类。
* @param Component The found component (output). 找到的组件(输出)。
* @return True if found. 如果找到返回true。
*/
UFUNCTION(BlueprintCallable, Category = "GCS|Combat", meta=(DefaultToSelf="Actor", DeterminesOutputType="DesiredClass", DynamicOutputParam="Component", ExpandBoolAsExecs="ReturnValue"))
static bool FindTypedCombatSystemComponent(AActor* Actor, TSubclassOf<UGCS_CombatSystemComponent> DesiredClass, UGCS_CombatSystemComponent*& Component);
/**
* Gets the combat flow for handling incoming attacks.
* 获取处理传入攻击的战斗流程。
* @return The combat flow instance. 战斗流程实例。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GCS|Combat", meta=(DisplayName="Get Combat Flow"))
UGCS_CombatFlow* GetCombatFlow() const;
/**
* Registers an attack result.
* 注册攻击结果。
* @param Payload The attack result to register. 要注册的攻击结果。
*/
UFUNCTION(BlueprintCallable, Category="GCS|Combat")
void RegisterAttackResult(UPARAM(ref)
FGCS_AttackResult& Payload);
/**
* Gets the last processed attack result.
* 获取最后处理的攻击结果。
* @return The last attack result. 最后攻击结果。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GCS|Combat")
FGCS_AttackResult GetLastProcessedAttackResult() const;
/**
* Sets the last processed attack result.
* 设置最后处理的攻击结果。
* @param Payload The attack result to set. 要设置的攻击结果。
*/
UFUNCTION(BlueprintCallable, Category = "GCS|Combat")
void SetLastProcessedAttackResult(const FGCS_AttackResult& Payload);
/**
* Plays a predictable montage for a target combat system component.
* 为目标战斗系统组件播放可预测的蒙太奇。
* @param TargetCSC The target combat system component. 目标战斗系统组件。
* @param Request The montage play request. 蒙太奇播放请求。
*/
UFUNCTION(BlueprintCallable, Category="GCS|Combat")
void PlayPredictableMontageForTarget(UGCS_CombatSystemComponent* TargetCSC, FGCS_PlayMontageRequest Request);
/**
* Server RPC to play a predictable montage for a target.
* 为目标播放可预测蒙太奇的服务器RPC。
* @param TargetCSC The target combat system component. 目标战斗系统组件。
* @param Request The montage play request. 蒙太奇播放请求。
*/
UFUNCTION(Server, Reliable, BlueprintCallable, Category="GCS|Combat")
void ServerPlayPredictableMontageForTarget(UGCS_CombatSystemComponent* TargetCSC, FGCS_PlayMontageRequest Request);
/**
* Sets the replicated montage information.
* 设置复制的蒙太奇信息。
* @param Request The montage play request. 蒙太奇播放请求。
*/
void SetReplicatedMontage(const FGCS_PlayMontageRequest& Request);
/**
* Timer handle for montage-related operations.
* 蒙太奇相关操作的计时器句柄。
*/
FTimerHandle TimerHandle;
/**
* Handles replication of montage information.
* 处理蒙太奇信息的复制。
*/
UFUNCTION()
void OnRep_ReplicatedMontageInfo();
/**
* Plays a predicted montage.
* 播放预测的蒙太奇。
* @param Request The montage play request. 蒙太奇播放请求。
*/
void PlayPredictedMontage(const FGCS_PlayMontageRequest& Request);
/**
* Gets the character's skeletal mesh component.
* 获取角色的骨骼网格组件。
* @return The skeletal mesh component. 骨骼网格组件。
*/
USkeletalMeshComponent* GetCharacterMeshComponent() const;
protected:
/**
* Handles pre-gameplay effect spec application.
* 处理游戏效果规格应用前逻辑。
* @param Spec The gameplay effect spec. 游戏效果规格。
* @param AbilitySystemComponent The ability system component. 能力系统组件。
*/
virtual void OnGlobalPreGameplayEffectSpecApply(FGameplayEffectSpec& Spec, UAbilitySystemComponent* AbilitySystemComponent) override;
/**
* Handles replication of the combat flow.
* 处理战斗流程的复制。
*/
UFUNCTION()
void OnRep_CombatFlow();
/**
* The class of the combat flow to instantiate.
* 要实例化的战斗流程类。
*/
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "GCS|Combat Settings")
TSubclassOf<UGCS_CombatFlow> CombatFlowClass;
/**
* The instantiated combat flow.
* 实例化的战斗流程。
*/
UPROPERTY(VisibleAnywhere, ReplicatedUsing=OnRep_CombatFlow, Category = "GCS|Combat State", meta=(ShowInnerProperties))
TObjectPtr<UGCS_CombatFlow> CombatFlow;
/**
* The last attack result processed by the combat flow.
* 战斗流程处理的最后攻击结果。
*/
UPROPERTY(VisibleAnywhere, Category = "GCS|Combat State")
FGCS_AttackResult LastProcessedAttackResult;
/**
* Container for attack results.
* 攻击结果容器。
*/
UPROPERTY(VisibleAnywhere, Replicated, Category="GCS|Combat State")
FGCS_AttackResultContainer AttackResultContainer;
/**
* Replicated montage information.
* 复制的蒙太奇信息。
*/
UPROPERTY(VisibleAnywhere, ReplicatedUsing=OnRep_ReplicatedMontageInfo, Category = "GCS|Combat State")
FGCS_ReplicatedMontageInfo ReplicatedMontageInfo;
/**
* Predicted montage information.
* 预测的蒙太奇信息。
*/
UPROPERTY(VisibleAnywhere, Category = "GCS|Combat State")
FGCS_PredictedMontageInfo PredictedMontageInfo;
#pragma region Combo System
public:
/**
* Get the current combo step.
* @return The current combo step.
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GMS|Combat")
int32 GetComboStep() const;
UFUNCTION(BlueprintCallable, Category="GCS|Combat")
void UpdateComboStep(int32 NewComboStep);
UFUNCTION(BlueprintCallable, Category="GCS|Combat")
virtual void ResetComboState();
/**
* Event for combo step changed.
* 连击步骤变更事件。
*/
UPROPERTY(BlueprintAssignable, Category="Event")
FGCS_ComboStepChangedEventSignature OnComboStepChangedEvent;
private:
void UpdateComboStep(int32 NewComboStep, bool bSendRpc);
UFUNCTION()
void OnReplicated_ComboStep(int32 PrevComboStep);
/**
* Client RPC to set the combo step.
* 客户端RPC设置运动集。
* @param NewComboStep combo step. 新运动集。
*/
UFUNCTION(Client, Reliable, WithValidation)
void ClientUpdateComboStep(int32 NewComboStep);
/**
* Server RPC to set the combo step.
* 服务器RPC设置运动集。
* @param NewComboStep The new combo step. 新运动集。
*/
UFUNCTION(Server, Reliable, WithValidation)
void ServerUpdateComboStep(int32 NewComboStep);
protected:
virtual bool ClientUpdateComboStep_Validate(int32 NewComboStep);
virtual bool ServerUpdateComboStep_Validate(int32 NewComboStep);
UFUNCTION(BlueprintNativeEvent, Category="GMS|Combat")
void OnComboStepChanged(int32 PrevComboStep);
virtual void OnComboStepChanged_Implementation(int32 PrevComboStep);
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, ReplicatedUsing=OnReplicated_ComboStep, Category = "GCS|Combat State")
int32 ComboStep{0};
private:
#pragma endregion
};