Lua向C#逻辑迁移 一期 #13

狐狸移动,技能迁移和完善
This commit is contained in:
2025-10-26 15:46:04 +08:00
parent dab9990b44
commit 8c0623b397
28 changed files with 605 additions and 323 deletions

View File

@ -1,5 +1,7 @@
#include "BlueprintLibrary/BusyAscLibrary.h"
#include "AbilitySystemComponent.h"
#include "AbilitySystemGlobals.h"
#include "GameplayEffectTypes.h"
#include "Gas/BusyGameAbility.h"
@ -18,3 +20,11 @@ AActor* UBusyAscLibrary::GetEffectInstigator(const FGameplayEffectSpec& Spec)
return Spec.GetEffectContext().GetInstigator();
}
FGameplayEffectSpecHandle UBusyAscLibrary::MakeGameplayEffectSpecHandle(const UAbilitySystemComponent* Asc, const UGameplayEffect* Effect, const float Level)
{
const FGameplayEffectContextHandle ContextHandle = Asc->MakeEffectContext();
FGameplayEffectSpec && Spec = FGameplayEffectSpec(Effect, ContextHandle, Level);
FGameplayEffectSpec* NewSpec = new FGameplayEffectSpec(Effect, ContextHandle, Level);
return FGameplayEffectSpecHandle(NewSpec);
}

View File

@ -2,12 +2,26 @@
#include "AbilitySystemBlueprintLibrary.h"
#include "AbilitySystemComponent.h"
UBusyGameAbility::UBusyGameAbility()
#pragma optimize("", off)
void UBusyGameAbility::OnGiveAbility(const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilitySpec& Spec)
{
Super::OnGiveAbility(ActorInfo, Spec);
Data = SoftDataAsset.LoadSynchronous();
if (Data)
{
Data->TargetAbility = this;
}
K2_OnGiveAbility(*ActorInfo, Spec);
}
void UBusyGameAbility::K2_OnGiveAbility_Implementation(const FGameplayAbilityActorInfo& ActorInfo, const FGameplayAbilitySpec& Spec)
{
}
bool UBusyGameAbility::GetAbilityEffectSpecHandle(const FName& EffectName, const UAbilitySystemComponent* Asc, const int32 Level,
FGameplayEffectSpecHandle& Handle) const
FGameplayEffectSpecHandle& Handle) const
{
// 1. 查找对应的GameplayEffectClass
const TSubclassOf<UGameplayEffect> *EffectClass = AbilityEffects.Find(EffectName);
@ -25,13 +39,3 @@ bool UBusyGameAbility::GetAbilityEffectSpecHandle(const FName& EffectName, const
return Handle.IsValid();
}
void UBusyGameAbility::PostInitProperties()
{
Super::PostInitProperties();
if (SoftDataAsset)
{
Data = SoftDataAsset.LoadSynchronous();
Data->TargetAbility = this;
}
}

View File

@ -0,0 +1,38 @@
#include "Gas/BusyGameplayEffectSubSystem.h"
#include "GameplayEffect.h"
#include "GameplayEffectComponents/TargetTagsGameplayEffectComponent.h"
UGameplayEffect* UBusyGameplayEffectSubSystem::GetTagGrantEffectWithDuration(const FGameplayTagContainer& TagsAdd,
const FGameplayTagContainer& TagsRemove, const float Duration, const float Period)
{
UGameplayEffect* Effect = nullptr;
if (EffectsPool.IsEmpty())
{
Effect = NewObject<UGameplayEffect>(this);
Effect->Period = Period;
if (Duration > 0)
{
Effect->DurationPolicy = EGameplayEffectDurationType::HasDuration;
Effect->DurationMagnitude = FGameplayEffectModifierMagnitude(Duration);
}
else
{
Effect->DurationPolicy = EGameplayEffectDurationType::Infinite;
}
}
else
{
Effect = EffectsPool.Pop();
}
FInheritedTagContainer Container;
UTargetTagsGameplayEffectComponent& Component = Effect->FindOrAddComponent<UTargetTagsGameplayEffectComponent>();
Container.Added = TagsAdd;
Container.CombinedTags = TagsAdd;
Container.Removed = TagsRemove;
Component.SetAndApplyTargetTagChanges(Container);
return Effect;
}

View File

@ -85,8 +85,5 @@ void ABusyPawnBase::BindGameplayTagAddOrRemove(const FGameplayTag& Tag, FGamepla
);
}
void ABusyPawnBase::InitCollision()
{
}

