Make Enemys Pooled
This commit is contained in:
parent
741a41ddfa
commit
58d4a57226
BIN
Content/Enemy/BP_EnemyCharacter.uasset
(Stored with Git LFS)
BIN
Content/Enemy/BP_EnemyCharacter.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Enemy/BP_TestEnemy.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Enemy/BP_TestEnemy.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/Enemy/DA_Enemy.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Enemy/DA_Enemy.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/Gamemode/BP_DefaultGamemode.uasset
(Stored with Git LFS)
BIN
Content/Gamemode/BP_DefaultGamemode.uasset
(Stored with Git LFS)
Binary file not shown.
@ -3,11 +3,15 @@
|
|||||||
|
|
||||||
#include "EnemyCharacter.h"
|
#include "EnemyCharacter.h"
|
||||||
|
|
||||||
|
#include "EnemyDataAsset.h"
|
||||||
#include "EXPPickup.h"
|
#include "EXPPickup.h"
|
||||||
#include "HealthComponent.h"
|
#include "HealthComponent.h"
|
||||||
#include "ObjectPoolComponent.h"
|
#include "ObjectPoolComponent.h"
|
||||||
#include "ObjectPoolManager.h"
|
#include "ObjectPoolManager.h"
|
||||||
|
#include "PaperFlipbookComponent.h"
|
||||||
|
#include "VampireAIController.h"
|
||||||
#include "VampireGameMode.h"
|
#include "VampireGameMode.h"
|
||||||
|
#include "Components/CapsuleComponent.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
|
||||||
AEnemyCharacter::AEnemyCharacter(const FObjectInitializer& ObjectInitializer)
|
AEnemyCharacter::AEnemyCharacter(const FObjectInitializer& ObjectInitializer)
|
||||||
@ -49,6 +53,49 @@ void AEnemyCharacter::OnDeath(FDamageInfo damageInfo)
|
|||||||
actorSpawnParameters);
|
actorSpawnParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AEnemyCharacter::LoadDataFromDataAsset_Implementation(UEnemyDataAsset* enemyDataAsset)
|
||||||
|
{
|
||||||
|
if (enemyDataAsset != nullptr)
|
||||||
|
{
|
||||||
|
// TODO: Load more data
|
||||||
|
PaperFlipbookComponent->SetFlipbook(enemyDataAsset->PaperFlipbook);
|
||||||
|
|
||||||
|
BehaviorTree = enemyDataAsset->BehaviorTree;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AEnemyCharacter::ResetData_Implementation()
|
||||||
|
{
|
||||||
|
// TODO: Reset more data
|
||||||
|
PaperFlipbookComponent->SetFlipbook(nullptr);
|
||||||
|
|
||||||
|
BehaviorTree = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
float AEnemyCharacter::GetCapsuleRadius_Implementation()
|
||||||
|
{
|
||||||
|
return GetCapsuleComponent() ? GetCapsuleComponent()->GetScaledCapsuleRadius() : -1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AEnemyCharacter::SpawnController_Implementation()
|
||||||
|
{
|
||||||
|
if (!Controller)
|
||||||
|
{
|
||||||
|
SpawnDefaultController();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BehaviorTree != nullptr)
|
||||||
|
{
|
||||||
|
AVampireAIController* controller = Cast<AVampireAIController>(Controller);
|
||||||
|
controller->RunBehaviorTree(BehaviorTree);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UHealthComponent* AEnemyCharacter::GetEnemyHealthComponent_Implementation()
|
||||||
|
{
|
||||||
|
return GetHealthComponent();
|
||||||
|
}
|
||||||
|
|
||||||
void AEnemyCharacter::ResetHealth()
|
void AEnemyCharacter::ResetHealth()
|
||||||
{
|
{
|
||||||
GetHealthComponent()->ResetHealth();
|
GetHealthComponent()->ResetHealth();
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "HealthComponent.h"
|
|
||||||
#include "VampireCharacter.h"
|
#include "VampireCharacter.h"
|
||||||
|
#include "Interfaces/Enemyable.h"
|
||||||
#include "EnemyCharacter.generated.h"
|
#include "EnemyCharacter.generated.h"
|
||||||
|
|
||||||
class UObjectPoolComponent;
|
class UObjectPoolComponent;
|
||||||
@ -14,7 +14,7 @@ class AEXPPickup;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class VAMPIRES_API AEnemyCharacter : public AVampireCharacter
|
class VAMPIRES_API AEnemyCharacter : public AVampireCharacter, public IEnemyable
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
@ -45,6 +45,21 @@ public:
|
|||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
virtual void OnDeath(FDamageInfo damageInfo);
|
virtual void OnDeath(FDamageInfo damageInfo);
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
virtual void LoadDataFromDataAsset_Implementation(UEnemyDataAsset* enemyDataAsset) override;
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
virtual void ResetData_Implementation() override;
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
virtual float GetCapsuleRadius_Implementation() override;
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
virtual void SpawnController_Implementation() override;
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
virtual UHealthComponent* GetEnemyHealthComponent_Implementation() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void ResetHealth();
|
void ResetHealth();
|
||||||
|
4
Source/vampires/EnemyDataAsset.cpp
Normal file
4
Source/vampires/EnemyDataAsset.cpp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "EnemyDataAsset.h"
|
26
Source/vampires/EnemyDataAsset.h
Normal file
26
Source/vampires/EnemyDataAsset.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "Engine/DataAsset.h"
|
||||||
|
#include "EnemyDataAsset.generated.h"
|
||||||
|
|
||||||
|
class UPaperFlipbook;
|
||||||
|
class UBehaviorTree;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class VAMPIRES_API UEnemyDataAsset : public UDataAsset
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||||
|
UPaperFlipbook* PaperFlipbook;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
|
||||||
|
UBehaviorTree* BehaviorTree = nullptr;
|
||||||
|
};
|
7
Source/vampires/Interfaces/Enemyable.cpp
Normal file
7
Source/vampires/Interfaces/Enemyable.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "Enemyable.h"
|
||||||
|
|
||||||
|
|
||||||
|
// Add default functionality here for any IEnemyable functions that are not pure virtual.
|
42
Source/vampires/Interfaces/Enemyable.h
Normal file
42
Source/vampires/Interfaces/Enemyable.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "UObject/Interface.h"
|
||||||
|
#include "Enemyable.generated.h"
|
||||||
|
|
||||||
|
class UHealthComponent;
|
||||||
|
class UEnemyDataAsset;
|
||||||
|
|
||||||
|
// This class does not need to be modified.
|
||||||
|
UINTERFACE()
|
||||||
|
class UEnemyable : public UInterface
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class VAMPIRES_API IEnemyable
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
|
||||||
|
public:
|
||||||
|
UFUNCTION(BlueprintNativeEvent)
|
||||||
|
void LoadDataFromDataAsset(UEnemyDataAsset* projectileDataAsset);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintNativeEvent)
|
||||||
|
void ResetData();
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintNativeEvent)
|
||||||
|
float GetCapsuleRadius();
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintNativeEvent)
|
||||||
|
void SpawnController();
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintNativeEvent)
|
||||||
|
UHealthComponent* GetEnemyHealthComponent();
|
||||||
|
};
|
@ -4,6 +4,7 @@
|
|||||||
#include "Projectile.h"
|
#include "Projectile.h"
|
||||||
|
|
||||||
#include "EnemyCharacter.h"
|
#include "EnemyCharacter.h"
|
||||||
|
#include "HealthComponent.h"
|
||||||
#include "ObjectPoolManager.h"
|
#include "ObjectPoolManager.h"
|
||||||
#include "ProjectileDataAsset.h"
|
#include "ProjectileDataAsset.h"
|
||||||
#include "Components/SphereComponent.h"
|
#include "Components/SphereComponent.h"
|
||||||
|
@ -78,24 +78,26 @@ void AVampireGameMode::SpawnEnemy()
|
|||||||
FActorSpawnParameters SpawnParameters;
|
FActorSpawnParameters SpawnParameters;
|
||||||
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||||
|
|
||||||
if (AActor* object = GetEnemyObjectPoolManager_Implementation()->GetObject())
|
if (AActor* enemy = GetEnemyObjectPoolManager_Implementation()->GetObject())
|
||||||
{
|
{
|
||||||
AEnemyCharacter* Actor = Cast<AEnemyCharacter>(object);
|
if (UKismetSystemLibrary::DoesImplementInterface(enemy, UEnemyable::StaticClass()) && EnemyDataAssets.Num() > 0)
|
||||||
Actor->SetActorTransform(Transform);
|
|
||||||
float CapsuleRadius = Actor->GetCapsuleComponent()->GetScaledCapsuleRadius();
|
|
||||||
FVector Direction = SpawnLocation - PlayerCharacter->GetActorLocation();
|
|
||||||
Direction.Normalize();
|
|
||||||
Direction *= CapsuleRadius;
|
|
||||||
Actor->SetActorLocation(SpawnLocation + Direction);
|
|
||||||
|
|
||||||
if (!Actor->Controller)
|
|
||||||
{
|
{
|
||||||
Actor->SpawnDefaultController();
|
IEnemyable::Execute_LoadDataFromDataAsset(enemy, EnemyDataAssets[FMath::RandRange(0, EnemyDataAssets.Num() - 1)]);
|
||||||
}
|
|
||||||
|
|
||||||
if (!Actor->GetHealthComponent()->OnDeath.IsAlreadyBound(this, &AVampireGameMode::HandleOnEnemyDeath))
|
enemy->SetActorTransform(Transform);
|
||||||
{
|
float CapsuleRadius = IEnemyable::Execute_GetCapsuleRadius(enemy);
|
||||||
Actor->GetHealthComponent()->OnDeath.AddDynamic(this, &AVampireGameMode::HandleOnEnemyDeath);
|
FVector Direction = SpawnLocation - PlayerCharacter->GetActorLocation();
|
||||||
|
Direction.Normalize();
|
||||||
|
Direction *= CapsuleRadius;
|
||||||
|
enemy->SetActorLocation(SpawnLocation + Direction);
|
||||||
|
|
||||||
|
IEnemyable::Execute_SpawnController(enemy);
|
||||||
|
|
||||||
|
UHealthComponent* healthComponent = IEnemyable::Execute_GetEnemyHealthComponent(enemy);
|
||||||
|
if (!healthComponent->OnDeath.IsAlreadyBound(this, &AVampireGameMode::HandleOnEnemyDeath))
|
||||||
|
{
|
||||||
|
healthComponent->OnDeath.AddDynamic(this, &AVampireGameMode::HandleOnEnemyDeath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "Interfaces/Pools.h"
|
#include "Interfaces/Pools.h"
|
||||||
#include "VampireGameMode.generated.h"
|
#include "VampireGameMode.generated.h"
|
||||||
|
|
||||||
|
class UEnemyDataAsset;
|
||||||
class AProjectile;
|
class AProjectile;
|
||||||
class AObjectPoolManager;
|
class AObjectPoolManager;
|
||||||
class AVampirePlayerController;
|
class AVampirePlayerController;
|
||||||
@ -30,6 +31,9 @@ public:
|
|||||||
|
|
||||||
FOnEnemyDeathCountIncrementDelegate OnEnemyDeathCountIncrementDelegate;
|
FOnEnemyDeathCountIncrementDelegate OnEnemyDeathCountIncrementDelegate;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
|
TArray<TObjectPtr<UEnemyDataAsset>> EnemyDataAssets;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TObjectPtr<APlayerCharacter> PlayerCharacter;
|
TObjectPtr<APlayerCharacter> PlayerCharacter;
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "GarlicWeapon.h"
|
#include "GarlicWeapon.h"
|
||||||
#include "Components/SphereComponent.h"
|
#include "Components/SphereComponent.h"
|
||||||
#include "vampires/EnemyCharacter.h"
|
#include "vampires/EnemyCharacter.h"
|
||||||
|
#include "vampires/HealthComponent.h"
|
||||||
|
|
||||||
AGarlicWeapon::AGarlicWeapon()
|
AGarlicWeapon::AGarlicWeapon()
|
||||||
{
|
{
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "LightningRingWeapon.h"
|
#include "LightningRingWeapon.h"
|
||||||
#include "Components/SphereComponent.h"
|
#include "Components/SphereComponent.h"
|
||||||
#include "vampires/EnemyCharacter.h"
|
#include "vampires/EnemyCharacter.h"
|
||||||
|
#include "vampires/HealthComponent.h"
|
||||||
|
|
||||||
ALightningRingWeapon::ALightningRingWeapon()
|
ALightningRingWeapon::ALightningRingWeapon()
|
||||||
{
|
{
|
||||||
|
2
vampires.sln.DotSettings.user
Normal file
2
vampires.sln.DotSettings.user
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=54EDB041_002DBA9B_002D35E0_002D8F53_002D9AB64E706FB2_002Fdl_003ASource_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FProgram_0020Files_003FEpic_0020Games_003FUE_005F5_002E4_003FEngine_003FSource_002Fd_003ARuntime_002Fd_003AAIModule_002Fd_003APrivate_002Ff_003AAIController_002Ecpp/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
Loading…
x
Reference in New Issue
Block a user