From 408954c96d4190c19a6ac0c0ad0738206121bc21 Mon Sep 17 00:00:00 2001 From: baz Date: Thu, 8 Feb 2024 18:30:33 +0000 Subject: [PATCH] Create Set Focus Task --- Source/Nakatomi/Tasks/BTTClearFocus.cpp | 5 +++++ Source/Nakatomi/Tasks/BTTClearFocus.h | 17 +++++++++++++++++ Source/Nakatomi/Tasks/BTTSetFocus.cpp | 20 ++++++++++++++++++++ Source/Nakatomi/Tasks/BTTSetFocus.h | 25 +++++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 Source/Nakatomi/Tasks/BTTClearFocus.cpp create mode 100644 Source/Nakatomi/Tasks/BTTClearFocus.h create mode 100644 Source/Nakatomi/Tasks/BTTSetFocus.cpp create mode 100644 Source/Nakatomi/Tasks/BTTSetFocus.h diff --git a/Source/Nakatomi/Tasks/BTTClearFocus.cpp b/Source/Nakatomi/Tasks/BTTClearFocus.cpp new file mode 100644 index 0000000..0cec164 --- /dev/null +++ b/Source/Nakatomi/Tasks/BTTClearFocus.cpp @@ -0,0 +1,5 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Tasks/BTTClearFocus.h" + diff --git a/Source/Nakatomi/Tasks/BTTClearFocus.h b/Source/Nakatomi/Tasks/BTTClearFocus.h new file mode 100644 index 0000000..7e7e552 --- /dev/null +++ b/Source/Nakatomi/Tasks/BTTClearFocus.h @@ -0,0 +1,17 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BehaviorTree/BTTaskNode.h" +#include "BTTClearFocus.generated.h" + +/** + * + */ +UCLASS() +class NAKATOMI_API UBTTClearFocus : public UBTTaskNode +{ + GENERATED_BODY() + +}; diff --git a/Source/Nakatomi/Tasks/BTTSetFocus.cpp b/Source/Nakatomi/Tasks/BTTSetFocus.cpp new file mode 100644 index 0000000..7fa63c7 --- /dev/null +++ b/Source/Nakatomi/Tasks/BTTSetFocus.cpp @@ -0,0 +1,20 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "../Tasks/BTTSetFocus.h" + +#include "BehaviorTree/BlackboardComponent.h" +#include "Nakatomi/EnemyAIController.h" +#include "Nakatomi/PlayerCharacter.h" + +EBTNodeResult::Type UBTTSetFocus::ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) +{ + UBlackboardComponent* BlackboardComponent = owner.GetBlackboardComponent(); + UObject* actor = BlackboardComponent->GetValueAsObject(TargetActorKey.SelectedKeyName); + APlayerCharacter* PlayerCharacter = Cast(actor); + + AEnemyAIController* enemyController = Cast(owner.GetAIOwner()); + enemyController->SetFocus(PlayerCharacter, EAIFocusPriority::Gameplay); + + return EBTNodeResult::Succeeded; +} diff --git a/Source/Nakatomi/Tasks/BTTSetFocus.h b/Source/Nakatomi/Tasks/BTTSetFocus.h new file mode 100644 index 0000000..4f13e87 --- /dev/null +++ b/Source/Nakatomi/Tasks/BTTSetFocus.h @@ -0,0 +1,25 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BehaviorTree/BTTaskNode.h" +#include "BTTSetFocus.generated.h" + +/** + * + */ +UCLASS() +class NAKATOMI_API UBTTSetFocus : public UBTTaskNode +{ + GENERATED_BODY() + +public: + UPROPERTY(EditAnywhere, Category = "Options", + Meta = (AllowPrivateAccess = "true", DisplayName = "Target Actor Key")) + FBlackboardKeySelector TargetActorKey; + +public: + virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) override; + +};