View File

@ -84,6 +84,7 @@ void UBusyPawnMovement::TickComponent(float DeltaTime, ELevelTick TickType,
}
#pragma optimize("", off)
void UBusyPawnMovement::MoveTick(const float DeltaTime)
{
@ -121,9 +122,10 @@ void UBusyPawnMovement::MoveTick(const float DeltaTime)
}
if (!NewDirection.Equals(LastMoveDirection))
{
Movable->Execute_OnMoveDirectionChanged(Owner, NewDirection);
MoveDirectionChangedDelegate.Broadcast(NewDirection);
LastMoveDirection = NewDirection;
}
}
void UBusyPawnMovement::SprintTick(const float DeltaTime)

View File

@ -148,41 +148,6 @@ void ALevelPlayerController::SwitchControlledRole(ABusyPlayerRole* Target)
this->Possess(Target);
}
void ALevelPlayerController::OnMove(const FInputActionValue& Value) const
{
AActor* ControlledRole = GetControlledRole();
if (!ControlledRole) return;
IBusyControllable *Controllable = Cast<IBusyControllable>(ControlledRole);
if (!Controllable) return;
if (FVector2D Position; GetCursorPosition(Position))
{
Controllable->Execute_OnMove(ControlledRole, Position);
}
}
void ALevelPlayerController::OnPrimarySkill(const FInputActionValue& Value) const
{
AActor* ControlledRole = GetControlledRole();
if (!ControlledRole) return;
if (IBusyControllable *Controllable = Cast<IBusyControllable>(ControlledRole))
{
Controllable->Execute_OnPrimarySkill(ControlledRole);
}
}
void ALevelPlayerController::OnUltimateSkill(const FInputActionValue& Value) const
{
AActor* ControlledRole = GetControlledRole();
if (!ControlledRole) return;
if (IBusyControllable *Controllable = Cast<IBusyControllable>(ControlledRole))
{
Controllable->Execute_OnUltimateSkill(ControlledRole);
}
}
void ALevelPlayerController::OnCameraDetach(const FInputActionValue& Value)
{
if (!RoamingCameraActor) return;
@ -223,6 +188,7 @@ void ALevelPlayerController::OnRoleSkillTriggered(FGameplayTag GameplayTag)
if (UAbilitySystemComponent* Asc = UAbilitySystemBlueprintLibrary::GetAbilitySystemComponent(ControlledRole))
{
FGameplayEventData EventData = FGameplayEventData();
EventData.Instigator = ControlledRole;
Asc->HandleGameplayEvent(GameplayTag, &EventData);
}
}

View File

@ -1,7 +1,9 @@
#pragma once
#include "GameplayEffectTypes.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "BusyAscLibrary.generated.h"
class UGameplayEffect;
struct FGameplayEffectSpec;
class UBusyAbilityDataAssetBase;
@ -15,4 +17,7 @@ public:
UFUNCTION(BlueprintCallable)
static AActor* GetEffectInstigator(const FGameplayEffectSpec& Spec);
UFUNCTION(BlueprintCallable)
static FGameplayEffectSpecHandle MakeGameplayEffectSpecHandle(const UAbilitySystemComponent* Asc, const UGameplayEffect* Effect, const float Level);
};

View File

