[박치영]

- DamageType System 추가
- 앞 뒤 피격에 따라 피격모션 변경
main
PCYPC\pcy35 2023-08-25 17:57:43 +09:00
parent 91779abbb7
commit 08002c3777
29 changed files with 128 additions and 32 deletions

View File

@ -110,7 +110,7 @@ void ABaseDualWeapon::OnHit_OffhandWeapon(FHitResult HitResult)
if(pActor)
{
if(pActor->Execute_CanReceiveDamage(HitResult.GetActor()))
UGameplayStatics::ApplyPointDamage(HitResult.GetActor(), GetDamage(), GetOwner()->GetActorForwardVector(), HitResult, GetInstigatorController(), this, TSubclassOf<UDamageType>(UDamageType::StaticClass()));
UGameplayStatics::ApplyPointDamage(HitResult.GetActor(), GetDamage(), GetOwner()->GetActorForwardVector(), HitResult, GetInstigatorController(), this, DamageTypeClass);
}
}
@ -120,7 +120,7 @@ void ABaseDualWeapon::OnHit_RightFoot(FHitResult HitResult)
if(pActor)
{
if(pActor->Execute_CanReceiveDamage(HitResult.GetActor()))
UGameplayStatics::ApplyPointDamage(HitResult.GetActor(), GetDamage(), GetOwner()->GetActorForwardVector(), HitResult, GetInstigatorController(), this, TSubclassOf<UDamageType>(UDamageType::StaticClass()));
UGameplayStatics::ApplyPointDamage(HitResult.GetActor(), GetDamage(), GetOwner()->GetActorForwardVector(), HitResult, GetInstigatorController(), this, DamageTypeClass);
}
}

View File

@ -5,6 +5,7 @@
#include "Components/CombatComponent.h"
#include "GameFramework/Character.h"
#include "Components/CollisionComponent.h"
#include "DamageType/AttackDamageType.h"
#include "Interface/CombatInterface.h"
#include "Definitions/CombatGameplayTags.h"
#include "Kismet/GameplayStatics.h"
@ -22,6 +23,8 @@ ABaseWeapon::ABaseWeapon()
CollisionComponent->SetCollisionObjectTypes(InputCollisionObjectTypes);
CollisionComponent->SetDrawDebugType(EDrawDebugTrace::None);
DamageTypeClass = UAttackDamageType::StaticClass();
//Stats
Damage = 20.f;
if(!FCombatGameplayTags::Get().Character_Action_Attack_LightAttack.IsValid())
@ -74,7 +77,7 @@ void ABaseWeapon::OnHit(FHitResult hitResult)
if (pActor)
{
if (pActor->Execute_CanReceiveDamage(hitResult.GetActor()))
UGameplayStatics::ApplyPointDamage(hitResult.GetActor(), GetDamage(), GetOwner()->GetActorForwardVector(), hitResult, GetInstigatorController(), this, TSubclassOf<UDamageType>(UDamageType::StaticClass()));
UGameplayStatics::ApplyPointDamage(hitResult.GetActor(), GetDamage(), GetOwner()->GetActorForwardVector(), hitResult, GetInstigatorController(), this, DamageTypeClass);
}
}

View File

@ -51,6 +51,8 @@ protected:
FName HandSocketName;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Initialization")
ECombatType CombatType;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Initialization")
TSubclassOf<UDamageType> DamageTypeClass;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Components")
TObjectPtr<class UCombatComponent> CombatComponent;

View File

