From 8a54837ad64feed35becba4924fcf1ad4f951386 Mon Sep 17 00:00:00 2001 From: Louis Hobbs Date: Fri, 3 Feb 2023 01:31:23 +0000 Subject: [PATCH] Damage `EnemyCharacter` in `CalculateHits` --- Source/Nakatomi/PlayerCharacter.cpp | 22 ++++++++++++---------- Source/Nakatomi/PlayerCharacter.h | 3 ++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index 9c59231..c9015b5 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -9,6 +9,8 @@ #include "GameFramework/CharacterMovementComponent.h" #include "InputMappingContext.h" #include "Destructable.h" +#include "EnemyCharacter.h" + #define COLLISION_WEAPON ECC_GameTraceChannel1 @@ -245,17 +247,17 @@ void APlayerCharacter::CalculateHits(TArray* hits) // Spawn field actor FTransform transform; transform.SetLocation(Result.ImpactPoint); - GetWorld()->SpawnActor(CurrentWeapon->GetFieldSystemActor(), transform, SpawnParameters); - - if (Result.GetActor()->ActorHasTag(FName("Destructable"))) + auto field = GetWorld()->SpawnActor(CurrentWeapon->GetFieldSystemActor(), transform, SpawnParameters); + fields.Add(field); + + if (Result.GetActor()) { - // TODO: Do thing - auto destructable = Cast(Result.GetActor()); - destructable->Destruct(); - } - else if (Result.GetActor()->ActorHasTag(FName("Enemy"))) - { - // TODO: Do thing + if (Result.GetActor()->ActorHasTag("Enemy")) + { + // TODO: Do thing + auto enemy = Cast(Result.GetActor()); + enemy->GetHealthComponent()->TakeDamage(Result.GetActor(),CurrentWeapon->GetWeaponProperties()->WeaponDamage, nullptr, GetController(), this); + } } } } diff --git a/Source/Nakatomi/PlayerCharacter.h b/Source/Nakatomi/PlayerCharacter.h index 16fec01..fa3d7da 100644 --- a/Source/Nakatomi/PlayerCharacter.h +++ b/Source/Nakatomi/PlayerCharacter.h @@ -9,11 +9,12 @@ #include "EnhancedInputComponent.h" #include "NakatomiCharacter.h" #include "Weapon.h" +#include "Engine/EngineTypes.h" +#include "Engine/DamageEvents.h" #include "PlayerCharacter.generated.h" class UInputAction; class UInputMappingContext; -//class UEnhancedInputComponent; /** *