@ -12,61 +12,64 @@ class UFoxUltimateDataAsset : public UBusyAbilityDataAssetBase
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="一阶消耗", Category="技能消耗")
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="一阶消耗", Category="技能消耗", meta=(ScriptName="FirstStageCost"))
float FirstStageCost = 5.f;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="二阶消耗", Category="技能消耗")
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="二阶消耗", Category="技能消耗", meta=(ScriptName="SecondStageCost"))
float SecondStageCost = 8.f;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="三阶消耗", Category="技能消耗")
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="三阶消耗", Category="技能消耗", meta=(ScriptName="LastStageCost"))
float LastStageCost = 12.f;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="一阶伤害系数", Category="伤害系数")
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="一阶伤害系数", Category="伤害系数", meta=(ScriptName="FirstStageDamageFactor"))
float FirstStageDamageFactor = 5.f;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="二阶伤害系数", Category="伤害系数")
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="二阶伤害系数", Category="伤害系数", meta=(ScriptName="SecondStageDamageFactor"))
float SecondStageDamageFactor = 8.f;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="三阶伤害系数", Category="伤害系数")
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="三阶伤害系数", Category="伤害系数", meta=(ScriptName="LastStageDamageFactor"))
float LastStageDamageFactor = 12.f;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="一阶速度系数", Category="速度系数")
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="一阶速度系数", Category="速度系数", meta=(ScriptName="FirstStageSpeedFactor"))
float FirstStageSpeedFactor = 5.f;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="二阶速度系数", Category="速度系数")
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="二阶速度系数", Category="速度系数", meta=(ScriptName="SecondStageSpeedFactor"))
float SecondStageSpeedFactor = 8.f;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="三阶一段速度系数", Category="速度系数")
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="三阶一段速度系数", Category="速度系数", meta=(ScriptName="LastStageNormalSpeedFactor"))
float LastStageNormalSpeedFactor = 12.f;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="三阶二段速度系数", Category="速度系数")
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="三阶二段速度系数", Category="速度系数", meta=(ScriptName="LastStageSprintSpeedFactor"))
float LastStageSprintSpeedFactor = 12.f;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="可释放一阶标签", Category="技能标签", meta=(ScriptName="FirstStageCastTag"))
FGameplayTag FirstStageCastTag;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="可释放二阶标签", Category="技能标签")
FGameplayTag SecondStageRecastTag;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="可释放二阶标签", Category="技能标签", meta=(ScriptName="SecondStageCastTag"))
FGameplayTag SecondStageCastTag;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="可释放三阶标签", Category="技能标签")
FGameplayTag LastStageRecastTag;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="可释放三阶标签", Category="技能标签", meta=(ScriptName="LastStageCastTag"))
FGameplayTag LastStageCastTag;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="一阶标签", Category="技能标签")
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="一阶标签", Category="技能标签", meta=(ScriptName="FirstStageTag"))
FGameplayTag FirstStageTag;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="二阶标签", Category="技能标签")
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="二阶标签", Category="技能标签", meta=(ScriptName="SecondStageTag"))
FGameplayTag SecondStageTag;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="三阶标签", Category="技能标签")
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="三阶标签", Category="技能标签", meta=(ScriptName="LastStageTag"))
FGameplayTag LastStageTag;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="可重新释放时长")
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="可重新释放时长", meta=(ScriptName="RecastWindow"))
float RecastWindow = 6.f;
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="冷却时间")
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="冷却时间", meta=(ScriptName="CooldownTime"))
float CooldownTime = 15.f;
};

View File

@ -10,16 +10,16 @@ class UBusyGameAbility : public UGameplayAbility
{
GENERATED_BODY()
public:
UBusyGameAbility();
virtual void OnGiveAbility(const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilitySpec& Spec) override;
public:
UFUNCTION(BlueprintCallable)
bool GetAbilityEffectSpecHandle(const FName& EffectName, const UAbilitySystemComponent* Asc, const int32 Level, FGameplayEffectSpecHandle& Handle)const;
UFUNCTION(BlueprintNativeEvent)
void K2_OnGiveAbility(const FGameplayAbilityActorInfo& ActorInfo, const FGameplayAbilitySpec& Spec);
public:
virtual void PostInitProperties()override;
UBusyAbilityDataAssetBase* GetData()const { return Data; }
public:

View File

@ -0,0 +1,21 @@
#pragma once
#include "GameplayTagContainer.h"
#include "BusyGameplayEffectSubSystem.generated.h"
class UGameplayEffect;
UCLASS(blueprinttype)
class UBusyGameplayEffectSubSystem : public UGameInstanceSubsystem
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "GameplayEffectSubSystem")
UGameplayEffect* GetTagGrantEffectWithDuration(const FGameplayTagContainer& TagsAdd,
const FGameplayTagContainer& TagsRemove, const float Duration, const float Period=0);
private:
UPROPERTY()
TArray<UGameplayEffect*> EffectsPool;
};

