From 0d5858f421f71cb5f672d0b1b14255c00479d1d2 Mon Sep 17 00:00:00 2001 From: baz Date: Fri, 2 Aug 2024 02:12:41 +0100 Subject: [PATCH] Make EnemyCharacters drop EXP Pickup in OnDeath --- Content/Enemy/BP_EnemyCharacter.uasset | 4 ++-- Content/Pickups/BP_EXPPickup.uasset | 3 +++ Content/Pickups/BP_GoldPickup.uasset | 3 +++ Content/Pickups/EXPPickup.uasset | 3 --- Content/Pickups/GoldPickup.uasset | 4 ++-- Source/vampires/EnemyCharacter.cpp | 14 ++++++++++++-- Source/vampires/EnemyCharacter.h | 7 ++++++- Source/vampires/VampireAIController.cpp | 2 +- 8 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 Content/Pickups/BP_EXPPickup.uasset create mode 100644 Content/Pickups/BP_GoldPickup.uasset delete mode 100644 Content/Pickups/EXPPickup.uasset diff --git a/Content/Enemy/BP_EnemyCharacter.uasset b/Content/Enemy/BP_EnemyCharacter.uasset index cf9afc4..1495d2e 100644 --- a/Content/Enemy/BP_EnemyCharacter.uasset +++ b/Content/Enemy/BP_EnemyCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:72cdbc9edd071070d4c21ddb8e7bae8b5b5d51cd89cfcc30f6f82504d23f6637 -size 29261 +oid sha256:4d30182af29e0aa00abb9c0e29b23f5886967406f647b24721a202b86f53e83f +size 29443 diff --git a/Content/Pickups/BP_EXPPickup.uasset b/Content/Pickups/BP_EXPPickup.uasset new file mode 100644 index 0000000..d555da2 --- /dev/null +++ b/Content/Pickups/BP_EXPPickup.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a1f1b706ff5282a1e927b7c4084cedf6d5e1b51d71245e6b24273451ce890873 +size 31824 diff --git a/Content/Pickups/BP_GoldPickup.uasset b/Content/Pickups/BP_GoldPickup.uasset new file mode 100644 index 0000000..9fcab23 --- /dev/null +++ b/Content/Pickups/BP_GoldPickup.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fc8656bd5416e283c254c85192a42d5019017f80626f9731168e902bd047d2b5 +size 31807 diff --git a/Content/Pickups/EXPPickup.uasset b/Content/Pickups/EXPPickup.uasset deleted file mode 100644 index 8c5e678..0000000 --- a/Content/Pickups/EXPPickup.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:9cfc5d04088c81833b0981c584a2f0fa85003b2647e8b692db6e065bdeef507f -size 24993 diff --git a/Content/Pickups/GoldPickup.uasset b/Content/Pickups/GoldPickup.uasset index eafe9a4..300cb13 100644 --- a/Content/Pickups/GoldPickup.uasset +++ b/Content/Pickups/GoldPickup.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4a006a540345b2950c79d8d7be172342a5b69277b52567ad0b652f9687229d0b -size 31790 +oid sha256:40393ab2e1f12af9b8928ccc48fd3afe6d058dd9e30b3a0626daf70388151dfb +size 2450 diff --git a/Source/vampires/EnemyCharacter.cpp b/Source/vampires/EnemyCharacter.cpp index 4a160fe..e574d7e 100644 --- a/Source/vampires/EnemyCharacter.cpp +++ b/Source/vampires/EnemyCharacter.cpp @@ -5,13 +5,13 @@ AEnemyCharacter::AEnemyCharacter(const FObjectInitializer& ObjectInitializer) { - GetHealthComponent()->OnDamaged.BindUFunction(this, "OnDamaged"); - GetHealthComponent()->OnDeath.BindUFunction(this, "OnDeath"); } void AEnemyCharacter::BeginPlay() { Super::BeginPlay(); + GetHealthComponent()->OnDamaged.BindUFunction(this, "OnDamaged"); + GetHealthComponent()->OnDeath.BindUFunction(this, "OnDeath"); } void AEnemyCharacter::Tick(float DeltaTime) @@ -30,4 +30,14 @@ void AEnemyCharacter::OnDamaged() void AEnemyCharacter::OnDeath() { + //if (IsValid(EXPPickupTemplate)) + //{ + FActorSpawnParameters actorSpawnParameters; + actorSpawnParameters.Owner = this; + actorSpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; + actorSpawnParameters.TransformScaleMethod = ESpawnActorScaleMethod::MultiplyWithRoot; + + GetWorld()->SpawnActor(EXPPickupTemplate, GetActorLocation(), FRotator::ZeroRotator, + actorSpawnParameters); + //} } diff --git a/Source/vampires/EnemyCharacter.h b/Source/vampires/EnemyCharacter.h index f46b115..a1af1e2 100644 --- a/Source/vampires/EnemyCharacter.h +++ b/Source/vampires/EnemyCharacter.h @@ -3,6 +3,7 @@ #pragma once #include "CoreMinimal.h" +#include "EXPPickup.h" #include "VampireCharacter.h" #include "BehaviorTree/BehaviorTree.h" #include "EnemyCharacter.generated.h" @@ -15,10 +16,14 @@ class VAMPIRES_API AEnemyCharacter : public AVampireCharacter { GENERATED_BODY() +public: + UPROPERTY(EditDefaultsOnly) + TSubclassOf EXPPickupTemplate = nullptr; + private: UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) - UBehaviorTree* BehaviorTree; + UBehaviorTree* BehaviorTree = nullptr; public: AEnemyCharacter(const FObjectInitializer& ObjectInitializer); diff --git a/Source/vampires/VampireAIController.cpp b/Source/vampires/VampireAIController.cpp index f105058..3358083 100644 --- a/Source/vampires/VampireAIController.cpp +++ b/Source/vampires/VampireAIController.cpp @@ -60,6 +60,7 @@ void AVampireAIController::OnDamaged(FDamageInfo info) void AVampireAIController::OnDeath(FDamageInfo info) { // TODO: Do stuff here + EnemyCharacter->OnDeath(); EnemyCharacter->DetachFromControllerPendingDestroy(); EnemyCharacter->GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision); EnemyCharacter->GetCapsuleComponent()->SetCollisionResponseToAllChannels(ECR_Ignore); @@ -71,7 +72,6 @@ void AVampireAIController::OnDeath(FDamageInfo info) characterMovementComponent->SetComponentTickEnabled(false); } GetWorldTimerManager().ClearTimer(PawnMoveToTimerHandle); - EnemyCharacter->SetLifeSpan(0.1f); }