Compare commits

...

2 Commits

Author SHA1 Message Date
baz 6a30ddae07 Refine Ranged Enemy functionality and hide on low health 2024-02-27 23:18:07 +00:00
baz cc21d38a0f Add Weapon Cooldown Decorator 2024-02-27 21:44:07 +00:00
17 changed files with 172 additions and 17 deletions

BIN
Content/Enemy/BT_Attacking_State.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Enemy/BT_Find_Cover.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Enemy/EQS/AttackTarget.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Enemy/EQS/EQS_FindIdealRange.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Enemy/Worker/AIC_Worker.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Enemy/Worker/BB_Worker.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Enemy/Worker/BT_Worker.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Enemy/Worker/C_Worker.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,27 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "../Decorators/BTDCanSeeTarget.h"
#include "AIController.h"
#include "BehaviorTree/BlackboardComponent.h"
bool UBTDCanSeeTarget::CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const
{
FHitResult HitResult;
FVector Start = OwnerComp.GetAIOwner()->GetPawn()->GetActorLocation();
UBlackboardComponent* BlackboardComponent = OwnerComp.GetBlackboardComponent();
AActor* TargetActor = Cast<AActor>(BlackboardComponent->GetValueAsObject(TargetActorKey.SelectedKeyName));
FVector End = TargetActor->GetActorLocation();
GetWorld()->LineTraceSingleByChannel(HitResult, Start, End, ECC_Pawn);
if (HitResult.GetActor())
{
return true;
}
return false;
}

View File

@ -0,0 +1,24 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "BehaviorTree/BTDecorator.h"
#include "BTDCanSeeTarget.generated.h"
/**
*
*/
UCLASS()
class NAKATOMI_API UBTDCanSeeTarget : public UBTDecorator
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, Category = "Options",
Meta = (AllowPrivateAccess = "true", DisplayName = "Target Actor Key"))
FBlackboardKeySelector TargetActorKey;
protected:
virtual bool CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const override;
};

View File

@ -0,0 +1,14 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "../Decorators/BTDIsHealthBelowThreshold.h"
#include "BehaviorTree/BlackboardComponent.h"
bool UBTDIsHealthBelowThreshold::CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const
{
UBlackboardComponent* BlackboardComponent = OwnerComp.GetBlackboardComponent();
float currentHealth = BlackboardComponent->GetValueAsFloat(CurrentHealthKey.SelectedKeyName);
return currentHealth <= HealthThreshold ? true : false;
}

View File

@ -0,0 +1,29 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "BehaviorTree/BTDecorator.h"
#include "BTDIsHealthBelowThreshold.generated.h"
/**
*
*/
UCLASS()
class NAKATOMI_API UBTDIsHealthBelowThreshold : public UBTDecorator
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, Category = "Options",
Meta = (AllowPrivateAccess = "true", DisplayName = "Current Health Key"))
FBlackboardKeySelector CurrentHealthKey;
UPROPERTY(EditAnywhere, Category = "Options",
Meta = (AllowPrivateAccess = "true", DisplayName = "Health Threshold"))
float HealthThreshold = 25.0f;
protected:
virtual bool CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const override;
};

View File

@ -0,0 +1,23 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "../Decorators/BTDWeaponCooldown.h"
#include "AIController.h"
#include "Nakatomi/EnemyCharacter.h"
void UBTDWeaponCooldown::TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds)
{
AEnemyCharacter* EnemyCharacter = Cast<AEnemyCharacter>(OwnerComp.GetAIOwner()->GetPawn());
if (EnemyCharacter && EnemyCharacter->GetCurrentWeapon())
{
const float Cooldown = EnemyCharacter->GetCurrentWeapon()->GetWeaponProperties()->WeaponCooldown;
if (CoolDownTime != Cooldown)
{
CoolDownTime = Cooldown;
}
}
Super::TickNode(OwnerComp, NodeMemory, DeltaSeconds);
}

View File

@ -0,0 +1,19 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "BehaviorTree/Decorators/BTDecorator_Cooldown.h"
#include "BTDWeaponCooldown.generated.h"
/**
*
*/
UCLASS()
class NAKATOMI_API UBTDWeaponCooldown : public UBTDecorator_Cooldown
{
GENERATED_BODY()
protected:
virtual void TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds) override;
};

View File

@ -4,6 +4,9 @@
#include "EnemyAIController.h"
#include "EnemyHealthComponent.h"
#include "InteractableComponent.h"
#include "BehaviorTree/BehaviorTree.h"
#include "BehaviorTree/BlackboardComponent.h"
#include "BehaviorTree/BlackboardData.h"
#define COLLISION_WEAPON ECC_GameTraceChannel1
@ -54,6 +57,10 @@ void AEnemyCharacter::WeaponCooldownHandler()
void AEnemyCharacter::BeginPlay()
{
Super::BeginPlay();
AEnemyAIController* controller = Cast<AEnemyAIController>(GetController());
controller->GetBlackboardComponent()->SetValueAsFloat("CurrentHealth", GetHealthComponent()->GetCurrentHealth());
GetHealthComponent()->OnDamaged.BindUFunction(this, "OnDamaged");
}
void AEnemyCharacter::PlayOnFireAnimations()
@ -130,3 +137,12 @@ void AEnemyCharacter::ProcessHits(TArray<FHitResult> hits)
}
}
}
void AEnemyCharacter::OnDamaged()
{
Super::OnDamaged();
AEnemyAIController* controller = Cast<AEnemyAIController>(GetController());
controller->GetBlackboardComponent()->SetValueAsFloat("CurrentHealth", GetHealthComponent()->GetCurrentHealth());
}

View File

@ -55,4 +55,7 @@ private:
virtual void CalculateHits(TArray<FHitResult>* hits) override;
virtual void ProcessHits(TArray<FHitResult> hits) override;
protected:
virtual void OnDamaged() override;
};