Add reworked Worker Enemy AI #3

Closed
baz wants to merge 24 commits from worker-ai into master
7 changed files with 110 additions and 0 deletions
Showing only changes of commit a8d9ca1783 - Show all commits

BIN
Content/Enemy/Worker/PatrolMovementSpeed.uasset (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,4 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "EPatrolMovementEnum.h"

View File

@ -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"),
};

View File

@ -19,6 +19,12 @@ void UNakatomiCMC::InitializeComponent()
NakatomiCharacterOwner = Cast<ANakatomiCharacter>(GetOwner()); NakatomiCharacterOwner = Cast<ANakatomiCharacter>(GetOwner());
} }
void UNakatomiCMC::BeginPlay()
{
Super::BeginPlay();
DefaultMaxWalkSpeed = Walk_MaxWalkSpeed;
}
// Checks if we can combine the NewMove with the current move to save on data. // 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. // 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, 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; return MovementMode == MOVE_Custom && CustomMovementMode == InCustomMovementMode;
} }
void UNakatomiCMC::SetMaxWalkSpeed(float newMaxSpeed)
{
Walk_MaxWalkSpeed = newMaxSpeed;
}
void UNakatomiCMC::SetMaxWalkSpeedToDefault()
{
Walk_MaxWalkSpeed = DefaultMaxWalkSpeed;
}
void UNakatomiCMC::EnterSlide() void UNakatomiCMC::EnterSlide()
{ {
Safe_bWantsToSlide = true; Safe_bWantsToSlide = true;

View File

@ -108,6 +108,8 @@ class NAKATOMI_API UNakatomiCMC : public UCharacterMovementComponent
UPROPERTY(Transient) UPROPERTY(Transient)
ANakatomiCharacter* NakatomiCharacterOwner; ANakatomiCharacter* NakatomiCharacterOwner;
float DefaultMaxWalkSpeed;
public: public:
UPROPERTY(BlueprintAssignable) UPROPERTY(BlueprintAssignable)
FDashStartDelegate DashStartDelegate; FDashStartDelegate DashStartDelegate;
@ -118,6 +120,8 @@ public:
protected: protected:
virtual void InitializeComponent() override; virtual void InitializeComponent() override;
virtual void BeginPlay() override;
virtual FNetworkPredictionData_Client* GetPredictionData_Client() const override; virtual FNetworkPredictionData_Client* GetPredictionData_Client() const override;
protected: protected:
@ -167,6 +171,12 @@ public:
UFUNCTION() UFUNCTION()
bool IsCustomMovementMode(ECustomMovementMove InCustomMovementMode) const; bool IsCustomMovementMode(ECustomMovementMove InCustomMovementMode) const;
UFUNCTION()
void SetMaxWalkSpeed(float newMaxSpeed);
UFUNCTION()
void SetMaxWalkSpeedToDefault();
private: private:
void EnterSlide(); void EnterSlide();
void ExitSlide(); void ExitSlide();

View File

@ -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<AEnemyAIController>(owner.GetAIOwner());
AEnemyCharacter* enemyPawn = Cast<AEnemyCharacter>(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;
}

View File

@ -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;
};