Add reworked Worker Enemy AI #3
|
@ -160,7 +160,6 @@ void AEnemyAIController::OnPerceptionUpdated(const TArray<AActor*>& actors)
|
|||
else if (stimulus.Type == HearingID)
|
||||
{
|
||||
SensedHearing(actor, stimulus);
|
||||
stimulus.StimulusLocation;
|
||||
}
|
||||
else if (stimulus.Type == DamageID)
|
||||
{
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "EnemyCharacter.h"
|
||||
#include "EnemyAIController.h"
|
||||
#include "EnemyHealthComponent.h"
|
||||
#include "InteractableComponent.h"
|
||||
|
||||
#define COLLISION_WEAPON ECC_GameTraceChannel1
|
||||
|
@ -10,6 +11,10 @@ AEnemyCharacter::AEnemyCharacter(const FObjectInitializer& ObjectInitializer) :
|
|||
{
|
||||
RandomWeaponParameters = CreateDefaultSubobject<URandomWeaponParameters>(TEXT("Random Weapon Parameters"));
|
||||
|
||||
auto healthComponent = CreateDefaultSubobject<UEnemyHealthComponent>(TEXT("Health Component"));
|
||||
SetHealthComponent(healthComponent);
|
||||
GetHealthComponent()->OnDamaged.BindUFunction(this, "OnDamaged");
|
||||
GetHealthComponent()->OnDeath.BindUFunction(this, "OnDeath");
|
||||
GetHealthComponent()->SetMaxHealth(100.0f);
|
||||
|
||||
this->Tags.Add(FName("Enemy"));
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "EnemyHealthComponent.h"
|
||||
|
||||
#include "EnemyAIController.h"
|
||||
#include "EnemyCharacter.h"
|
||||
|
||||
void UEnemyHealthComponent::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
}
|
||||
|
||||
void UEnemyHealthComponent::TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType,
|
||||
AController* instigatedBy, AActor* damageCauser)
|
||||
{
|
||||
if (damagedActor == nullptr || IsDead || !CanDamage)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentHealth -= damage;
|
||||
|
||||
AEnemyCharacter* enemyCharacter = Cast<AEnemyCharacter>(damagedActor);
|
||||
UAISense_Damage::ReportDamageEvent(GetWorld(), damagedActor, damageCauser, 1,
|
||||
damageCauser->GetTransform().GetLocation(),
|
||||
damageCauser->GetTransform().GetLocation());
|
||||
|
||||
OnDamaged.ExecuteIfBound({damagedActor, damage, damageType, instigatedBy, damageCauser});
|
||||
|
||||
if (CurrentHealth <= 0.0f)
|
||||
{
|
||||
IsDead = true;
|
||||
OnDeath.ExecuteIfBound({damagedActor, damage, damageType, instigatedBy, damageCauser});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "EnemyHealthComponent.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class NAKATOMI_API UEnemyHealthComponent : public UHealthComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
virtual void TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType, AController* instigatedBy, AActor* damageCauser) override;
|
||||
|
||||
};
|
|
@ -39,7 +39,7 @@ public:
|
|||
FOnDamageDelegate OnDamaged;
|
||||
FOnDeathDelegate OnDeath;
|
||||
|
||||
private:
|
||||
protected:
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
float MaxHealth = 100.f;
|
||||
|
||||
|
@ -55,7 +55,7 @@ public:
|
|||
UHealthComponent();
|
||||
|
||||
UFUNCTION()
|
||||
void TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType, AController* instigatedBy,
|
||||
virtual void TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType, AController* instigatedBy,
|
||||
AActor* damageCauser);
|
||||
|
||||
UFUNCTION()
|
||||
|
|
|
@ -14,9 +14,12 @@ ANakatomiCharacter::ANakatomiCharacter(const FObjectInitializer& ObjectInitializ
|
|||
|
||||
NakatomiCMC = Cast<UNakatomiCMC>(GetCharacterMovement());
|
||||
|
||||
HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component"));
|
||||
HealthComponent->OnDamaged.BindUFunction(this, "OnDamaged");
|
||||
HealthComponent->OnDeath.BindUFunction(this, "OnDeath");
|
||||
// if (!HealthComponent)
|
||||
// {
|
||||
// HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component"));
|
||||
// HealthComponent->OnDamaged.BindUFunction(this, "OnDamaged");
|
||||
// HealthComponent->OnDeath.BindUFunction(this, "OnDeath");
|
||||
// }
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
|
|
|
@ -30,6 +30,10 @@ APlayerCharacter::APlayerCharacter(const FObjectInitializer& ObjectInitializer)
|
|||
//bUseControllerRotationYaw = true;
|
||||
//bUseControllerRotationRoll = false;
|
||||
|
||||
SetHealthComponent(CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component")));
|
||||
GetHealthComponent()->OnDamaged.BindUFunction(this, "OnDamaged");
|
||||
GetHealthComponent()->OnDeath.BindUFunction(this, "OnDeath");
|
||||
|
||||
// Setup the camera boom
|
||||
CameraSpringArmComponent = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraSpringArmComponent"));
|
||||
CameraSpringArmComponent->SetupAttachment(RootComponent);
|
||||
|
@ -398,6 +402,7 @@ void APlayerCharacter::ProcessHits(TArray<FHitResult> hits)
|
|||
{
|
||||
healthComponent->TakeDamage(Hit.GetActor(), CurrentWeapon->GetWeaponProperties()->WeaponDamage, nullptr,
|
||||
GetController(), this);
|
||||
|
||||
if (!healthComponent->GetIsDead())
|
||||
{
|
||||
OnEnemyHit.ExecuteIfBound();
|
||||
|
@ -437,6 +442,8 @@ void APlayerCharacter::ProcessHits(TArray<FHitResult> hits)
|
|||
true);
|
||||
}
|
||||
}
|
||||
|
||||
MakeNoise(1, this, Hit.Location);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -639,6 +646,8 @@ void APlayerCharacter::OnFire()
|
|||
|
||||
CurrentWeapon->PlayFireSoundAtLocation(this->GetTransform().GetLocation());
|
||||
|
||||
MakeNoise(1,this, this->GetTransform().GetLocation());
|
||||
|
||||
PlayOnFireAnimations();
|
||||
|
||||
CurrentWeapon->SetCurrentWeaponStatus(Cooldown);
|
||||
|
|
Loading…
Reference in New Issue