Add Enemy Attacks
This commit is contained in:
parent
f44915e5f0
commit
2c3a66cbd4
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)
BIN
Content/Enemy/BP_TestEnemy.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Pickups/EXP/BP_PickupTemplate.uasset
(Stored with Git LFS)
BIN
Content/Pickups/EXP/BP_PickupTemplate.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Pickups/Gold/BP_GoldPickup.uasset
(Stored with Git LFS)
BIN
Content/Pickups/Gold/BP_GoldPickup.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Player/BP_PlayerCharacter.uasset
(Stored with Git LFS)
BIN
Content/Player/BP_PlayerCharacter.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Weapons/FireWand/BP_FireWandWeapon.uasset
(Stored with Git LFS)
BIN
Content/Weapons/FireWand/BP_FireWandWeapon.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Weapons/MagicWand/BP_MagicWandProjectile.uasset
(Stored with Git LFS)
BIN
Content/Weapons/MagicWand/BP_MagicWandProjectile.uasset
(Stored with Git LFS)
Binary file not shown.
@ -6,17 +6,23 @@
|
|||||||
#include "EnemyDataAsset.h"
|
#include "EnemyDataAsset.h"
|
||||||
#include "EXPPickup.h"
|
#include "EXPPickup.h"
|
||||||
#include "HealthComponent.h"
|
#include "HealthComponent.h"
|
||||||
|
#include "MovieSceneTracksComponentTypes.h"
|
||||||
#include "ObjectPoolComponent.h"
|
#include "ObjectPoolComponent.h"
|
||||||
#include "ObjectPoolManager.h"
|
#include "ObjectPoolManager.h"
|
||||||
#include "PaperFlipbookComponent.h"
|
#include "PaperFlipbookComponent.h"
|
||||||
#include "VampireAIController.h"
|
#include "VampireAIController.h"
|
||||||
#include "VampireGameMode.h"
|
#include "VampireGameMode.h"
|
||||||
#include "Components/CapsuleComponent.h"
|
#include "Components/CapsuleComponent.h"
|
||||||
|
#include "Components/SphereComponent.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
|
||||||
AEnemyCharacter::AEnemyCharacter(const FObjectInitializer& ObjectInitializer)
|
AEnemyCharacter::AEnemyCharacter(const FObjectInitializer& ObjectInitializer)
|
||||||
{
|
{
|
||||||
ObjectPoolComponent = CreateDefaultSubobject<UObjectPoolComponent>(TEXT("Object Pool Component"));
|
ObjectPoolComponent = CreateDefaultSubobject<UObjectPoolComponent>(TEXT("Object Pool Component"));
|
||||||
|
|
||||||
|
DamageSphere = CreateDefaultSubobject<USphereComponent>(TEXT("Damage Sphere"));
|
||||||
|
DamageSphere->SetupAttachment(RootComponent);
|
||||||
|
DamageSphere->SetSphereRadius(50.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AEnemyCharacter::BeginPlay()
|
void AEnemyCharacter::BeginPlay()
|
||||||
@ -26,6 +32,10 @@ void AEnemyCharacter::BeginPlay()
|
|||||||
GetHealthComponent()->OnDeath.AddDynamic(this, &AEnemyCharacter::OnDeath);
|
GetHealthComponent()->OnDeath.AddDynamic(this, &AEnemyCharacter::OnDeath);
|
||||||
|
|
||||||
ObjectPoolComponent->OnRetrieve.BindUFunction(this, "ResetHealth");
|
ObjectPoolComponent->OnRetrieve.BindUFunction(this, "ResetHealth");
|
||||||
|
|
||||||
|
DamageSphere->OnComponentBeginOverlap.AddDynamic(this, &AEnemyCharacter::OnDamageBeginOverlap);
|
||||||
|
DamageSphere->OnComponentEndOverlap.AddDynamic(this, &AEnemyCharacter::OnDamageEndOverlap);
|
||||||
|
DamageSphere->MoveIgnoreActors.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AEnemyCharacter::Tick(float DeltaTime)
|
void AEnemyCharacter::Tick(float DeltaTime)
|
||||||
@ -104,7 +114,37 @@ UHealthComponent* AEnemyCharacter::GetEnemyHealthComponent_Implementation()
|
|||||||
return GetHealthComponent();
|
return GetHealthComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AEnemyCharacter::OnDamageBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||||
|
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
|
||||||
|
{
|
||||||
|
if (Cast<ACharacter>(OtherActor) == UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) && !Player.Contains(OtherActor))
|
||||||
|
{
|
||||||
|
Player.Add(OtherActor);
|
||||||
|
|
||||||
|
GetWorldTimerManager().SetTimer(DamageTimerHandle, this, &AEnemyCharacter::DamagePlayer, AttackCooldown, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AEnemyCharacter::OnDamageEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
|
||||||
|
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
|
||||||
|
{
|
||||||
|
if (Cast<ACharacter>(OtherActor) == UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) && Player.Contains(OtherActor))
|
||||||
|
{
|
||||||
|
Player.Remove(OtherActor);
|
||||||
|
|
||||||
|
GetWorldTimerManager().ClearTimer(DamageTimerHandle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AEnemyCharacter::ResetHealth()
|
void AEnemyCharacter::ResetHealth()
|
||||||
{
|
{
|
||||||
GetHealthComponent()->ResetHealth();
|
GetHealthComponent()->ResetHealth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AEnemyCharacter::DamagePlayer()
|
||||||
|
{
|
||||||
|
for (auto player : Player)
|
||||||
|
{
|
||||||
|
UGameplayStatics::ApplyDamage(player, Damage, GetController(), this, nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "Interfaces/Enemyable.h"
|
#include "Interfaces/Enemyable.h"
|
||||||
#include "EnemyCharacter.generated.h"
|
#include "EnemyCharacter.generated.h"
|
||||||
|
|
||||||
|
class USphereComponent;
|
||||||
class UObjectPoolComponent;
|
class UObjectPoolComponent;
|
||||||
class UBehaviorTree;
|
class UBehaviorTree;
|
||||||
class AEXPPickup;
|
class AEXPPickup;
|
||||||
@ -23,6 +24,15 @@ public:
|
|||||||
UPROPERTY(EditDefaultsOnly)
|
UPROPERTY(EditDefaultsOnly)
|
||||||
TSubclassOf<AEXPPickup> EXPPickupTemplate = nullptr;
|
TSubclassOf<AEXPPickup> EXPPickupTemplate = nullptr;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
|
TObjectPtr<USphereComponent> DamageSphere = nullptr;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
|
float Damage = 5.0f;;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
|
float AttackCooldown = 1.0f;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
|
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
|
||||||
UBehaviorTree* BehaviorTree = nullptr;
|
UBehaviorTree* BehaviorTree = nullptr;
|
||||||
@ -31,6 +41,10 @@ private:
|
|||||||
|
|
||||||
UPickupDataAsset* PickupTemplate = nullptr;
|
UPickupDataAsset* PickupTemplate = nullptr;
|
||||||
|
|
||||||
|
TArray<AActor*> Player;
|
||||||
|
|
||||||
|
FTimerHandle DamageTimerHandle;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AEnemyCharacter(const FObjectInitializer& ObjectInitializer);
|
AEnemyCharacter(const FObjectInitializer& ObjectInitializer);
|
||||||
|
|
||||||
@ -63,7 +77,18 @@ public:
|
|||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
virtual UHealthComponent* GetEnemyHealthComponent_Implementation() override;
|
virtual UHealthComponent* GetEnemyHealthComponent_Implementation() override;
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void OnDamageBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||||
|
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||||
|
const FHitResult& SweepResult);
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void OnDamageEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,
|
||||||
|
int32 OtherBodyIndex);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void ResetHealth();
|
void ResetHealth();
|
||||||
|
|
||||||
|
void DamagePlayer();
|
||||||
};
|
};
|
||||||
|
@ -21,10 +21,12 @@ APickup::APickup()
|
|||||||
InnerSphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Inner Sphere Component"));
|
InnerSphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Inner Sphere Component"));
|
||||||
SetRootComponent(InnerSphereComponent);
|
SetRootComponent(InnerSphereComponent);
|
||||||
InnerSphereComponent->SetSphereRadius(25.0f);
|
InnerSphereComponent->SetSphereRadius(25.0f);
|
||||||
|
InnerSphereComponent->SetCollisionProfileName(TEXT("Pickup"));
|
||||||
|
|
||||||
OuterSphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Outer Sphere Component"));
|
OuterSphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Outer Sphere Component"));
|
||||||
OuterSphereComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
|
OuterSphereComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
|
||||||
OuterSphereComponent->SetSphereRadius(250.0f);
|
OuterSphereComponent->SetSphereRadius(250.0f);
|
||||||
|
OuterSphereComponent->SetCollisionProfileName(TEXT("Pickup"));
|
||||||
|
|
||||||
StaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Static Mesh Component"));
|
StaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Static Mesh Component"));
|
||||||
StaticMeshComponent->SetRelativeRotation(FRotator(0.0f, 90.0f, 0.0f));
|
StaticMeshComponent->SetRelativeRotation(FRotator(0.0f, 90.0f, 0.0f));
|
||||||
|
@ -20,6 +20,7 @@ AProjectile::AProjectile()
|
|||||||
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component"));
|
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component"));
|
||||||
SetRootComponent(SphereComponent);
|
SetRootComponent(SphereComponent);
|
||||||
SphereComponent->SetSphereRadius(50.0f);
|
SphereComponent->SetSphereRadius(50.0f);
|
||||||
|
SphereComponent->SetCollisionProfileName(TEXT("Weapon"));
|
||||||
|
|
||||||
ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("Projectile Movement"));
|
ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("Projectile Movement"));
|
||||||
ProjectileMovement->ProjectileGravityScale = 0.0f;
|
ProjectileMovement->ProjectileGravityScale = 0.0f;
|
||||||
|
@ -11,6 +11,8 @@ AGarlicWeapon::AGarlicWeapon()
|
|||||||
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component"));
|
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component"));
|
||||||
SphereComponent->SetupAttachment(RootComponent);
|
SphereComponent->SetupAttachment(RootComponent);
|
||||||
SphereComponent->SetSphereRadius(150.0f);
|
SphereComponent->SetSphereRadius(150.0f);
|
||||||
|
SphereComponent->SetCollisionProfileName(TEXT("Weapon"));
|
||||||
|
|
||||||
Damage = 51.0f;
|
Damage = 51.0f;
|
||||||
Range = SphereComponent->GetScaledSphereRadius();
|
Range = SphereComponent->GetScaledSphereRadius();
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@ ALightningRingWeapon::ALightningRingWeapon()
|
|||||||
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component"));
|
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component"));
|
||||||
SphereComponent->SetupAttachment(RootComponent);
|
SphereComponent->SetupAttachment(RootComponent);
|
||||||
SphereComponent->SetSphereRadius(1000.0f);
|
SphereComponent->SetSphereRadius(1000.0f);
|
||||||
|
SphereComponent->SetCollisionProfileName(TEXT("Weapon"));
|
||||||
|
|
||||||
Damage = 51.0f;
|
Damage = 51.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,8 @@ APentagramWeapon::APentagramWeapon()
|
|||||||
{
|
{
|
||||||
BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("Sphere Component"));
|
BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("Sphere Component"));
|
||||||
BoxComponent->SetupAttachment(RootComponent);
|
BoxComponent->SetupAttachment(RootComponent);
|
||||||
|
BoxComponent->SetCollisionProfileName(TEXT("Weapon"));
|
||||||
|
|
||||||
WeaponCooldown = 90.0f;
|
WeaponCooldown = 90.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ AProjectileWeapon::AProjectileWeapon()
|
|||||||
{
|
{
|
||||||
BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("Box Component"));
|
BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("Box Component"));
|
||||||
BoxComponent->SetupAttachment(RootComponent);
|
BoxComponent->SetupAttachment(RootComponent);
|
||||||
|
BoxComponent->SetCollisionProfileName(TEXT("Weapon"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AProjectileWeapon::BeginPlay()
|
void AProjectileWeapon::BeginPlay()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user