[박치영] Gruntling Enemy 추가 작업 중

main
PCYPC\pcy35 2023-09-07 17:53:48 +09:00
parent 33271f5876
commit 0e12d099e2
13 changed files with 152 additions and 0 deletions

View File

@ -0,0 +1,106 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "AI/GruntlingEnemy.h"
#include "Blueprint/UserWidget.h"
#include "Components/CollisionComponent.h"
#include "Components/WidgetComponent.h"
#include "Components/CombatComponent.h"
#include "DamageType/AttackDamageType.h"
#include "Kismet/GameplayStatics.h"
#include "UI/UI_HealthBar.h"
AGruntlingEnemy::AGruntlingEnemy()
{
TargetingWidgetComponent->SetRelativeLocation(FVector(0.f, 0.f, 132.f));
//Setting SocketName
AttachSocketName = TEXT("SwordHipAttachSocket");
WeaponHandSocketName = TEXT("RightWeaponSocket");
//Setting UWidgetComponent
HealthBarComponent = CreateDefaultSubobject<UWidgetComponent>(TEXT("HealthBar"));
static ConstructorHelpers::FClassFinder<UUserWidget> WidgetRef(TEXT("/Game/CombatSystem/UI/WBP_HealthBar.WBP_HealthBar_C"));
if(WidgetRef.Class)
{
HealthBarComponent->SetWidgetClass(WidgetRef.Class);
HealthBarComponent->SetWidgetSpace(EWidgetSpace::Screen);
HealthBarComponent->SetDrawSize({150.f, 10.f});
HealthBarComponent->SetupAttachment(GetMesh());
HealthBarComponent->SetRelativeLocation(FVector(0.f, 0.f, 200.f));
HealthBarComponent->SetVisibility(false);
}
//Setting WeaponMeshComponent
WeaponMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("WeaponMeshComponent"));
WeaponMeshComponent->SetRelativeLocationAndRotation(FVector(0.f, 0.f, 0.f), FRotator(0.f, 0.f, 0.f));
WeaponMeshComponent->SetupAttachment(GetMesh(), AttachSocketName);
WeaponMeshComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);
//Setting MainWeaponCollisionComponent
//Setting others is Parents
MainWeaponCollisionComponent->OnHitDelegate.BindUObject(this, &AGruntlingEnemy::OnHit);
//Setting CombatComponent
//Setting others is Parents
CombatComponent->OnCombatToggled.AddUObject(this, &AGruntlingEnemy::OnCombatToggled);
}
void AGruntlingEnemy::BeginPlay()
{
Super::BeginPlay();
MainWeaponCollisionComponent->SetCollisionMeshComponent(WeaponMeshComponent);
MainWeaponCollisionComponent->AddActorToIgnore(this);
if(APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
{
UUI_HealthBar* HealthBarRef = Cast<UUI_HealthBar>(HealthBarComponent->GetWidget());
if(HealthBarRef) //ExposeOnSpawn 대용으로 사용
{
HealthBarRef->InitializeHealthBar(this->StatsComponent, EStats::Health);
HealthBarComponent->SetWidget(HealthBarRef);
}
}
}
void AGruntlingEnemy::OnTargeted(bool bIsTargeted)
{
Super::OnTargeted(bIsTargeted);
HealthBarComponent->SetVisibility(bIsTargeted);
}
void AGruntlingEnemy::OnHit(FHitResult hitResult)
{
ICombatInterface* pActor = Cast<ICombatInterface>(hitResult.GetActor());
if (pActor)
{
if (pActor->Execute_CanReceiveDamage(hitResult.GetActor()))
UGameplayStatics::ApplyPointDamage(hitResult.GetActor(), StatsComponent->GetCurrentStatValue(EStats::Damage), this->GetActorForwardVector(), hitResult, GetController(), this, UAttackDamageType::StaticClass());
}
}
void AGruntlingEnemy::OnCombatToggled(bool IsCombatEnabled)
{
FName SocketName;
if(IsCombatEnabled)
SocketName = WeaponHandSocketName;
else
SocketName = AttachSocketName;
FAttachmentTransformRules rules(EAttachmentRule::SnapToTarget, EAttachmentRule::SnapToTarget, EAttachmentRule::SnapToTarget, true);
WeaponMeshComponent->AttachToComponent(GetMesh(), rules, SocketName);
}
void AGruntlingEnemy::PerformDeath()
{
//TODO : 죽었을 때 무기에 Collision이 남아있는 버그 있음
Super::PerformDeath();
SimulateWeaponPhysics();
}
void AGruntlingEnemy::SimulateWeaponPhysics()
{
WeaponMeshComponent->SetCollisionProfileName(TEXT("PhysicsActor"), true);
WeaponMeshComponent->SetSimulatePhysics(true);
}

View File

@ -0,0 +1,46 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "AI/MasterAI.h"
#include "GruntlingEnemy.generated.h"
/**
*
*/
UCLASS()
class D1_API AGruntlingEnemy : public AMasterAI
{
GENERATED_BODY()
public:
AGruntlingEnemy();
private:
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="UI", meta=(AllowPrivateAccess="true"))
TObjectPtr<class UWidgetComponent> HealthBarComponent;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Component", meta=(AllowPrivateAccess="true"))
TObjectPtr<class UStaticMeshComponent> WeaponMeshComponent;
protected:
virtual void BeginPlay() override;
protected:
// Inherited via ITargetingInterface
virtual void OnTargeted(bool bIsTargeted) override;
public: // Delegate
//UCollisionComponent
void OnHit(FHitResult hitResult);
//UCombatComponent
void OnCombatToggled(bool IsCombatEnabled);
public:
virtual void PerformDeath() override;
void SimulateWeaponPhysics();
private:
UPROPERTY(EditAnywhere, Blueprintable, Category="Initialization", meta=(AllowPrivateAccess="true"))
FName AttachSocketName;
UPROPERTY(EditAnywhere, Blueprintable, Category="Initialization", meta=(AllowPrivateAccess="true"))
FName WeaponHandSocketName;
};