From a8d9ca1783f5acec036ad5b43a3f36820e83657b Mon Sep 17 00:00:00 2001 From: baz Date: Fri, 9 Feb 2024 21:15:55 +0000 Subject: [PATCH] Create Set Movement Speed Task --- .../Enemy/Worker/PatrolMovementSpeed.uasset | 3 ++ Source/Nakatomi/EPatrolMovementEnum.cpp | 4 +++ Source/Nakatomi/EPatrolMovementEnum.h | 15 +++++++++ Source/Nakatomi/NakatomiCMC.cpp | 16 ++++++++++ Source/Nakatomi/NakatomiCMC.h | 10 ++++++ Source/Nakatomi/Tasks/BTTSetMovementSpeed.cpp | 30 +++++++++++++++++ Source/Nakatomi/Tasks/BTTSetMovementSpeed.h | 32 +++++++++++++++++++ 7 files changed, 110 insertions(+) create mode 100644 Content/Enemy/Worker/PatrolMovementSpeed.uasset create mode 100644 Source/Nakatomi/EPatrolMovementEnum.cpp create mode 100644 Source/Nakatomi/EPatrolMovementEnum.h create mode 100644 Source/Nakatomi/Tasks/BTTSetMovementSpeed.cpp create mode 100644 Source/Nakatomi/Tasks/BTTSetMovementSpeed.h diff --git a/Content/Enemy/Worker/PatrolMovementSpeed.uasset b/Content/Enemy/Worker/PatrolMovementSpeed.uasset new file mode 100644 index 0000000..e0d6963 --- /dev/null +++ b/Content/Enemy/Worker/PatrolMovementSpeed.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e9cf595f36b15dce976ce9e9506d74974b44264319c5a4da0a9f76dc7feb8eac +size 2770 diff --git a/Source/Nakatomi/EPatrolMovementEnum.cpp b/Source/Nakatomi/EPatrolMovementEnum.cpp new file mode 100644 index 0000000..f50c7ad --- /dev/null +++ b/Source/Nakatomi/EPatrolMovementEnum.cpp @@ -0,0 +1,4 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "EPatrolMovementEnum.h" diff --git a/Source/Nakatomi/EPatrolMovementEnum.h b/Source/Nakatomi/EPatrolMovementEnum.h new file mode 100644 index 0000000..e044459 --- /dev/null +++ b/Source/Nakatomi/EPatrolMovementEnum.h @@ -0,0 +1,15 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" + +/** + * + */ +UENUM(BlueprintType) +enum class EPatrolMovementEnum : uint8 +{ + SLOWWALK UMETA(DisplayName = "Slow Walk"), + WALK UMETA(DisplayName = "Walk"), +}; diff --git a/Source/Nakatomi/NakatomiCMC.cpp b/Source/Nakatomi/NakatomiCMC.cpp index 1e45ce7..3898557 100644 --- a/Source/Nakatomi/NakatomiCMC.cpp +++ b/Source/Nakatomi/NakatomiCMC.cpp @@ -19,6 +19,12 @@ void UNakatomiCMC::InitializeComponent() NakatomiCharacterOwner = Cast(GetOwner()); } +void UNakatomiCMC::BeginPlay() +{ + Super::BeginPlay(); + DefaultMaxWalkSpeed = Walk_MaxWalkSpeed; +} + // Checks if we can combine the NewMove with the current move to save on data. // If all the data in a saved move is identical, if true, we cam tell the server to run the existing move instead. bool UNakatomiCMC::FSavedMove_Nakatomi::CanCombineWith(const FSavedMovePtr& NewMove, ACharacter* InCharacter, @@ -271,6 +277,16 @@ bool UNakatomiCMC::IsCustomMovementMode(ECustomMovementMove InCustomMovementMode return MovementMode == MOVE_Custom && CustomMovementMode == InCustomMovementMode; } +void UNakatomiCMC::SetMaxWalkSpeed(float newMaxSpeed) +{ + Walk_MaxWalkSpeed = newMaxSpeed; +} + +void UNakatomiCMC::SetMaxWalkSpeedToDefault() +{ + Walk_MaxWalkSpeed = DefaultMaxWalkSpeed; +} + void UNakatomiCMC::EnterSlide() { Safe_bWantsToSlide = true; diff --git a/Source/Nakatomi/NakatomiCMC.h b/Source/Nakatomi/NakatomiCMC.h index 5ef4b35..6e422c2 100644 --- a/Source/Nakatomi/NakatomiCMC.h +++ b/Source/Nakatomi/NakatomiCMC.h @@ -108,6 +108,8 @@ class NAKATOMI_API UNakatomiCMC : public UCharacterMovementComponent UPROPERTY(Transient) ANakatomiCharacter* NakatomiCharacterOwner; + float DefaultMaxWalkSpeed; + public: UPROPERTY(BlueprintAssignable) FDashStartDelegate DashStartDelegate; @@ -118,6 +120,8 @@ public: protected: virtual void InitializeComponent() override; + virtual void BeginPlay() override; + virtual FNetworkPredictionData_Client* GetPredictionData_Client() const override; protected: @@ -167,6 +171,12 @@ public: UFUNCTION() bool IsCustomMovementMode(ECustomMovementMove InCustomMovementMode) const; + UFUNCTION() + void SetMaxWalkSpeed(float newMaxSpeed); + + UFUNCTION() + void SetMaxWalkSpeedToDefault(); + private: void EnterSlide(); void ExitSlide(); diff --git a/Source/Nakatomi/Tasks/BTTSetMovementSpeed.cpp b/Source/Nakatomi/Tasks/BTTSetMovementSpeed.cpp new file mode 100644 index 0000000..afab13f --- /dev/null +++ b/Source/Nakatomi/Tasks/BTTSetMovementSpeed.cpp @@ -0,0 +1,30 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "../Tasks/BTTSetMovementSpeed.h" + +#include "Nakatomi/EnemyAIController.h" +#include "Nakatomi/NakatomiCMC.h" + +enum class EPatrolMovementEnum : uint8; + +EBTNodeResult::Type UBTTSetMovementSpeed::ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) +{ + AEnemyAIController* enemyController = Cast(owner.GetAIOwner()); + AEnemyCharacter* enemyPawn = Cast(enemyController->GetPawn()); + + switch (MaxWalkSpeedKey) + { + case EPatrolMovementEnum::SLOWWALK: + enemyPawn->GetCharacterMovementComponent()->SetMaxWalkSpeed(slowWalkSpeed); + break; + case EPatrolMovementEnum::WALK: + enemyPawn->GetCharacterMovementComponent()->SetMaxWalkSpeed(walkSpeed); + break; + default: + enemyPawn->GetCharacterMovementComponent()->SetMaxWalkSpeedToDefault(); + break; + } + + return EBTNodeResult::Succeeded; +} diff --git a/Source/Nakatomi/Tasks/BTTSetMovementSpeed.h b/Source/Nakatomi/Tasks/BTTSetMovementSpeed.h new file mode 100644 index 0000000..8f09911 --- /dev/null +++ b/Source/Nakatomi/Tasks/BTTSetMovementSpeed.h @@ -0,0 +1,32 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BehaviorTree/BTTaskNode.h" +#include "Nakatomi/EPatrolMovementEnum.h" +#include "BTTSetMovementSpeed.generated.h" + +/** + * + */ +UCLASS() +class NAKATOMI_API UBTTSetMovementSpeed : public UBTTaskNode +{ + GENERATED_BODY() + +public: + + UPROPERTY(EditAnywhere, Category = "Options", + Meta = (AllowPrivateAccess = "true", DisplayName = "Max Walk Speed Key")) + EPatrolMovementEnum MaxWalkSpeedKey; + +private: + float slowWalkSpeed = 250.0f; + + float walkSpeed = 500.0f; + +public: + virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) override; + +};