View File

@ -70,10 +70,6 @@ public:
UFUNCTION(BlueprintCallable)
void BindGameplayTagAddOrRemove(const FGameplayTag& Tag, FGameplayTagAddOrRemoveDelegate Delegate)const;
protected:
void InitCollision();
protected:
UPROPERTY(EditDefaultsOnly)
TObjectPtr<USceneComponent> RootScene; //场景根组件
@ -85,8 +81,7 @@ protected:
UPROPERTY(EditDefaultsOnly)
TObjectPtr<USpineSkeletonRendererComponent> SpineRenderComponent;
UPROPERTY(EditAnywhere, BlueprintReadOnly)
TObjectPtr<USpineSkeletonAnimationComponent> SpineAnimationComponent;
/*-------------------------------------------------------------------*/
/*-----------------------------GAS相关--------------------------------*/
@ -96,6 +91,9 @@ protected:
/*-------------------------------------------------------------------*/
public:
UPROPERTY(EditAnywhere, BlueprintReadOnly)
TObjectPtr<USpineSkeletonAnimationComponent> SpineAnimationComponent;
/*-------------------------------移动组件------------------------------*/
UPROPERTY(EditAnywhere, BlueprintReadOnly)
TObjectPtr<UBusyPawnMovement> MovementComponent;

View File

@ -36,7 +36,7 @@ public:
UCLASS()
class ABusyPlayerRole : public ABusyPawnBase, public IBusyControllable
class ABusyPlayerRole : public ABusyPawnBase
{
GENERATED_BODY()
public:
@ -48,7 +48,7 @@ public:
virtual void InitPawnAttributes(const struct FBusyPawnBaseConfig& Config)override;
virtual void OnMoveDirectionChanged_Implementation(const FVector2D& InDirection) override {}
protected:
/*--------------------相机相关--------------------------*/

View File

@ -34,6 +34,9 @@ enum class EBusyMoveState: uint8
};
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FBusyMoveDirectionChanged, FVector2D, Direction);
UCLASS()
class UBusyPawnMovement : public UActorComponent
{
@ -99,6 +102,11 @@ public:
*/
void SprintTick(const float DeltaTime);
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
FBusyMoveDirectionChanged MoveDirectionChangedDelegate;
protected:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Movement")
EBusyMoveState BusyMoveState = EBusyMoveState::None;

View File

@ -5,31 +5,6 @@
#include "LevelPlayerController.generated.h"
UINTERFACE(MinimalAPI, Blueprintable)
class UBusyControllable: public UInterface
{
GENERATED_BODY()
};
class IBusyControllable
{
GENERATED_BODY()
public:
// 角色移动
UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
void OnMove(const FVector2D& Location);
// 角色普通技能
UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
void OnPrimarySkill();
// 角色大招
UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
void OnUltimateSkill();
};
class ABusyPlayerRole;
struct FInputActionValue;
@ -116,15 +91,6 @@ public: // 输入相关
TArray<FBusySkillActionConfig> RoleSkillActions;
public:
UFUNCTION()
void OnMove(const FInputActionValue& Value)const;
UFUNCTION()
void OnPrimarySkill(const FInputActionValue& Value)const;
UFUNCTION()
void OnUltimateSkill(const FInputActionValue& Value)const;
UFUNCTION()
void OnCameraDetach(const FInputActionValue& Value);