@ -17,6 +17,7 @@
#include "Engine/DamageEvents.h"
#include "NiagaraFunctionLibrary.h"
#include "NiagaraComponent.h"
#include "DamageType/AttackDamageType.h"
#include "Kismet/KismetSystemLibrary.h"
#include "Kismet/KismetMathLibrary.h"
#include "Kismet/GameplayStatics.h"
@ -90,7 +91,6 @@ ACombatCharacter::ACombatCharacter()
SprintSpeed = 700.f;
ChargeAttackTime = 0.18f;
Health = 100.f;
PelvisBoneName = TEXT("pelvis");
}
@ -123,26 +123,26 @@ float ACombatCharacter::TakeDamage(float Damage, FDamageEvent const& DamageEvent
{
float fDamage = Super::TakeDamage(Damage, DamageEvent, EventInstigator, DamageCauser);
UAttackDamageType* damageTypeClass = Cast<UAttackDamageType>(DamageEvent.DamageTypeClass->GetDefaultObject());
if(!IsValid(damageTypeClass))
return false;
if (DamageEvent.IsOfType(FPointDamageEvent::ClassID))
{
const FPointDamageEvent* PointDamageEvent = static_cast<const FPointDamageEvent*>(&DamageEvent);
//스텟 관련 처리
StatsComponent->TakeDamageOnStat(Damage);
//Play Sound
UGameplayStatics::PlaySoundAtLocation(this, HitSound, PointDamageEvent->HitInfo.Location);
//Hit Effect
//UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), HitEmitter, PointDamageEvent->HitInfo.Location);
UNiagaraFunctionLibrary::SpawnSystemAtLocation(GetWorld(), HitEmitter, PointDamageEvent->HitInfo.Location);
//앞에서 맞았는지 뒤에서 맞았는지 판별
bHitFront = UKismetMathLibrary::InRange_FloatFloat(this->GetDotProductTo(EventInstigator->GetPawn()), -0.1f, 1.f);
LastHitInfo = PointDamageEvent->HitInfo;
//play sound, effect
ApplyImpactEffect(damageTypeClass->DamageType);
if (CanReceiveHitReaction())
{
StateManagerComponent->SetCurrentState(FCombatGameplayTags::Get().Character_State_Disable);
//Play Animation
PlayAnimMontage(HitMontage);
}
ApplyHitReaction(damageTypeClass->DamageType);
}
return fDamage;
}
@ -615,6 +615,33 @@ void ACombatCharacter::SprintStaminaCost()
}
}
void ACombatCharacter::ApplyHitReaction(EDamageType InDamageType)
{
switch (InDamageType)
{
case EDamageType::None:
PerformHitStun();
break;
case EDamageType::MeleeDamage:
PerformHitStun();
break;
case EDamageType::KnockdownDamage:
PerformKnockdown();
break;
default:
break;
}
}
void ACombatCharacter::ApplyImpactEffect(EDamageType InDamageType)
{
//Play Sound
UGameplayStatics::PlaySoundAtLocation(this, HitSound, LastHitInfo.Location);
//Hit Effect
UNiagaraFunctionLibrary::SpawnSystemAtLocation(GetWorld(), HitEmitter, LastHitInfo.Location);
}
void ACombatCharacter::PerformAttack(FGameplayTag attackType, int32 attackIndex)
{
ABaseWeapon* CurrentWeapon = CombatComponent->GetMainWeapon();
@ -725,6 +752,38 @@ void ACombatCharacter::PerformDeath()
}), 4.f, false); // 4초 후에 object 삭제
}
bool ACombatCharacter::PerformHitStun()
{
UAnimMontage* hitMontage = nullptr;
if(bHitFront)
hitMontage = HitStunFrontMontage;
else
hitMontage = HitStunBackMontage;
if(!IsValid(hitMontage))
return false;
StateManagerComponent->SetCurrentState(FCombatGameplayTags::Get().Character_State_Disable);
PlayAnimMontage(hitMontage);
return true;
}
bool ACombatCharacter::PerformKnockdown()
{
UAnimMontage* hitMontage = nullptr;
if(bHitFront)
hitMontage = KnockdownFrontMontage;
else
hitMontage = KnockdownBackMontage;
if(!IsValid(hitMontage))
return false;
StateManagerComponent->SetCurrentState(FCombatGameplayTags::Get().Character_State_Disable);
PlayAnimMontage(hitMontage);
return true;
}
bool ACombatCharacter::CanPerformToggleCombat()
{
bool ReturnValue = true;

View File

@ -145,14 +145,18 @@ private:
bool ResetChargeAttack();
void DisableSprint();
void SprintStaminaCost();
void ApplyHitReaction(EDamageType InDamageType);
void ApplyImpactEffect(EDamageType InDamageType);
private:
void PerformAttack(FGameplayTag attackType, int32 attackIndex);
void PerformDodge();
bool PerformAction(FGameplayTag characterState, FGameplayTag characterAction, int32 montageIndex);
void PerformDeath();
bool PerformHitStun();
bool PerformKnockdown();
protected:
protected: //Check Func
bool CanPerformToggleCombat();
bool CanPerformAttack();
bool CanPerformDodge();
@ -164,13 +168,10 @@ protected:
public:
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Components", meta=(AllowPrivateAccess="true"))
TObjectPtr<class UCombatComponent> CombatComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Components", meta=(AllowPrivateAccess="true"))
TObjectPtr<UStateManagerComponent> StateManagerComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Components", meta=(AllowPrivateAccess="true"))
TObjectPtr<UStatsComponent> StatsComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Components", meta=(AllowPrivateAccess="true"))
TObjectPtr<UTargetingComponent> TargetingComponent;
@ -179,30 +180,28 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hit", meta = (AllowPrivateAccess = "true"))
FName PelvisBoneName;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hit", meta = (AllowPrivateAccess = "true"))
TObjectPtr<UAnimMontage> HitMontage;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hit", meta = (AllowPrivateAccess = "true"))
TObjectPtr<class USoundBase> HitSound;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hit", meta = (AllowPrivateAccess = "true"))
TObjectPtr<class UNiagaraSystem> HitEmitter;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MovementSpeed", meta = (AllowPrivateAccess = "true"))
EMovementSpeedMode MovementSpeedMode;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MovementSpeed", meta = (AllowPrivateAccess = "true"))
float WalkingSpeed;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MovementSpeed", meta = (AllowPrivateAccess = "true"))
float JoggingSpeed;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MovementSpeed", meta = (AllowPrivateAccess = "true"))
float SprintSpeed;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats", meta = (AllowPrivateAccess = "true"))
float Health;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Montage", meta = (AllowPrivateAccess = "true"))
TObjectPtr<UAnimMontage> HitStunFrontMontage;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Montage", meta = (AllowPrivateAccess = "true"))
TObjectPtr<UAnimMontage> HitStunBackMontage;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Montage", meta = (AllowPrivateAccess = "true"))
TObjectPtr<UAnimMontage> KnockdownFrontMontage;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Montage", meta = (AllowPrivateAccess = "true"))
TObjectPtr<UAnimMontage> KnockdownBackMontage;
private:
FTimerHandle StaminaTimerHandle;
@ -212,5 +211,6 @@ private:
float AttackHeldTime;
bool bAttackCharged;
bool bCanMove = true;
bool bHitFront;
FHitResult LastHitInfo;
};

View File

@ -0,0 +1,5 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "AttackDamageType.h"

View File

@ -0,0 +1,20 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Definitions/GameEnums.h"
#include "GameFramework/DamageType.h"
#include "AttackDamageType.generated.h"
/**
* DamageType Class EDamageType
*/
UCLASS()
class D1_API UAttackDamageType : public UDamageType
{
GENERATED_BODY()
public:
EDamageType DamageType = EDamageType::MeleeDamage;
};

View File

@ -29,3 +29,10 @@ enum class ECollisionPart : uint8
RightFoot UMETA(DisplayName = "RightFoot"),
};
UENUM(BlueprintType)
enum class EDamageType : uint8
{
None UMETA(DisplayName = "None"),
MeleeDamage UMETA(DisplayName = "MeleeDamage"),
KnockdownDamage UMETA(DisplayName = "KnockdownDamage"),
};