From 0fd27b6745c738b5e107ef3601a1acc230422807 Mon Sep 17 00:00:00 2001 From: baz Date: Fri, 9 Feb 2024 18:21:18 +0000 Subject: [PATCH] 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; +};