From e77b6cce3563e4b1621915b61a29565149a20906 Mon Sep 17 00:00:00 2001 From: Louis Hobbs Date: Mon, 13 Mar 2023 22:23:42 +0000 Subject: [PATCH] Create AI `TaskFireWeapon` node --- Source/Nakatomi/TaskFireWeapon.cpp | 20 ++++++++++++++++++++ Source/Nakatomi/TaskFireWeapon.h | 23 +++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 Source/Nakatomi/TaskFireWeapon.cpp create mode 100644 Source/Nakatomi/TaskFireWeapon.h diff --git a/Source/Nakatomi/TaskFireWeapon.cpp b/Source/Nakatomi/TaskFireWeapon.cpp new file mode 100644 index 0000000..54671f3 --- /dev/null +++ b/Source/Nakatomi/TaskFireWeapon.cpp @@ -0,0 +1,20 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#include "TaskFireWeapon.h" +#include "EnemyAIController.h" + +EBTNodeResult::Type UTaskFireWeapon::ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) +{ + auto enemyController = Cast(owner.GetAIOwner()); + auto enemyPawn = Cast(enemyController->GetPawn()); + auto blackboardComponent = owner.GetBlackboardComponent(); + auto playerCharacter = Cast(blackboardComponent->GetValueAsObject(TargetActor.SelectedKeyName)); + + if (enemyPawn && playerCharacter) + { + enemyPawn->OnFire(); + return EBTNodeResult::Succeeded; + } + + return EBTNodeResult::Failed; +} diff --git a/Source/Nakatomi/TaskFireWeapon.h b/Source/Nakatomi/TaskFireWeapon.h new file mode 100644 index 0000000..ae727b4 --- /dev/null +++ b/Source/Nakatomi/TaskFireWeapon.h @@ -0,0 +1,23 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BehaviorTree/BTTaskNode.h" +#include "TaskFireWeapon.generated.h" + +/** + * + */ +UCLASS() +class NAKATOMI_API UTaskFireWeapon : public UBTTaskNode +{ + GENERATED_BODY() + +public: + UPROPERTY(EditAnywhere, Category = "Options", Meta = (AllowPrivateAccess = "true", DisplayName = "Target Actor Key")) + FBlackboardKeySelector TargetActor; + + virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) override; + +};