From dcd292cb485ed92f4986fd011336d3b71e4905b4 Mon Sep 17 00:00:00 2001 From: baz Date: Thu, 8 Feb 2024 18:30:39 +0000 Subject: [PATCH 01/24] Create Clear Focus Task --- Source/Nakatomi/Tasks/BTTClearFocus.cpp | 10 +++++++++- Source/Nakatomi/Tasks/BTTClearFocus.h | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Source/Nakatomi/Tasks/BTTClearFocus.cpp b/Source/Nakatomi/Tasks/BTTClearFocus.cpp index 0cec164..16239b5 100644 --- a/Source/Nakatomi/Tasks/BTTClearFocus.cpp +++ b/Source/Nakatomi/Tasks/BTTClearFocus.cpp @@ -1,5 +1,13 @@ // Fill out your copyright notice in the Description page of Project Settings. -#include "Tasks/BTTClearFocus.h" +#include "../Tasks/BTTClearFocus.h" +#include "Nakatomi/EnemyAIController.h" + +EBTNodeResult::Type UBTTClearFocus::ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) +{ + auto enemyController = Cast(owner.GetAIOwner()); + enemyController->ClearFocus(EAIFocusPriority::Default); + return EBTNodeResult::Succeeded; +} diff --git a/Source/Nakatomi/Tasks/BTTClearFocus.h b/Source/Nakatomi/Tasks/BTTClearFocus.h index 7e7e552..513bf29 100644 --- a/Source/Nakatomi/Tasks/BTTClearFocus.h +++ b/Source/Nakatomi/Tasks/BTTClearFocus.h @@ -13,5 +13,8 @@ UCLASS() class NAKATOMI_API UBTTClearFocus : public UBTTaskNode { GENERATED_BODY() + +public: + virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) override; }; -- 2.34.1 From b381da27444148838c0e0469b7be7ee61cad2b08 Mon Sep 17 00:00:00 2001 From: baz Date: Thu, 8 Feb 2024 23:41:11 +0000 Subject: [PATCH 02/24] Create PatrolRoute --- Source/Nakatomi/PatrolRoute.cpp | 34 +++++++++++++++++++++++++++++++++ Source/Nakatomi/PatrolRoute.h | 32 +++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 Source/Nakatomi/PatrolRoute.cpp create mode 100644 Source/Nakatomi/PatrolRoute.h diff --git a/Source/Nakatomi/PatrolRoute.cpp b/Source/Nakatomi/PatrolRoute.cpp new file mode 100644 index 0000000..53761f7 --- /dev/null +++ b/Source/Nakatomi/PatrolRoute.cpp @@ -0,0 +1,34 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "PatrolRoute.h" + +// Sets default values +APatrolRoute::APatrolRoute() +{ + PrimaryActorTick.bCanEverTick = false; + + Spline = CreateDefaultSubobject(TEXT("Spline")); + Spline->SetupAttachment(RootComponent); +} + +void APatrolRoute::IncrementPatrolRoute() +{ + if (PatrolIndex == Spline->GetNumberOfSplinePoints() - 1) + { + Direction = -1; + } + else if (PatrolIndex == 0) + { + Direction = 1; + } + + PatrolIndex += Direction; + + +} + +FVector APatrolRoute::GetSplinePointAtWorld(int pointIndex) +{ + return Spline->GetLocationAtSplinePoint(pointIndex, ESplineCoordinateSpace::World); +} diff --git a/Source/Nakatomi/PatrolRoute.h b/Source/Nakatomi/PatrolRoute.h new file mode 100644 index 0000000..5989f1a --- /dev/null +++ b/Source/Nakatomi/PatrolRoute.h @@ -0,0 +1,32 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Components/SplineComponent.h" +#include "GameFramework/Actor.h" +#include "PatrolRoute.generated.h" + +UCLASS() +class NAKATOMI_API APatrolRoute : public AActor +{ + GENERATED_BODY() + +public: + + UPROPERTY(BlueprintReadWrite) + USplineComponent* Spline; + +private: + int PatrolIndex = 0; + + int Direction; + +public: + // Sets default values for this actor's properties + APatrolRoute(); + + void IncrementPatrolRoute(); + + FVector GetSplinePointAtWorld(int pointIndex); +}; -- 2.34.1 From 0e60ae2976ab3a232c53fc243d6b6964c7ba237d Mon Sep 17 00:00:00 2001 From: baz Date: Fri, 9 Feb 2024 18:21:18 +0000 Subject: [PATCH 03/24] Create Move Along Patrol Route task --- Content/TestPatrolRoute.uasset | 3 ++ .../Tasks/BTTMoveAlongPatrolRoute.cpp | 28 +++++++++++++++++++ .../Nakatomi/Tasks/BTTMoveAlongPatrolRoute.h | 24 ++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 Content/TestPatrolRoute.uasset create mode 100644 Source/Nakatomi/Tasks/BTTMoveAlongPatrolRoute.cpp create mode 100644 Source/Nakatomi/Tasks/BTTMoveAlongPatrolRoute.h diff --git a/Content/TestPatrolRoute.uasset b/Content/TestPatrolRoute.uasset new file mode 100644 index 0000000..2657dd9 --- /dev/null +++ b/Content/TestPatrolRoute.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:951fb0bbfcbd6e594c596168e3247eaa4db8ab4f8237e5f965540c1ecd01add9 +size 20989 diff --git a/Source/Nakatomi/Tasks/BTTMoveAlongPatrolRoute.cpp b/Source/Nakatomi/Tasks/BTTMoveAlongPatrolRoute.cpp new file mode 100644 index 0000000..aa8a0f3 --- /dev/null +++ b/Source/Nakatomi/Tasks/BTTMoveAlongPatrolRoute.cpp @@ -0,0 +1,28 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "../Tasks/BTTMoveAlongPatrolRoute.h" + +#include "navigationSystem.h" +#include "BehaviorTree/BlackboardComponent.h" +#include "Nakatomi/EnemyAIController.h" +#include "Nakatomi/NakatomiCMC.h" + +EBTNodeResult::Type UBTTMoveAlongPatrolRoute::ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) +{ + AEnemyAIController* enemyController = Cast(owner.GetAIOwner()); + AEnemyCharacter* enemyPawn = Cast(enemyController->GetPawn()); + + if (enemyPawn->CurrentPatrolRoute) + { + FVector location = enemyPawn->CurrentPatrolRoute->GetSplinePointAtWorld(); + UBlackboardComponent* blackboardComponent = owner.GetBlackboardComponent(); + blackboardComponent->SetValueAsVector(PatrolLocationKey.SelectedKeyName, location); + + enemyPawn->CurrentPatrolRoute->IncrementPatrolRoute(); + + return EBTNodeResult::Succeeded; + } + + return EBTNodeResult::Failed; +} diff --git a/Source/Nakatomi/Tasks/BTTMoveAlongPatrolRoute.h b/Source/Nakatomi/Tasks/BTTMoveAlongPatrolRoute.h new file mode 100644 index 0000000..71b4ad0 --- /dev/null +++ b/Source/Nakatomi/Tasks/BTTMoveAlongPatrolRoute.h @@ -0,0 +1,24 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BehaviorTree/BTTaskNode.h" +#include "BTTMoveAlongPatrolRoute.generated.h" + +/** + * + */ +UCLASS() +class NAKATOMI_API UBTTMoveAlongPatrolRoute : public UBTTaskNode +{ + GENERATED_BODY() + +public: + UPROPERTY(EditAnywhere, Category = "Options", + Meta = (AllowPrivateAccess = "true", DisplayName = "Patrol Location Key")) + FBlackboardKeySelector PatrolLocationKey; + +public: + virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) override; +}; -- 2.34.1 From 25c421cc671fa53771ec91d0a02a4ab1ad9673e9 Mon Sep 17 00:00:00 2001 From: baz Date: Fri, 9 Feb 2024 18:21:40 +0000 Subject: [PATCH 04/24] Add CurrentPatrolRoute reference to EnemyCharacter --- Source/Nakatomi/EnemyCharacter.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/Nakatomi/EnemyCharacter.h b/Source/Nakatomi/EnemyCharacter.h index d998214..c596ec2 100644 --- a/Source/Nakatomi/EnemyCharacter.h +++ b/Source/Nakatomi/EnemyCharacter.h @@ -4,6 +4,7 @@ #include "CoreMinimal.h" #include "NakatomiCharacter.h" +#include "PatrolRoute.h" #include "BehaviorTree/BehaviorTreeComponent.h" #include "RandomWeaponParameters.h" #include "EnemyCharacter.generated.h" @@ -17,6 +18,10 @@ class NAKATOMI_API AEnemyCharacter : public ANakatomiCharacter { GENERATED_BODY() +public: + UPROPERTY(EditAnywhere, Meta = (AllowPrivateAccess = "true")) + APatrolRoute* CurrentPatrolRoute; + private: UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) UBehaviorTree* BehaviourTree; -- 2.34.1 From 275f86b03fa2712e758c5580f32f357da37e060d Mon Sep 17 00:00:00 2001 From: baz Date: Fri, 9 Feb 2024 18:22:12 +0000 Subject: [PATCH 05/24] Add default GetSplinePointAtWorld function --- Source/Nakatomi/PatrolRoute.cpp | 5 ++++- Source/Nakatomi/PatrolRoute.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/Nakatomi/PatrolRoute.cpp b/Source/Nakatomi/PatrolRoute.cpp index 53761f7..df7c94a 100644 --- a/Source/Nakatomi/PatrolRoute.cpp +++ b/Source/Nakatomi/PatrolRoute.cpp @@ -24,8 +24,11 @@ void APatrolRoute::IncrementPatrolRoute() } PatrolIndex += Direction; +} - +FVector APatrolRoute::GetSplinePointAtWorld() +{ + return GetSplinePointAtWorld(PatrolIndex); } FVector APatrolRoute::GetSplinePointAtWorld(int pointIndex) diff --git a/Source/Nakatomi/PatrolRoute.h b/Source/Nakatomi/PatrolRoute.h index 5989f1a..ee9a9d2 100644 --- a/Source/Nakatomi/PatrolRoute.h +++ b/Source/Nakatomi/PatrolRoute.h @@ -28,5 +28,7 @@ public: void IncrementPatrolRoute(); + FVector GetSplinePointAtWorld(); + FVector GetSplinePointAtWorld(int pointIndex); }; -- 2.34.1 From a8d9ca1783f5acec036ad5b43a3f36820e83657b Mon Sep 17 00:00:00 2001 From: baz Date: Fri, 9 Feb 2024 21:15:55 +0000 Subject: [PATCH 06/24] 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; + +}; -- 2.34.1 From 594ef5f1587b3f15ab7b337b5666e720615f1dcf Mon Sep 17 00:00:00 2001 From: baz Date: Fri, 9 Feb 2024 21:16:09 +0000 Subject: [PATCH 07/24] Create Has Patrol Route Decorator --- .../Nakatomi/Decorators/BTDHasPatrolRoute.cpp | 14 ++++++++++++++ .../Nakatomi/Decorators/BTDHasPatrolRoute.h | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 Source/Nakatomi/Decorators/BTDHasPatrolRoute.cpp create mode 100644 Source/Nakatomi/Decorators/BTDHasPatrolRoute.h diff --git a/Source/Nakatomi/Decorators/BTDHasPatrolRoute.cpp b/Source/Nakatomi/Decorators/BTDHasPatrolRoute.cpp new file mode 100644 index 0000000..9345c29 --- /dev/null +++ b/Source/Nakatomi/Decorators/BTDHasPatrolRoute.cpp @@ -0,0 +1,14 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "../Decorators/BTDHasPatrolRoute.h" + +#include "Nakatomi/EnemyAIController.h" + +bool UBTDHasPatrolRoute::CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const +{ + AEnemyAIController* enemyController = Cast(OwnerComp.GetAIOwner()); + AEnemyCharacter* enemyPawn = Cast(enemyController->GetPawn()); + + return enemyPawn->CurrentPatrolRoute ? true : false; +} diff --git a/Source/Nakatomi/Decorators/BTDHasPatrolRoute.h b/Source/Nakatomi/Decorators/BTDHasPatrolRoute.h new file mode 100644 index 0000000..c9cc9bd --- /dev/null +++ b/Source/Nakatomi/Decorators/BTDHasPatrolRoute.h @@ -0,0 +1,19 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BehaviorTree/BTDecorator.h" +#include "BTDHasPatrolRoute.generated.h" + +/** + * + */ +UCLASS(Blueprintable) +class NAKATOMI_API UBTDHasPatrolRoute : public UBTDecorator +{ + GENERATED_BODY() + +public: + virtual bool CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const override; +}; -- 2.34.1 From db4d6beb4cfc27e83c1a35ed27ba1b793d400204 Mon Sep 17 00:00:00 2001 From: baz Date: Mon, 12 Feb 2024 21:18:07 +0000 Subject: [PATCH 08/24] Create AI State Enum --- Source/Nakatomi/EAIState.cpp | 5 +++++ Source/Nakatomi/EAIState.h | 18 ++++++++++++++++++ Source/Nakatomi/EnemyAIController.cpp | 20 ++++++++++++++++++++ Source/Nakatomi/EnemyAIController.h | 10 ++++++++++ 4 files changed, 53 insertions(+) create mode 100644 Source/Nakatomi/EAIState.cpp create mode 100644 Source/Nakatomi/EAIState.h diff --git a/Source/Nakatomi/EAIState.cpp b/Source/Nakatomi/EAIState.cpp new file mode 100644 index 0000000..b94b964 --- /dev/null +++ b/Source/Nakatomi/EAIState.cpp @@ -0,0 +1,5 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "EAIState.h" + diff --git a/Source/Nakatomi/EAIState.h b/Source/Nakatomi/EAIState.h new file mode 100644 index 0000000..abadf5b --- /dev/null +++ b/Source/Nakatomi/EAIState.h @@ -0,0 +1,18 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" + +/** + * + */ +UENUM(BlueprintType) +enum class EAIState : uint8 +{ + PASSIVE UMETA(DisplayName = "Passive"), + ATTACKING UMETA(DisplayName = "Attacking"), + FROZEN UMETA(DisplayName = "Frozen"), + INVESTIGATING UMETA(DisplayName = "Investigating"), + DEAD UMETA(DisplayName = "Dead"), +}; diff --git a/Source/Nakatomi/EnemyAIController.cpp b/Source/Nakatomi/EnemyAIController.cpp index bbc8b5a..e67cc77 100644 --- a/Source/Nakatomi/EnemyAIController.cpp +++ b/Source/Nakatomi/EnemyAIController.cpp @@ -2,6 +2,8 @@ #include "EnemyAIController.h" #include + +#include "EAIState.h" #include "NakatomiGameInstance.h" #include "BehaviorTree/BehaviorTree.h" #include "BehaviorTree/BlackboardComponent.h" @@ -48,6 +50,8 @@ void AEnemyAIController::OnPossess(APawn* InPawn) BehaviorTree->StartTree(*behaviourTree); Blackboard->SetValueAsObject("SelfActor", enemy); } + + Blackboard->SetValueAsEnum("State", static_cast(EAIState::PASSIVE)); //ensure(enemy->GetMovementComponent()->UseAccelerationForPathFollowing()); } @@ -179,3 +183,19 @@ bool AEnemyAIController::GetHasAttackToken() { return HasAttackToken; } + +void AEnemyAIController::SetState(EAIState state) +{ + Blackboard->SetValueAsEnum("State", static_cast(state)); +} + +void AEnemyAIController::SetStateAsPassive() +{ + SetState(EAIState::PASSIVE); +} + +void AEnemyAIController::SetStateAsAttacking(AActor* target) +{ + Blackboard->SetValueAsObject("TargetActor", target); + SetState(EAIState::ATTACKING); +} diff --git a/Source/Nakatomi/EnemyAIController.h b/Source/Nakatomi/EnemyAIController.h index 3122437..28f02e5 100644 --- a/Source/Nakatomi/EnemyAIController.h +++ b/Source/Nakatomi/EnemyAIController.h @@ -4,6 +4,7 @@ #include "CoreMinimal.h" #include "AIController.h" +#include "EAIState.h" #include "EnemyCharacter.h" #include "PlayerCharacter.h" #include "Perception/AISenseConfig_Sight.h" @@ -59,4 +60,13 @@ public: UFUNCTION() bool GetHasAttackToken(); + + UFUNCTION() + void SetState(EAIState state); + + UFUNCTION() + void SetStateAsPassive(); + + UFUNCTION() + void SetStateAsAttacking(AActor* target); }; -- 2.34.1 From 7313dccdffcb781fbdb2cea6255d76083d20e433 Mon Sep 17 00:00:00 2001 From: baz Date: Tue, 13 Feb 2024 21:23:15 +0000 Subject: [PATCH 09/24] Add new Perception Senses --- Content/Enemy/Worker/AIC_Worker.uasset | 3 ++ Source/Nakatomi/EnemyAIController.cpp | 63 ++++++++++++++++++++++++-- Source/Nakatomi/EnemyAIController.h | 14 ++++++ Source/Nakatomi/Tasks/BTTSetState.cpp | 17 +++++++ Source/Nakatomi/Tasks/BTTSetState.h | 27 +++++++++++ 5 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 Content/Enemy/Worker/AIC_Worker.uasset create mode 100644 Source/Nakatomi/Tasks/BTTSetState.cpp create mode 100644 Source/Nakatomi/Tasks/BTTSetState.h diff --git a/Content/Enemy/Worker/AIC_Worker.uasset b/Content/Enemy/Worker/AIC_Worker.uasset new file mode 100644 index 0000000..105a3ce --- /dev/null +++ b/Content/Enemy/Worker/AIC_Worker.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:50deb580132c8059cab1d6b9cd9556977ece12cd3300827cb696e1940801377a +size 19654 diff --git a/Source/Nakatomi/EnemyAIController.cpp b/Source/Nakatomi/EnemyAIController.cpp index e67cc77..66fd18c 100644 --- a/Source/Nakatomi/EnemyAIController.cpp +++ b/Source/Nakatomi/EnemyAIController.cpp @@ -27,8 +27,19 @@ AEnemyAIController::AEnemyAIController(const FObjectInitializer& object_initiali SightConfig->DetectionByAffiliation.bDetectEnemies = true; SightConfig->DetectionByAffiliation.bDetectNeutrals = true; + HearingConfig = CreateDefaultSubobject(TEXT("Hearing Sense Config")); + HearingConfig->HearingRange = 800.0f; + HearingConfig->SetMaxAge(3.0f); + HearingConfig->DetectionByAffiliation.bDetectEnemies = true; + HearingConfig->DetectionByAffiliation.bDetectNeutrals = true; + + DamageConfig = CreateDefaultSubobject(TEXT("Damage Sense Config")); + DamageConfig->SetMaxAge(5.0f); + AIPerception->SetDominantSense(SightConfig->GetSenseImplementation()); AIPerception->ConfigureSense(*SightConfig); + AIPerception->ConfigureSense(*HearingConfig); + AIPerception->ConfigureSense(*DamageConfig); } void AEnemyAIController::OnPossess(APawn* InPawn) @@ -120,7 +131,7 @@ void AEnemyAIController::OnDeath(FDamageInfo info) void AEnemyAIController::OnPerceptionUpdated(const TArray& actors) { - for (auto actor : actors) + for (AActor* actor : actors) { if (!actor->GetClass()->IsChildOf(APlayerCharacter::StaticClass())) { @@ -130,13 +141,32 @@ void AEnemyAIController::OnPerceptionUpdated(const TArray& actors) FActorPerceptionBlueprintInfo perceptionInfo; PerceptionComponent->GetActorsPerception(actor, perceptionInfo); - for (auto& stimulus : perceptionInfo.LastSensedStimuli) + for (FAIStimulus& stimulus : perceptionInfo.LastSensedStimuli) { - if (!stimulus.IsValid() || stimulus.IsExpired()) + if (!stimulus.IsValid() || stimulus.IsExpired() || + static_cast(Blackboard->GetValueAsEnum("State")) == EAIState::DEAD) { continue; } + FAISenseID SightID = SightConfig->GetSenseID(); + FAISenseID HearingID = HearingConfig->GetSenseID(); + FAISenseID DamageID = DamageConfig->GetSenseID(); + + if (stimulus.Type == SightID) + { + SensedSight(actor, stimulus); + } + else if (stimulus.Type == HearingID) + { + SensedHearing(actor, stimulus); + stimulus.StimulusLocation; + } + else if (stimulus.Type == DamageID) + { + SensedDamaged(actor, stimulus); + } + Blackboard->SetValueAsObject("TargetActor", actor); if (stimulus.IsActive()) @@ -199,3 +229,30 @@ void AEnemyAIController::SetStateAsAttacking(AActor* target) Blackboard->SetValueAsObject("TargetActor", target); SetState(EAIState::ATTACKING); } + +void AEnemyAIController::SensedSight(AActor* actor, FAIStimulus& stimulus) +{ + EAIState CurrentState = static_cast(Blackboard->GetValueAsEnum("State")); + + + if (CurrentState == EAIState::PASSIVE || CurrentState == EAIState::INVESTIGATING) + { + SetStateAsAttacking(actor); + } +} + +void AEnemyAIController::SensedHearing(AActor* actor, FAIStimulus& stimulus) +{ + EAIState CurrentState = static_cast(Blackboard->GetValueAsEnum("State")); + + if (CurrentState == EAIState::PASSIVE || CurrentState == EAIState::INVESTIGATING) + { + SetState(EAIState::INVESTIGATING); + Blackboard->SetValueAsVector("InvestigationLocation", stimulus.StimulusLocation); + } +} + +void AEnemyAIController::SensedDamaged(AActor* actor, FAIStimulus& stimulus) +{ + SetStateAsAttacking(actor); +} diff --git a/Source/Nakatomi/EnemyAIController.h b/Source/Nakatomi/EnemyAIController.h index 28f02e5..d14f019 100644 --- a/Source/Nakatomi/EnemyAIController.h +++ b/Source/Nakatomi/EnemyAIController.h @@ -7,6 +7,8 @@ #include "EAIState.h" #include "EnemyCharacter.h" #include "PlayerCharacter.h" +#include "Perception/AISenseConfig_Damage.h" +#include "Perception/AISenseConfig_Hearing.h" #include "Perception/AISenseConfig_Sight.h" #include "EnemyAIController.generated.h" @@ -30,6 +32,10 @@ private: UAISenseConfig_Sight* SightConfig; + UAISenseConfig_Hearing* HearingConfig; + + UAISenseConfig_Damage* DamageConfig; + bool HasAttackToken = false; public: @@ -69,4 +75,12 @@ public: UFUNCTION() void SetStateAsAttacking(AActor* target); + +private: + + void SensedSight(AActor* actor, FAIStimulus& stimulus); + + void SensedHearing(AActor* actor, FAIStimulus& stimulus); + + void SensedDamaged(AActor* actor, FAIStimulus& stimulus); }; diff --git a/Source/Nakatomi/Tasks/BTTSetState.cpp b/Source/Nakatomi/Tasks/BTTSetState.cpp new file mode 100644 index 0000000..afb0f28 --- /dev/null +++ b/Source/Nakatomi/Tasks/BTTSetState.cpp @@ -0,0 +1,17 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "../Tasks/BTTSetState.h" + +#include "Nakatomi/EnemyAIController.h" + +EBTNodeResult::Type UBTTSetState::ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) +{ + if (AEnemyAIController* EnemyController = Cast(owner.GetAIOwner())) + { + EnemyController->SetState(NewState); + return EBTNodeResult::Succeeded; + } + + return EBTNodeResult::Failed; +} diff --git a/Source/Nakatomi/Tasks/BTTSetState.h b/Source/Nakatomi/Tasks/BTTSetState.h new file mode 100644 index 0000000..2aa3518 --- /dev/null +++ b/Source/Nakatomi/Tasks/BTTSetState.h @@ -0,0 +1,27 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BehaviorTree/BTTaskNode.h" +#include "Nakatomi/EAIState.h" +#include "BTTSetState.generated.h" + +/** + * + */ +UCLASS() +class NAKATOMI_API UBTTSetState : public UBTTaskNode +{ + GENERATED_BODY() + +public: + + UPROPERTY(EditAnywhere, Category = "Options", + Meta = (AllowPrivateAccess = "true", DisplayName = "New State")) + EAIState NewState; + +public: + virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) override; + +}; -- 2.34.1 From a1832e352e3d209265825e08528d3aefdfa0e269 Mon Sep 17 00:00:00 2001 From: baz Date: Wed, 14 Feb 2024 20:35:26 +0000 Subject: [PATCH 10/24] Make hearing and damaged perception events --- Source/Nakatomi/EnemyAIController.cpp | 1 - Source/Nakatomi/EnemyCharacter.cpp | 5 ++++ Source/Nakatomi/EnemyHealthComponent.cpp | 36 ++++++++++++++++++++++++ Source/Nakatomi/EnemyHealthComponent.h | 22 +++++++++++++++ Source/Nakatomi/HealthComponent.h | 4 +-- Source/Nakatomi/NakatomiCharacter.cpp | 9 ++++-- Source/Nakatomi/PlayerCharacter.cpp | 9 ++++++ 7 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 Source/Nakatomi/EnemyHealthComponent.cpp create mode 100644 Source/Nakatomi/EnemyHealthComponent.h diff --git a/Source/Nakatomi/EnemyAIController.cpp b/Source/Nakatomi/EnemyAIController.cpp index 66fd18c..f7a37d3 100644 --- a/Source/Nakatomi/EnemyAIController.cpp +++ b/Source/Nakatomi/EnemyAIController.cpp @@ -160,7 +160,6 @@ void AEnemyAIController::OnPerceptionUpdated(const TArray& actors) else if (stimulus.Type == HearingID) { SensedHearing(actor, stimulus); - stimulus.StimulusLocation; } else if (stimulus.Type == DamageID) { diff --git a/Source/Nakatomi/EnemyCharacter.cpp b/Source/Nakatomi/EnemyCharacter.cpp index 41bf8bb..8018d9e 100644 --- a/Source/Nakatomi/EnemyCharacter.cpp +++ b/Source/Nakatomi/EnemyCharacter.cpp @@ -2,6 +2,7 @@ #include "EnemyCharacter.h" #include "EnemyAIController.h" +#include "EnemyHealthComponent.h" #include "InteractableComponent.h" #define COLLISION_WEAPON ECC_GameTraceChannel1 @@ -10,6 +11,10 @@ AEnemyCharacter::AEnemyCharacter(const FObjectInitializer& ObjectInitializer) : { RandomWeaponParameters = CreateDefaultSubobject(TEXT("Random Weapon Parameters")); + auto healthComponent = CreateDefaultSubobject(TEXT("Health Component")); + SetHealthComponent(healthComponent); + GetHealthComponent()->OnDamaged.BindUFunction(this, "OnDamaged"); + GetHealthComponent()->OnDeath.BindUFunction(this, "OnDeath"); GetHealthComponent()->SetMaxHealth(100.0f); this->Tags.Add(FName("Enemy")); diff --git a/Source/Nakatomi/EnemyHealthComponent.cpp b/Source/Nakatomi/EnemyHealthComponent.cpp new file mode 100644 index 0000000..820c831 --- /dev/null +++ b/Source/Nakatomi/EnemyHealthComponent.cpp @@ -0,0 +1,36 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "EnemyHealthComponent.h" + +#include "EnemyAIController.h" +#include "EnemyCharacter.h" + +void UEnemyHealthComponent::BeginPlay() +{ + Super::BeginPlay(); +} + +void UEnemyHealthComponent::TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType, + AController* instigatedBy, AActor* damageCauser) +{ + if (damagedActor == nullptr || IsDead || !CanDamage) + { + return; + } + + CurrentHealth -= damage; + + AEnemyCharacter* enemyCharacter = Cast(damagedActor); + UAISense_Damage::ReportDamageEvent(GetWorld(), damagedActor, damageCauser, 1, + damageCauser->GetTransform().GetLocation(), + damageCauser->GetTransform().GetLocation()); + + OnDamaged.ExecuteIfBound({damagedActor, damage, damageType, instigatedBy, damageCauser}); + + if (CurrentHealth <= 0.0f) + { + IsDead = true; + OnDeath.ExecuteIfBound({damagedActor, damage, damageType, instigatedBy, damageCauser}); + } +} diff --git a/Source/Nakatomi/EnemyHealthComponent.h b/Source/Nakatomi/EnemyHealthComponent.h new file mode 100644 index 0000000..fd7536c --- /dev/null +++ b/Source/Nakatomi/EnemyHealthComponent.h @@ -0,0 +1,22 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "HealthComponent.h" +#include "EnemyHealthComponent.generated.h" + +/** + * + */ +UCLASS() +class NAKATOMI_API UEnemyHealthComponent : public UHealthComponent +{ + GENERATED_BODY() + +protected: + virtual void BeginPlay() override; + + virtual void TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType, AController* instigatedBy, AActor* damageCauser) override; + +}; diff --git a/Source/Nakatomi/HealthComponent.h b/Source/Nakatomi/HealthComponent.h index 8e15ccd..9ec0b1d 100644 --- a/Source/Nakatomi/HealthComponent.h +++ b/Source/Nakatomi/HealthComponent.h @@ -39,7 +39,7 @@ public: FOnDamageDelegate OnDamaged; FOnDeathDelegate OnDeath; -private: +protected: UPROPERTY(EditDefaultsOnly) float MaxHealth = 100.f; @@ -55,7 +55,7 @@ public: UHealthComponent(); UFUNCTION() - void TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType, AController* instigatedBy, + virtual void TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType, AController* instigatedBy, AActor* damageCauser); UFUNCTION() diff --git a/Source/Nakatomi/NakatomiCharacter.cpp b/Source/Nakatomi/NakatomiCharacter.cpp index ec54fda..536c469 100644 --- a/Source/Nakatomi/NakatomiCharacter.cpp +++ b/Source/Nakatomi/NakatomiCharacter.cpp @@ -14,9 +14,12 @@ ANakatomiCharacter::ANakatomiCharacter(const FObjectInitializer& ObjectInitializ NakatomiCMC = Cast(GetCharacterMovement()); - HealthComponent = CreateDefaultSubobject(TEXT("Health Component")); - HealthComponent->OnDamaged.BindUFunction(this, "OnDamaged"); - HealthComponent->OnDeath.BindUFunction(this, "OnDeath"); + // if (!HealthComponent) + // { + // HealthComponent = CreateDefaultSubobject(TEXT("Health Component")); + // HealthComponent->OnDamaged.BindUFunction(this, "OnDamaged"); + // HealthComponent->OnDeath.BindUFunction(this, "OnDeath"); + // } } // Called when the game starts or when spawned diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index de607e9..3846d19 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -30,6 +30,10 @@ APlayerCharacter::APlayerCharacter(const FObjectInitializer& ObjectInitializer) //bUseControllerRotationYaw = true; //bUseControllerRotationRoll = false; + SetHealthComponent(CreateDefaultSubobject(TEXT("Health Component"))); + GetHealthComponent()->OnDamaged.BindUFunction(this, "OnDamaged"); + GetHealthComponent()->OnDeath.BindUFunction(this, "OnDeath"); + // Setup the camera boom CameraSpringArmComponent = CreateDefaultSubobject(TEXT("CameraSpringArmComponent")); CameraSpringArmComponent->SetupAttachment(RootComponent); @@ -398,6 +402,7 @@ void APlayerCharacter::ProcessHits(TArray hits) { healthComponent->TakeDamage(Hit.GetActor(), CurrentWeapon->GetWeaponProperties()->WeaponDamage, nullptr, GetController(), this); + if (!healthComponent->GetIsDead()) { OnEnemyHit.ExecuteIfBound(); @@ -437,6 +442,8 @@ void APlayerCharacter::ProcessHits(TArray hits) true); } } + + MakeNoise(1, this, Hit.Location); } } @@ -639,6 +646,8 @@ void APlayerCharacter::OnFire() CurrentWeapon->PlayFireSoundAtLocation(this->GetTransform().GetLocation()); + MakeNoise(1,this, this->GetTransform().GetLocation()); + PlayOnFireAnimations(); CurrentWeapon->SetCurrentWeaponStatus(Cooldown); -- 2.34.1 From 78d363bc09b9843f5cb18ef776fdee92c3bca4f9 Mon Sep 17 00:00:00 2001 From: baz Date: Mon, 19 Feb 2024 21:53:19 +0000 Subject: [PATCH 11/24] Add new Sprint enemy movement speed --- Source/Nakatomi/Tasks/BTTSetMovementSpeed.cpp | 3 +++ Source/Nakatomi/Tasks/BTTSetMovementSpeed.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Source/Nakatomi/Tasks/BTTSetMovementSpeed.cpp b/Source/Nakatomi/Tasks/BTTSetMovementSpeed.cpp index afab13f..eda9a35 100644 --- a/Source/Nakatomi/Tasks/BTTSetMovementSpeed.cpp +++ b/Source/Nakatomi/Tasks/BTTSetMovementSpeed.cpp @@ -21,6 +21,9 @@ EBTNodeResult::Type UBTTSetMovementSpeed::ExecuteTask(UBehaviorTreeComponent& ow case EPatrolMovementEnum::WALK: enemyPawn->GetCharacterMovementComponent()->SetMaxWalkSpeed(walkSpeed); break; + case EPatrolMovementEnum::SPRINT: + enemyPawn->GetCharacterMovementComponent()->SetMaxWalkSpeed(sprintSpeed); + break; default: enemyPawn->GetCharacterMovementComponent()->SetMaxWalkSpeedToDefault(); break; diff --git a/Source/Nakatomi/Tasks/BTTSetMovementSpeed.h b/Source/Nakatomi/Tasks/BTTSetMovementSpeed.h index 8f09911..4a90608 100644 --- a/Source/Nakatomi/Tasks/BTTSetMovementSpeed.h +++ b/Source/Nakatomi/Tasks/BTTSetMovementSpeed.h @@ -25,6 +25,8 @@ private: float slowWalkSpeed = 250.0f; float walkSpeed = 500.0f; + + float sprintSpeed = 750.0f; public: virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) override; -- 2.34.1 From 73581f3d41b50ba6c067352aee55c21631742f69 Mon Sep 17 00:00:00 2001 From: baz Date: Mon, 19 Feb 2024 21:53:33 +0000 Subject: [PATCH 12/24] Add IsWithinRange Decorator --- .../Nakatomi/Decorators/BTDIsWithinRange.cpp | 29 +++++++++++++++++ Source/Nakatomi/Decorators/BTDIsWithinRange.h | 31 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 Source/Nakatomi/Decorators/BTDIsWithinRange.cpp create mode 100644 Source/Nakatomi/Decorators/BTDIsWithinRange.h diff --git a/Source/Nakatomi/Decorators/BTDIsWithinRange.cpp b/Source/Nakatomi/Decorators/BTDIsWithinRange.cpp new file mode 100644 index 0000000..53328ce --- /dev/null +++ b/Source/Nakatomi/Decorators/BTDIsWithinRange.cpp @@ -0,0 +1,29 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "../Decorators/BTDIsWithinRange.h" + +#include "AIController.h" +#include "navigationSystem.h" +#include "BehaviorTree/BlackboardComponent.h" +#include "Nakatomi/NakatomiCharacter.h" + +bool UBTDIsWithinRange::CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const +{ + UBlackboardComponent* BlackboardComponent = OwnerComp.GetBlackboardComponent(); + float Dist = BlackboardComponent->GetValueAsFloat(DistanceKey.SelectedKeyName); + UObject* Target = BlackboardComponent->GetValueAsObject(TargetActorKey.SelectedKeyName); + auto TargetLocation = Cast(Target)->GetActorLocation(); + UNavigationSystemV1* NavigationSystem = FNavigationSystem::GetCurrent(GetWorld()); + + APawn* pawn = OwnerComp.GetAIOwner()->GetPawn(); + + if (pawn && NavigationSystem && TargetLocation != FVector::ZeroVector) + { + double Distance = -1.0; + NavigationSystem->GetPathLength(TargetLocation, pawn->GetTransform().GetLocation(), Distance); + return Distance <= Dist ? true : false; + } + + return false; +} diff --git a/Source/Nakatomi/Decorators/BTDIsWithinRange.h b/Source/Nakatomi/Decorators/BTDIsWithinRange.h new file mode 100644 index 0000000..dce4bc0 --- /dev/null +++ b/Source/Nakatomi/Decorators/BTDIsWithinRange.h @@ -0,0 +1,31 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BehaviorTree/BTDecorator.h" +#include "BTDIsWithinRange.generated.h" + +/** + * + */ +UCLASS() +class NAKATOMI_API UBTDIsWithinRange : public UBTDecorator +{ + GENERATED_BODY() + +public: + + UPROPERTY(EditAnywhere, Category = "Options", + Meta = (AllowPrivateAccess = "true", DisplayName = "Target Actor Key")) + FBlackboardKeySelector TargetActorKey; + + UPROPERTY(EditAnywhere, Category = "Options", + Meta = (AllowPrivateAccess = "true", DisplayName = "Distance Key")) + FBlackboardKeySelector DistanceKey; + +public: + + virtual bool CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const override; + +}; -- 2.34.1 From 6ef43d5feac602f0989a5d2a778a5299e7abed0e Mon Sep 17 00:00:00 2001 From: baz Date: Mon, 19 Feb 2024 21:53:46 +0000 Subject: [PATCH 13/24] Add MoveToIdealRange Task --- Content/Enemy/Tasks/BTTMoveToIdealRange.uasset | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Content/Enemy/Tasks/BTTMoveToIdealRange.uasset diff --git a/Content/Enemy/Tasks/BTTMoveToIdealRange.uasset b/Content/Enemy/Tasks/BTTMoveToIdealRange.uasset new file mode 100644 index 0000000..5997afe --- /dev/null +++ b/Content/Enemy/Tasks/BTTMoveToIdealRange.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:35f6fe1f6c16f3a0920d3bfdfdedbfad5067979f25239d8a13df1a942305824b +size 40726 -- 2.34.1 From cc3b05d8b86def8e3a31756773ceb6a481cb63da Mon Sep 17 00:00:00 2001 From: baz Date: Mon, 19 Feb 2024 21:54:11 +0000 Subject: [PATCH 14/24] Misc Enemy Updates --- Source/Nakatomi/EPatrolMovementEnum.h | 1 + Source/Nakatomi/EnemyAIController.cpp | 29 ++++++++++++++++++++++++--- Source/Nakatomi/EnemyAIController.h | 3 +++ Source/Nakatomi/EnemyCharacter.h | 6 ++++++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Source/Nakatomi/EPatrolMovementEnum.h b/Source/Nakatomi/EPatrolMovementEnum.h index e044459..86797f1 100644 --- a/Source/Nakatomi/EPatrolMovementEnum.h +++ b/Source/Nakatomi/EPatrolMovementEnum.h @@ -12,4 +12,5 @@ enum class EPatrolMovementEnum : uint8 { SLOWWALK UMETA(DisplayName = "Slow Walk"), WALK UMETA(DisplayName = "Walk"), + SPRINT UMETA(DisplayName = "Sprint"), }; diff --git a/Source/Nakatomi/EnemyAIController.cpp b/Source/Nakatomi/EnemyAIController.cpp index f7a37d3..259e413 100644 --- a/Source/Nakatomi/EnemyAIController.cpp +++ b/Source/Nakatomi/EnemyAIController.cpp @@ -63,6 +63,9 @@ void AEnemyAIController::OnPossess(APawn* InPawn) } Blackboard->SetValueAsEnum("State", static_cast(EAIState::PASSIVE)); + + Blackboard->SetValueAsFloat("AttackRadius", enemy->AttackRadius); + Blackboard->SetValueAsFloat("DefendRadius", enemy->DefendRadius); //ensure(enemy->GetMovementComponent()->UseAccelerationForPathFollowing()); } @@ -149,9 +152,24 @@ void AEnemyAIController::OnPerceptionUpdated(const TArray& actors) continue; } - FAISenseID SightID = SightConfig->GetSenseID(); - FAISenseID HearingID = HearingConfig->GetSenseID(); - FAISenseID DamageID = DamageConfig->GetSenseID(); + FAISenseID SightID; + FAISenseID HearingID; + FAISenseID DamageID; + + if (SightConfig) + { + SightID = SightConfig->GetSenseID(); + } + + if (HearingConfig) + { + HearingID = HearingConfig->GetSenseID(); + } + + if (DamageConfig) + { + DamageID = DamageConfig->GetSenseID(); + } if (stimulus.Type == SightID) { @@ -229,6 +247,11 @@ void AEnemyAIController::SetStateAsAttacking(AActor* target) SetState(EAIState::ATTACKING); } +AActor* AEnemyAIController::GetTargetActor() +{ + return Cast(Blackboard->GetValueAsObject("TargetActor")); +} + void AEnemyAIController::SensedSight(AActor* actor, FAIStimulus& stimulus) { EAIState CurrentState = static_cast(Blackboard->GetValueAsEnum("State")); diff --git a/Source/Nakatomi/EnemyAIController.h b/Source/Nakatomi/EnemyAIController.h index d14f019..2e46abd 100644 --- a/Source/Nakatomi/EnemyAIController.h +++ b/Source/Nakatomi/EnemyAIController.h @@ -76,6 +76,9 @@ public: UFUNCTION() void SetStateAsAttacking(AActor* target); + UFUNCTION(BlueprintCallable) + AActor* GetTargetActor(); + private: void SensedSight(AActor* actor, FAIStimulus& stimulus); diff --git a/Source/Nakatomi/EnemyCharacter.h b/Source/Nakatomi/EnemyCharacter.h index c596ec2..2f7bbc3 100644 --- a/Source/Nakatomi/EnemyCharacter.h +++ b/Source/Nakatomi/EnemyCharacter.h @@ -21,6 +21,12 @@ class NAKATOMI_API AEnemyCharacter : public ANakatomiCharacter public: UPROPERTY(EditAnywhere, Meta = (AllowPrivateAccess = "true")) APatrolRoute* CurrentPatrolRoute; + + UPROPERTY(EditAnywhere) + float AttackRadius = 300.0; + + UPROPERTY(EditAnywhere) + float DefendRadius = 500.0f; private: UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) -- 2.34.1 From 7bb9c1ccee94da1bd7ecc0ec3117633b09fdfea2 Mon Sep 17 00:00:00 2001 From: baz Date: Mon, 19 Feb 2024 21:54:42 +0000 Subject: [PATCH 15/24] Add Strafe EQS --- Content/Enemy/EQS/AttackTarget.uasset | 3 +++ Content/Enemy/EQS/EQSTestingPawn.uasset | 3 +++ Content/Enemy/EQS/EQS_Strafe.uasset | 3 +++ 3 files changed, 9 insertions(+) create mode 100644 Content/Enemy/EQS/AttackTarget.uasset create mode 100644 Content/Enemy/EQS/EQSTestingPawn.uasset create mode 100644 Content/Enemy/EQS/EQS_Strafe.uasset diff --git a/Content/Enemy/EQS/AttackTarget.uasset b/Content/Enemy/EQS/AttackTarget.uasset new file mode 100644 index 0000000..76da29c --- /dev/null +++ b/Content/Enemy/EQS/AttackTarget.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8f71efccb7685f82108e667a1469fdd0792929b918e238e10b95031223a69782 +size 31667 diff --git a/Content/Enemy/EQS/EQSTestingPawn.uasset b/Content/Enemy/EQS/EQSTestingPawn.uasset new file mode 100644 index 0000000..21c2b67 --- /dev/null +++ b/Content/Enemy/EQS/EQSTestingPawn.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f3eebdb5c3e64b80dc9608a0de79f2f858198226723623675371ef87cc814c46 +size 23202 diff --git a/Content/Enemy/EQS/EQS_Strafe.uasset b/Content/Enemy/EQS/EQS_Strafe.uasset new file mode 100644 index 0000000..85cba39 --- /dev/null +++ b/Content/Enemy/EQS/EQS_Strafe.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c52d3a813cb2ace15d022913f6085d367cc4330b26c92f3c36520496121a5026 +size 7010 -- 2.34.1 From 9e81450656e85fafcba07430e78797eab2d227e4 Mon Sep 17 00:00:00 2001 From: baz Date: Mon, 19 Feb 2024 21:55:18 +0000 Subject: [PATCH 16/24] Update Worker Blackboard and Behaviour Tree --- Content/Enemy/Worker/BB_Worker.uasset | 4 ++-- Content/Enemy/Worker/BT_Worker.uasset | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Content/Enemy/Worker/BB_Worker.uasset b/Content/Enemy/Worker/BB_Worker.uasset index 9ee8152..bfc4c59 100644 --- a/Content/Enemy/Worker/BB_Worker.uasset +++ b/Content/Enemy/Worker/BB_Worker.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0389d49e48e76a626f19b5cb173168d2eb0dff74a6ba6a1db4ed6149f75b4ca7 -size 3379 +oid sha256:f11f9cbf3cdff3fad52087639d39c89321a8092ec520bf7be61fec2fed2d2844 +size 4955 diff --git a/Content/Enemy/Worker/BT_Worker.uasset b/Content/Enemy/Worker/BT_Worker.uasset index 5f426cf..bac4158 100644 --- a/Content/Enemy/Worker/BT_Worker.uasset +++ b/Content/Enemy/Worker/BT_Worker.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:96c2010017f544db0377a648fb78e655ffd93953f5adf4a6c78d32415e4f1e68 -size 35454 +oid sha256:6d797bd3ea1f4f6a3a440e7f76b16ca0c0c2fd8d6a682c177522131feef2aab2 +size 71258 -- 2.34.1 From e0fc0030f96173fb565d7c54f4a2f122d6064a30 Mon Sep 17 00:00:00 2001 From: baz Date: Mon, 19 Feb 2024 22:14:27 +0000 Subject: [PATCH 17/24] Add Find Cover EQS and Behaviour Tree tasks --- Content/Enemy/EQS/AttackTarget.uasset | 4 ++-- Content/Enemy/EQS/EQS_FindCover.uasset | 3 +++ Content/Enemy/Worker/BT_Worker.uasset | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 Content/Enemy/EQS/EQS_FindCover.uasset diff --git a/Content/Enemy/EQS/AttackTarget.uasset b/Content/Enemy/EQS/AttackTarget.uasset index 76da29c..5283654 100644 --- a/Content/Enemy/EQS/AttackTarget.uasset +++ b/Content/Enemy/EQS/AttackTarget.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8f71efccb7685f82108e667a1469fdd0792929b918e238e10b95031223a69782 -size 31667 +oid sha256:b4878cf302d1af0c0940717a91289392ddf7cae9a41fa70fd214c5a2fecf47a3 +size 31452 diff --git a/Content/Enemy/EQS/EQS_FindCover.uasset b/Content/Enemy/EQS/EQS_FindCover.uasset new file mode 100644 index 0000000..6d0efcc --- /dev/null +++ b/Content/Enemy/EQS/EQS_FindCover.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9f4fac65c93b0a643e3897612c0d8aad0090cf3e1708e62701829f5622a164ba +size 7182 diff --git a/Content/Enemy/Worker/BT_Worker.uasset b/Content/Enemy/Worker/BT_Worker.uasset index bac4158..a6a9d6a 100644 --- a/Content/Enemy/Worker/BT_Worker.uasset +++ b/Content/Enemy/Worker/BT_Worker.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6d797bd3ea1f4f6a3a440e7f76b16ca0c0c2fd8d6a682c177522131feef2aab2 -size 71258 +oid sha256:5e9ee83341f469fd59aaf70afa376fda45e3afcdabb73e4930431baabaee8677 +size 77597 -- 2.34.1 From 8603f2421bfbba182dc6d48c5b974f60627251c6 Mon Sep 17 00:00:00 2001 From: baz Date: Tue, 27 Feb 2024 20:45:09 +0000 Subject: [PATCH 18/24] Break behaviour tree components into individual behaviour trees --- Content/Enemy/BT_Attacking_State.uasset | 3 +++ Content/Enemy/BT_Find_Cover.uasset | 3 +++ Content/Enemy/BT_Fire_Weapon.uasset | 3 +++ Content/Enemy/BT_Investigating_State.uasset | 3 +++ Content/Enemy/BT_Passive_State.uasset | 3 +++ Content/Enemy/FireWeaponTasks.uasset | 3 --- Content/Enemy/Worker/BT_Worker.uasset | 4 ++-- 7 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 Content/Enemy/BT_Attacking_State.uasset create mode 100644 Content/Enemy/BT_Find_Cover.uasset create mode 100644 Content/Enemy/BT_Fire_Weapon.uasset create mode 100644 Content/Enemy/BT_Investigating_State.uasset create mode 100644 Content/Enemy/BT_Passive_State.uasset delete mode 100644 Content/Enemy/FireWeaponTasks.uasset diff --git a/Content/Enemy/BT_Attacking_State.uasset b/Content/Enemy/BT_Attacking_State.uasset new file mode 100644 index 0000000..e84ca7f --- /dev/null +++ b/Content/Enemy/BT_Attacking_State.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8a5236e64bd434f6de908e6e96b843882a5b2b94caf1301b2473f05100a85d26 +size 25814 diff --git a/Content/Enemy/BT_Find_Cover.uasset b/Content/Enemy/BT_Find_Cover.uasset new file mode 100644 index 0000000..f3f852f --- /dev/null +++ b/Content/Enemy/BT_Find_Cover.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bb8c2676663aaf0507e907e488cdb92ebc960b6ca60376058c9d51d1bf6e2935 +size 11350 diff --git a/Content/Enemy/BT_Fire_Weapon.uasset b/Content/Enemy/BT_Fire_Weapon.uasset new file mode 100644 index 0000000..fcf5807 --- /dev/null +++ b/Content/Enemy/BT_Fire_Weapon.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:16bfc29686a9f5cea58c13e7618c78b82256377c8d2313f9c484f1c7544d5441 +size 8232 diff --git a/Content/Enemy/BT_Investigating_State.uasset b/Content/Enemy/BT_Investigating_State.uasset new file mode 100644 index 0000000..53f179b --- /dev/null +++ b/Content/Enemy/BT_Investigating_State.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2bf8cd1e59417c385fe6210ceaf897fd1f71bae70f2ff5ce6f0ba4b1cb3088ca +size 10777 diff --git a/Content/Enemy/BT_Passive_State.uasset b/Content/Enemy/BT_Passive_State.uasset new file mode 100644 index 0000000..6c94d23 --- /dev/null +++ b/Content/Enemy/BT_Passive_State.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:be95ddd31183bfbbbf914ab6e5df8910b87492818d089e7ddd5f2cf9ae550ea2 +size 20045 diff --git a/Content/Enemy/FireWeaponTasks.uasset b/Content/Enemy/FireWeaponTasks.uasset deleted file mode 100644 index bb06c91..0000000 --- a/Content/Enemy/FireWeaponTasks.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:2d62b5fd4bffcbd1b1a9a8ce534518cf789216991f050a3481103f11c4313dbb -size 9411 diff --git a/Content/Enemy/Worker/BT_Worker.uasset b/Content/Enemy/Worker/BT_Worker.uasset index a6a9d6a..4827207 100644 --- a/Content/Enemy/Worker/BT_Worker.uasset +++ b/Content/Enemy/Worker/BT_Worker.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5e9ee83341f469fd59aaf70afa376fda45e3afcdabb73e4930431baabaee8677 -size 77597 +oid sha256:16efaab8807056f5c92464bd376657dc4a4edcea1b1ed26ad5f77d6f01ccd879 +size 35221 -- 2.34.1 From cc21d38a0fa03b5ab0e467576b7fb3997561ae49 Mon Sep 17 00:00:00 2001 From: baz Date: Tue, 27 Feb 2024 21:44:07 +0000 Subject: [PATCH 19/24] Add Weapon Cooldown Decorator --- Content/Enemy/BT_Attacking_State.uasset | 4 ++-- .../Nakatomi/Decorators/BTDWeaponCooldown.cpp | 23 +++++++++++++++++++ .../Nakatomi/Decorators/BTDWeaponCooldown.h | 19 +++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 Source/Nakatomi/Decorators/BTDWeaponCooldown.cpp create mode 100644 Source/Nakatomi/Decorators/BTDWeaponCooldown.h diff --git a/Content/Enemy/BT_Attacking_State.uasset b/Content/Enemy/BT_Attacking_State.uasset index e84ca7f..ad8ad93 100644 --- a/Content/Enemy/BT_Attacking_State.uasset +++ b/Content/Enemy/BT_Attacking_State.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8a5236e64bd434f6de908e6e96b843882a5b2b94caf1301b2473f05100a85d26 -size 25814 +oid sha256:d2d10560f8fc5d39c97cae7f1db8463469d5723c0966a4ee8a69fe5f986a9f0a +size 25779 diff --git a/Source/Nakatomi/Decorators/BTDWeaponCooldown.cpp b/Source/Nakatomi/Decorators/BTDWeaponCooldown.cpp new file mode 100644 index 0000000..3855d0b --- /dev/null +++ b/Source/Nakatomi/Decorators/BTDWeaponCooldown.cpp @@ -0,0 +1,23 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "../Decorators/BTDWeaponCooldown.h" + +#include "AIController.h" +#include "Nakatomi/EnemyCharacter.h" + +void UBTDWeaponCooldown::TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds) +{ + AEnemyCharacter* EnemyCharacter = Cast(OwnerComp.GetAIOwner()->GetPawn()); + + if (EnemyCharacter && EnemyCharacter->GetCurrentWeapon()) + { + const float Cooldown = EnemyCharacter->GetCurrentWeapon()->GetWeaponProperties()->WeaponCooldown; + if (CoolDownTime != Cooldown) + { + CoolDownTime = Cooldown; + } + } + + Super::TickNode(OwnerComp, NodeMemory, DeltaSeconds); +} diff --git a/Source/Nakatomi/Decorators/BTDWeaponCooldown.h b/Source/Nakatomi/Decorators/BTDWeaponCooldown.h new file mode 100644 index 0000000..5367200 --- /dev/null +++ b/Source/Nakatomi/Decorators/BTDWeaponCooldown.h @@ -0,0 +1,19 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BehaviorTree/Decorators/BTDecorator_Cooldown.h" +#include "BTDWeaponCooldown.generated.h" + +/** + * + */ +UCLASS() +class NAKATOMI_API UBTDWeaponCooldown : public UBTDecorator_Cooldown +{ + GENERATED_BODY() + +protected: + virtual void TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds) override; +}; -- 2.34.1 From 6a30ddae07ce781320ba0195a6bc82948d3b2b07 Mon Sep 17 00:00:00 2001 From: baz Date: Tue, 27 Feb 2024 23:18:07 +0000 Subject: [PATCH 20/24] Refine Ranged Enemy functionality and hide on low health --- Content/Enemy/BT_Attacking_State.uasset | 4 +-- Content/Enemy/BT_Find_Cover.uasset | 4 +-- Content/Enemy/EQS/AttackTarget.uasset | 2 +- Content/Enemy/EQS/EQS_FindIdealRange.uasset | 3 ++ Content/Enemy/Worker/AIC_Worker.uasset | 4 +-- Content/Enemy/Worker/BB_Worker.uasset | 4 +-- Content/Enemy/Worker/BT_Worker.uasset | 4 +-- Content/Enemy/Worker/C_Worker.uasset | 4 +-- .../Enemy/Worker/PatrolMovementSpeed.uasset | 3 -- .../Nakatomi/Decorators/BTDCanSeeTarget.cpp | 27 +++++++++++++++++ Source/Nakatomi/Decorators/BTDCanSeeTarget.h | 24 +++++++++++++++ .../Decorators/BTDIsHealthBelowThreshold.cpp | 14 +++++++++ .../Decorators/BTDIsHealthBelowThreshold.h | 29 +++++++++++++++++++ Source/Nakatomi/EnemyCharacter.cpp | 18 +++++++++++- Source/Nakatomi/EnemyCharacter.h | 3 ++ 15 files changed, 130 insertions(+), 17 deletions(-) create mode 100644 Content/Enemy/EQS/EQS_FindIdealRange.uasset delete mode 100644 Content/Enemy/Worker/PatrolMovementSpeed.uasset create mode 100644 Source/Nakatomi/Decorators/BTDCanSeeTarget.cpp create mode 100644 Source/Nakatomi/Decorators/BTDCanSeeTarget.h create mode 100644 Source/Nakatomi/Decorators/BTDIsHealthBelowThreshold.cpp create mode 100644 Source/Nakatomi/Decorators/BTDIsHealthBelowThreshold.h diff --git a/Content/Enemy/BT_Attacking_State.uasset b/Content/Enemy/BT_Attacking_State.uasset index ad8ad93..4d6bcdc 100644 --- a/Content/Enemy/BT_Attacking_State.uasset +++ b/Content/Enemy/BT_Attacking_State.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d2d10560f8fc5d39c97cae7f1db8463469d5723c0966a4ee8a69fe5f986a9f0a -size 25779 +oid sha256:046a90ce16e45a46b81d069cd5947962e106ec8eabdefd48afcf3b1e7c5504b2 +size 29454 diff --git a/Content/Enemy/BT_Find_Cover.uasset b/Content/Enemy/BT_Find_Cover.uasset index f3f852f..dc3d704 100644 --- a/Content/Enemy/BT_Find_Cover.uasset +++ b/Content/Enemy/BT_Find_Cover.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bb8c2676663aaf0507e907e488cdb92ebc960b6ca60376058c9d51d1bf6e2935 -size 11350 +oid sha256:f73ce2850790ae0b631e6065d74cb62fb9f0c22945ff072d9783b4d9fec0d185 +size 11379 diff --git a/Content/Enemy/EQS/AttackTarget.uasset b/Content/Enemy/EQS/AttackTarget.uasset index 5283654..e25ef2e 100644 --- a/Content/Enemy/EQS/AttackTarget.uasset +++ b/Content/Enemy/EQS/AttackTarget.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b4878cf302d1af0c0940717a91289392ddf7cae9a41fa70fd214c5a2fecf47a3 +oid sha256:c301262f435afa726497425b119c5f5aab80501dd20bee5476a7cfa4dcf4ba3a size 31452 diff --git a/Content/Enemy/EQS/EQS_FindIdealRange.uasset b/Content/Enemy/EQS/EQS_FindIdealRange.uasset new file mode 100644 index 0000000..efb8de4 --- /dev/null +++ b/Content/Enemy/EQS/EQS_FindIdealRange.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:69da4619195e312747cc99b0a65cebe3cb6dba7cff6d7f85d65a5bf630b177a6 +size 9598 diff --git a/Content/Enemy/Worker/AIC_Worker.uasset b/Content/Enemy/Worker/AIC_Worker.uasset index 105a3ce..517c5f0 100644 --- a/Content/Enemy/Worker/AIC_Worker.uasset +++ b/Content/Enemy/Worker/AIC_Worker.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:50deb580132c8059cab1d6b9cd9556977ece12cd3300827cb696e1940801377a -size 19654 +oid sha256:eabfe5d0b7d9fb24fd797f5ab6c6b16b90c2dcdfd1d630b7f62645bec170d357 +size 20894 diff --git a/Content/Enemy/Worker/BB_Worker.uasset b/Content/Enemy/Worker/BB_Worker.uasset index bfc4c59..ca26bb3 100644 --- a/Content/Enemy/Worker/BB_Worker.uasset +++ b/Content/Enemy/Worker/BB_Worker.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f11f9cbf3cdff3fad52087639d39c89321a8092ec520bf7be61fec2fed2d2844 -size 4955 +oid sha256:bfe99d758ae52a5cdc8c067a64fb4deb766eb1229663686533360cf4f1c8079a +size 5247 diff --git a/Content/Enemy/Worker/BT_Worker.uasset b/Content/Enemy/Worker/BT_Worker.uasset index 4827207..6dd4eb7 100644 --- a/Content/Enemy/Worker/BT_Worker.uasset +++ b/Content/Enemy/Worker/BT_Worker.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:16efaab8807056f5c92464bd376657dc4a4edcea1b1ed26ad5f77d6f01ccd879 -size 35221 +oid sha256:2a3f2eb952d460100efe964df20f5576e6ea4d788a2a6d32b5442efaba3bf5dc +size 33603 diff --git a/Content/Enemy/Worker/C_Worker.uasset b/Content/Enemy/Worker/C_Worker.uasset index 22843bf..cdcd13d 100644 --- a/Content/Enemy/Worker/C_Worker.uasset +++ b/Content/Enemy/Worker/C_Worker.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cc57648ca59ab9181814d46afa44701b6ab3dd1d1114d60963cda8729b1aee7c -size 40112 +oid sha256:1307c6303ccede36903875211f758077933ef495e0fb8aebe8c45147e9cfb66d +size 38588 diff --git a/Content/Enemy/Worker/PatrolMovementSpeed.uasset b/Content/Enemy/Worker/PatrolMovementSpeed.uasset deleted file mode 100644 index e0d6963..0000000 --- a/Content/Enemy/Worker/PatrolMovementSpeed.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:e9cf595f36b15dce976ce9e9506d74974b44264319c5a4da0a9f76dc7feb8eac -size 2770 diff --git a/Source/Nakatomi/Decorators/BTDCanSeeTarget.cpp b/Source/Nakatomi/Decorators/BTDCanSeeTarget.cpp new file mode 100644 index 0000000..75302e2 --- /dev/null +++ b/Source/Nakatomi/Decorators/BTDCanSeeTarget.cpp @@ -0,0 +1,27 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "../Decorators/BTDCanSeeTarget.h" + +#include "AIController.h" +#include "BehaviorTree/BlackboardComponent.h" + +bool UBTDCanSeeTarget::CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const +{ + FHitResult HitResult; + + FVector Start = OwnerComp.GetAIOwner()->GetPawn()->GetActorLocation(); + + UBlackboardComponent* BlackboardComponent = OwnerComp.GetBlackboardComponent(); + AActor* TargetActor = Cast(BlackboardComponent->GetValueAsObject(TargetActorKey.SelectedKeyName)); + FVector End = TargetActor->GetActorLocation(); + + GetWorld()->LineTraceSingleByChannel(HitResult, Start, End, ECC_Pawn); + + if (HitResult.GetActor()) + { + return true; + } + + return false; +} diff --git a/Source/Nakatomi/Decorators/BTDCanSeeTarget.h b/Source/Nakatomi/Decorators/BTDCanSeeTarget.h new file mode 100644 index 0000000..e926c3b --- /dev/null +++ b/Source/Nakatomi/Decorators/BTDCanSeeTarget.h @@ -0,0 +1,24 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BehaviorTree/BTDecorator.h" +#include "BTDCanSeeTarget.generated.h" + +/** + * + */ +UCLASS() +class NAKATOMI_API UBTDCanSeeTarget : public UBTDecorator +{ + GENERATED_BODY() + +public: + UPROPERTY(EditAnywhere, Category = "Options", + Meta = (AllowPrivateAccess = "true", DisplayName = "Target Actor Key")) + FBlackboardKeySelector TargetActorKey; + +protected: + virtual bool CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const override; +}; diff --git a/Source/Nakatomi/Decorators/BTDIsHealthBelowThreshold.cpp b/Source/Nakatomi/Decorators/BTDIsHealthBelowThreshold.cpp new file mode 100644 index 0000000..6e21503 --- /dev/null +++ b/Source/Nakatomi/Decorators/BTDIsHealthBelowThreshold.cpp @@ -0,0 +1,14 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "../Decorators/BTDIsHealthBelowThreshold.h" + +#include "BehaviorTree/BlackboardComponent.h" + +bool UBTDIsHealthBelowThreshold::CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const +{ + UBlackboardComponent* BlackboardComponent = OwnerComp.GetBlackboardComponent(); + float currentHealth = BlackboardComponent->GetValueAsFloat(CurrentHealthKey.SelectedKeyName); + + return currentHealth <= HealthThreshold ? true : false; +} diff --git a/Source/Nakatomi/Decorators/BTDIsHealthBelowThreshold.h b/Source/Nakatomi/Decorators/BTDIsHealthBelowThreshold.h new file mode 100644 index 0000000..a65081d --- /dev/null +++ b/Source/Nakatomi/Decorators/BTDIsHealthBelowThreshold.h @@ -0,0 +1,29 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BehaviorTree/BTDecorator.h" +#include "BTDIsHealthBelowThreshold.generated.h" + +/** + * + */ +UCLASS() +class NAKATOMI_API UBTDIsHealthBelowThreshold : public UBTDecorator +{ + GENERATED_BODY() + +public: + + UPROPERTY(EditAnywhere, Category = "Options", + Meta = (AllowPrivateAccess = "true", DisplayName = "Current Health Key")) + FBlackboardKeySelector CurrentHealthKey; + + UPROPERTY(EditAnywhere, Category = "Options", + Meta = (AllowPrivateAccess = "true", DisplayName = "Health Threshold")) + float HealthThreshold = 25.0f; + +protected: + virtual bool CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const override; +}; diff --git a/Source/Nakatomi/EnemyCharacter.cpp b/Source/Nakatomi/EnemyCharacter.cpp index 8018d9e..b23e46f 100644 --- a/Source/Nakatomi/EnemyCharacter.cpp +++ b/Source/Nakatomi/EnemyCharacter.cpp @@ -4,6 +4,9 @@ #include "EnemyAIController.h" #include "EnemyHealthComponent.h" #include "InteractableComponent.h" +#include "BehaviorTree/BehaviorTree.h" +#include "BehaviorTree/BlackboardComponent.h" +#include "BehaviorTree/BlackboardData.h" #define COLLISION_WEAPON ECC_GameTraceChannel1 @@ -16,7 +19,7 @@ AEnemyCharacter::AEnemyCharacter(const FObjectInitializer& ObjectInitializer) : GetHealthComponent()->OnDamaged.BindUFunction(this, "OnDamaged"); GetHealthComponent()->OnDeath.BindUFunction(this, "OnDeath"); GetHealthComponent()->SetMaxHealth(100.0f); - + this->Tags.Add(FName("Enemy")); } @@ -54,6 +57,10 @@ void AEnemyCharacter::WeaponCooldownHandler() void AEnemyCharacter::BeginPlay() { Super::BeginPlay(); + + AEnemyAIController* controller = Cast(GetController()); + controller->GetBlackboardComponent()->SetValueAsFloat("CurrentHealth", GetHealthComponent()->GetCurrentHealth()); + GetHealthComponent()->OnDamaged.BindUFunction(this, "OnDamaged"); } void AEnemyCharacter::PlayOnFireAnimations() @@ -130,3 +137,12 @@ void AEnemyCharacter::ProcessHits(TArray hits) } } } + +void AEnemyCharacter::OnDamaged() +{ + Super::OnDamaged(); + + AEnemyAIController* controller = Cast(GetController()); + controller->GetBlackboardComponent()->SetValueAsFloat("CurrentHealth", GetHealthComponent()->GetCurrentHealth()); +} + diff --git a/Source/Nakatomi/EnemyCharacter.h b/Source/Nakatomi/EnemyCharacter.h index 2f7bbc3..3e24291 100644 --- a/Source/Nakatomi/EnemyCharacter.h +++ b/Source/Nakatomi/EnemyCharacter.h @@ -55,4 +55,7 @@ private: virtual void CalculateHits(TArray* hits) override; virtual void ProcessHits(TArray hits) override; + +protected: + virtual void OnDamaged() override; }; -- 2.34.1 From e89c8cd0872466633f3d1f27383c4bddcdb27e63 Mon Sep 17 00:00:00 2001 From: baz Date: Thu, 29 Feb 2024 17:16:15 +0000 Subject: [PATCH 21/24] Move generic behavior trees into dedicated folder --- Content/Enemy/BT_Attacking_State.uasset | 3 --- Content/Enemy/BT_Find_Cover.uasset | 3 --- Content/Enemy/BT_Fire_Weapon.uasset | 3 --- Content/Enemy/BT_Investigating_State.uasset | 3 --- Content/Enemy/BT_Passive_State.uasset | 3 --- Content/Enemy/BehaviorTrees/BT_Attacking_State.uasset | 3 +++ Content/Enemy/BehaviorTrees/BT_Find_Cover.uasset | 3 +++ Content/Enemy/BehaviorTrees/BT_Fire_Weapon.uasset | 3 +++ Content/Enemy/BehaviorTrees/BT_Investigating_State.uasset | 3 +++ Content/Enemy/BehaviorTrees/BT_Passive_State.uasset | 3 +++ 10 files changed, 15 insertions(+), 15 deletions(-) delete mode 100644 Content/Enemy/BT_Attacking_State.uasset delete mode 100644 Content/Enemy/BT_Find_Cover.uasset delete mode 100644 Content/Enemy/BT_Fire_Weapon.uasset delete mode 100644 Content/Enemy/BT_Investigating_State.uasset delete mode 100644 Content/Enemy/BT_Passive_State.uasset create mode 100644 Content/Enemy/BehaviorTrees/BT_Attacking_State.uasset create mode 100644 Content/Enemy/BehaviorTrees/BT_Find_Cover.uasset create mode 100644 Content/Enemy/BehaviorTrees/BT_Fire_Weapon.uasset create mode 100644 Content/Enemy/BehaviorTrees/BT_Investigating_State.uasset create mode 100644 Content/Enemy/BehaviorTrees/BT_Passive_State.uasset diff --git a/Content/Enemy/BT_Attacking_State.uasset b/Content/Enemy/BT_Attacking_State.uasset deleted file mode 100644 index 4d6bcdc..0000000 --- a/Content/Enemy/BT_Attacking_State.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:046a90ce16e45a46b81d069cd5947962e106ec8eabdefd48afcf3b1e7c5504b2 -size 29454 diff --git a/Content/Enemy/BT_Find_Cover.uasset b/Content/Enemy/BT_Find_Cover.uasset deleted file mode 100644 index dc3d704..0000000 --- a/Content/Enemy/BT_Find_Cover.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f73ce2850790ae0b631e6065d74cb62fb9f0c22945ff072d9783b4d9fec0d185 -size 11379 diff --git a/Content/Enemy/BT_Fire_Weapon.uasset b/Content/Enemy/BT_Fire_Weapon.uasset deleted file mode 100644 index fcf5807..0000000 --- a/Content/Enemy/BT_Fire_Weapon.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:16bfc29686a9f5cea58c13e7618c78b82256377c8d2313f9c484f1c7544d5441 -size 8232 diff --git a/Content/Enemy/BT_Investigating_State.uasset b/Content/Enemy/BT_Investigating_State.uasset deleted file mode 100644 index 53f179b..0000000 --- a/Content/Enemy/BT_Investigating_State.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:2bf8cd1e59417c385fe6210ceaf897fd1f71bae70f2ff5ce6f0ba4b1cb3088ca -size 10777 diff --git a/Content/Enemy/BT_Passive_State.uasset b/Content/Enemy/BT_Passive_State.uasset deleted file mode 100644 index 6c94d23..0000000 --- a/Content/Enemy/BT_Passive_State.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:be95ddd31183bfbbbf914ab6e5df8910b87492818d089e7ddd5f2cf9ae550ea2 -size 20045 diff --git a/Content/Enemy/BehaviorTrees/BT_Attacking_State.uasset b/Content/Enemy/BehaviorTrees/BT_Attacking_State.uasset new file mode 100644 index 0000000..17616be --- /dev/null +++ b/Content/Enemy/BehaviorTrees/BT_Attacking_State.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e4aa6120a1019fa9a70169fd1bc87de566e9653df822c5d17d9043276c567e2f +size 29454 diff --git a/Content/Enemy/BehaviorTrees/BT_Find_Cover.uasset b/Content/Enemy/BehaviorTrees/BT_Find_Cover.uasset new file mode 100644 index 0000000..8a9e2d0 --- /dev/null +++ b/Content/Enemy/BehaviorTrees/BT_Find_Cover.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b8ae5b944c94321fc570d414fea297adbe0fa0d5a1998fa76579a61fd8a73e5f +size 11351 diff --git a/Content/Enemy/BehaviorTrees/BT_Fire_Weapon.uasset b/Content/Enemy/BehaviorTrees/BT_Fire_Weapon.uasset new file mode 100644 index 0000000..6389b51 --- /dev/null +++ b/Content/Enemy/BehaviorTrees/BT_Fire_Weapon.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:aa0777bdb6070ed25054cc1d38888df0aaa066ce499fdea01c556ee322156f43 +size 8261 diff --git a/Content/Enemy/BehaviorTrees/BT_Investigating_State.uasset b/Content/Enemy/BehaviorTrees/BT_Investigating_State.uasset new file mode 100644 index 0000000..5fe29e8 --- /dev/null +++ b/Content/Enemy/BehaviorTrees/BT_Investigating_State.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:167d55cce0fcf3684613917077949dd2e922a6cfd46014b4492926e59de0bbac +size 10806 diff --git a/Content/Enemy/BehaviorTrees/BT_Passive_State.uasset b/Content/Enemy/BehaviorTrees/BT_Passive_State.uasset new file mode 100644 index 0000000..809608d --- /dev/null +++ b/Content/Enemy/BehaviorTrees/BT_Passive_State.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:db3c0d6c6178ee434cddbaf740563546f7b3c78655dea35c0e5bd8f77d1a0233 +size 20074 -- 2.34.1 From 45106c47cb5d6796a5e230826ccf0d2591acaaa0 Mon Sep 17 00:00:00 2001 From: baz Date: Thu, 29 Feb 2024 17:16:41 +0000 Subject: [PATCH 22/24] Move and make Worker Blackboard generic --- Content/Enemy/BB_Base_Enemy.uasset | 3 +++ Content/Enemy/Worker/BB_Worker.uasset | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 Content/Enemy/BB_Base_Enemy.uasset delete mode 100644 Content/Enemy/Worker/BB_Worker.uasset diff --git a/Content/Enemy/BB_Base_Enemy.uasset b/Content/Enemy/BB_Base_Enemy.uasset new file mode 100644 index 0000000..4754676 --- /dev/null +++ b/Content/Enemy/BB_Base_Enemy.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7d05342d401b4b8dc0c3e28fb9a9169cc305b78b1029be1d7f5d85d0d45c1014 +size 5253 diff --git a/Content/Enemy/Worker/BB_Worker.uasset b/Content/Enemy/Worker/BB_Worker.uasset deleted file mode 100644 index ca26bb3..0000000 --- a/Content/Enemy/Worker/BB_Worker.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:bfe99d758ae52a5cdc8c067a64fb4deb766eb1229663686533360cf4f1c8079a -size 5247 -- 2.34.1 From d19ff8180b0f92d1c4aa15feab8a644257206ddc Mon Sep 17 00:00:00 2001 From: baz Date: Thu, 29 Feb 2024 17:27:09 +0000 Subject: [PATCH 23/24] new worker --- Content/Enemy/Worker/BT_Worker.uasset | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Content/Enemy/Worker/BT_Worker.uasset b/Content/Enemy/Worker/BT_Worker.uasset index 6dd4eb7..2727938 100644 --- a/Content/Enemy/Worker/BT_Worker.uasset +++ b/Content/Enemy/Worker/BT_Worker.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2a3f2eb952d460100efe964df20f5576e6ea4d788a2a6d32b5442efaba3bf5dc -size 33603 +oid sha256:1aa0439b160b9cc4a744f2efdbb6131ffeb1aec8a50685dea2f921cae8be614e +size 33660 -- 2.34.1 From 1e91cd48aabdae0c5ff69316be10830533049246 Mon Sep 17 00:00:00 2001 From: baz Date: Thu, 29 Feb 2024 17:27:23 +0000 Subject: [PATCH 24/24] misc schanges --- Content/Levels/TestLevel.umap | 4 ++-- Content/Weapons/Pistol/Pistol.uasset | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Content/Levels/TestLevel.umap b/Content/Levels/TestLevel.umap index 00bb672..c9de13a 100644 --- a/Content/Levels/TestLevel.umap +++ b/Content/Levels/TestLevel.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2982149907d00efe6509ec3e0258f31442fedeb988fd15132f604413a0de1a1c -size 47583 +oid sha256:26a15ae4ce8cbab7bc63b8abb00075551a55cae73ce5434bd8c0a8446be1ee95 +size 77030 diff --git a/Content/Weapons/Pistol/Pistol.uasset b/Content/Weapons/Pistol/Pistol.uasset index 5959a19..7c06c57 100644 --- a/Content/Weapons/Pistol/Pistol.uasset +++ b/Content/Weapons/Pistol/Pistol.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b97899ccc443870d47aa50df9974339e0487633ebcc22d6b2b884292ea266ca2 +oid sha256:42b20fafef19a1ca1ce6b3a428f4dc5c358054ef427e00862851aa48895a8ebe size 22640 -- 2.34.1