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