Add BT Services and Tasks for Animation Triggers
This commit is contained in:
parent
7a9488e13a
commit
0fb24cd386
@ -63,6 +63,14 @@ void AEnemyCharacter::EquipWeapon_Implementation()
|
||||
{
|
||||
}
|
||||
|
||||
void AEnemyCharacter::DeEquipWeapon_Implementation()
|
||||
{
|
||||
}
|
||||
|
||||
void AEnemyCharacter::SetFiring_Implementation(bool IsFiring)
|
||||
{
|
||||
}
|
||||
|
||||
void AEnemyCharacter::HuntPlayer(FVector PlayerLastKnownLocation)
|
||||
{
|
||||
if (!IsValid(this)) return;
|
||||
|
@ -16,6 +16,8 @@ class ENDLESSVENDETTA_API AEnemyCharacter : public AAICharacter
|
||||
public:
|
||||
// Sets default values for this character's properties
|
||||
AEnemyCharacter();
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
bool WeaponRaised = false;
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
@ -29,9 +31,16 @@ public:
|
||||
void SubscribeToGroupAIEvents(class AAIControlHub* ControlHub);
|
||||
void SetLocalAlertLevel(int NewAlertLevel) const;
|
||||
|
||||
//Animation Blueprint Triggers
|
||||
UFUNCTION(BlueprintNativeEvent)
|
||||
void EquipWeapon();
|
||||
virtual void EquipWeapon_Implementation();
|
||||
UFUNCTION(BlueprintNativeEvent)
|
||||
void DeEquipWeapon();
|
||||
virtual void DeEquipWeapon_Implementation();
|
||||
UFUNCTION(BlueprintNativeEvent)
|
||||
void SetFiring(bool IsFiring);
|
||||
virtual void SetFiring_Implementation(bool IsFiring);
|
||||
|
||||
private:
|
||||
FDelegateHandle AlertLevelDelegateHandle;
|
||||
|
@ -0,0 +1,24 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "BTService_StopAttack.h"
|
||||
|
||||
#include "EndlessVendetta/AI/AI_EnemyController.h"
|
||||
#include "EndlessVendetta/AI/EnemyCharacter.h"
|
||||
|
||||
UBTService_StopAttack::UBTService_StopAttack()
|
||||
{
|
||||
NodeName = "Stop Attack";
|
||||
}
|
||||
|
||||
void UBTService_StopAttack::OnBecomeRelevant(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
|
||||
{
|
||||
Super::OnBecomeRelevant(OwnerComp, NodeMemory);
|
||||
if (const AAI_EnemyController* const EnemyController = Cast<AAI_EnemyController>(OwnerComp.GetAIOwner()))
|
||||
{
|
||||
if (AEnemyCharacter* const EnemyCharacter = Cast<AEnemyCharacter>(EnemyController->GetPawn()))
|
||||
{
|
||||
EnemyCharacter->SetFiring(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "BehaviorTree/Services/BTService_BlackboardBase.h"
|
||||
#include "BTService_StopAttack.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class ENDLESSVENDETTA_API UBTService_StopAttack : public UBTService_BlackboardBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UBTService_StopAttack();
|
||||
virtual void OnBecomeRelevant(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) override;
|
||||
};
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "EndlessVendetta/AI/AI_EnemyController.h"
|
||||
#include "BehaviorTree/BlackboardComponent.h"
|
||||
#include "EndlessVendetta/AI/EnemyCharacter.h"
|
||||
|
||||
UBTTask_AttackPlayer::UBTTask_AttackPlayer(FObjectInitializer const& ObjectInitializer)
|
||||
{
|
||||
@ -21,8 +22,13 @@ EBTNodeResult::Type UBTTask_AttackPlayer::ExecuteTask(UBehaviorTreeComponent& Ow
|
||||
FVector const PlayerLocation = Blackboard->GetValueAsVector("TargetLocation");
|
||||
DrawDebugLine(GetWorld(), Origin, PlayerLocation, FColor::Green, false, 1.f, 0, 1.f);
|
||||
|
||||
FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
|
||||
return EBTNodeResult::Succeeded;
|
||||
if (AEnemyCharacter* const EnemyCharacter = Cast<AEnemyCharacter>(AIController->GetPawn()))
|
||||
{
|
||||
EnemyCharacter->SetFiring(true);
|
||||
|
||||
FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
|
||||
return EBTNodeResult::Succeeded;
|
||||
}
|
||||
}
|
||||
}
|
||||
return EBTNodeResult::Failed;
|
||||
|
@ -0,0 +1,32 @@
|
||||
// Fill out your copyright notice in the Description page of PrBTTask_LowerWeapon.h"
|
||||
|
||||
#include "BTTask_LowerWeapon.h"
|
||||
#include "EndlessVendetta/AI/AI_EnemyController.h"
|
||||
#include "EndlessVendetta/AI/EnemyCharacter.h"
|
||||
|
||||
UBTTask_LowerWeapon::UBTTask_LowerWeapon()
|
||||
{
|
||||
NodeName = "Lower Weapon";
|
||||
}
|
||||
|
||||
EBTNodeResult::Type UBTTask_LowerWeapon::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
|
||||
{
|
||||
if (const AAI_EnemyController* const AIEnemyController = Cast<AAI_EnemyController>(OwnerComp.GetAIOwner()))
|
||||
{
|
||||
if (AEnemyCharacter* const EnemyCharacter = Cast<AEnemyCharacter>(AIEnemyController->GetPawn()))
|
||||
{
|
||||
if (!EnemyCharacter->WeaponRaised)
|
||||
{
|
||||
FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
|
||||
return EBTNodeResult::Succeeded;
|
||||
}
|
||||
EnemyCharacter->DeEquipWeapon();
|
||||
EnemyCharacter->WeaponRaised = false;
|
||||
|
||||
FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
|
||||
return EBTNodeResult::Succeeded;
|
||||
}
|
||||
}
|
||||
|
||||
return EBTNodeResult::Failed;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "BehaviorTree/Tasks/BTTask_BlackboardBase.h"
|
||||
#include "BTTask_LowerWeapon.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class ENDLESSVENDETTA_API UBTTask_LowerWeapon : public UBTTask_BlackboardBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UBTTask_LowerWeapon();
|
||||
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) override;
|
||||
|
||||
};
|
@ -0,0 +1,34 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "BTTask_RaiseWeapon.h"
|
||||
#include "EndlessVendetta/AI/AI_EnemyController.h"
|
||||
#include "EndlessVendetta/AI/EnemyCharacter.h"
|
||||
|
||||
UBTTask_RaiseWeapon::UBTTask_RaiseWeapon()
|
||||
{
|
||||
NodeName = "Raise Weapon";
|
||||
}
|
||||
|
||||
EBTNodeResult::Type UBTTask_RaiseWeapon::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
|
||||
{
|
||||
if (const AAI_EnemyController* const AIEnemyController = Cast<AAI_EnemyController>(OwnerComp.GetAIOwner()))
|
||||
{
|
||||
if (AEnemyCharacter* const EnemyCharacter = Cast<AEnemyCharacter>(AIEnemyController->GetPawn()))
|
||||
{
|
||||
if (EnemyCharacter->WeaponRaised)
|
||||
{
|
||||
FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
|
||||
return EBTNodeResult::Succeeded;
|
||||
}
|
||||
|
||||
EnemyCharacter->EquipWeapon();
|
||||
EnemyCharacter->WeaponRaised = true;
|
||||
|
||||
FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
|
||||
return EBTNodeResult::Succeeded;
|
||||
}
|
||||
}
|
||||
|
||||
return EBTNodeResult::Failed;
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "BehaviorTree/Tasks/BTTask_BlackboardBase.h"
|
||||
#include "BTTask_RaiseWeapon.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class ENDLESSVENDETTA_API UBTTask_RaiseWeapon : public UBTTask_BlackboardBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UBTTask_RaiseWeapon();
|
||||
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) override;
|
||||
};
|
@ -0,0 +1,26 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "BTTask_StopAttack.h"
|
||||
#include "EndlessVendetta/AI/AI_EnemyController.h"
|
||||
#include "EndlessVendetta/AI/EnemyCharacter.h"
|
||||
|
||||
UBTTask_StopAttack::UBTTask_StopAttack()
|
||||
{
|
||||
NodeName = "Stop Attack";
|
||||
}
|
||||
|
||||
EBTNodeResult::Type UBTTask_StopAttack::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
|
||||
{
|
||||
if (const AAI_EnemyController* const AIEnemyController = Cast<AAI_EnemyController>(OwnerComp.GetAIOwner()))
|
||||
{
|
||||
if (AEnemyCharacter* const EnemyCharacter = Cast<AEnemyCharacter>(AIEnemyController->GetPawn()))
|
||||
{
|
||||
EnemyCharacter->SetFiring(false);
|
||||
|
||||
FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
|
||||
return EBTNodeResult::Succeeded;
|
||||
}
|
||||
}
|
||||
return EBTNodeResult::Failed;
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "BehaviorTree/Tasks/BTTask_BlackboardBase.h"
|
||||
#include "BTTask_StopAttack.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class ENDLESSVENDETTA_API UBTTask_StopAttack : public UBTTask_BlackboardBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UBTTask_StopAttack();
|
||||
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) override;
|
||||
};
|
Loading…
Reference in New Issue
Block a user