From 4321696a33b7a23dbcdb23a0d5650867af3d633e Mon Sep 17 00:00:00 2001 From: Caleb Buhungiro Date: Fri, 12 Sep 2025 22:13:07 +0800 Subject: [PATCH] create GE_DeathEffect --- Config/DefaultGameplayTags.ini | 1 + .../GameplayEffects/GE_Death.uasset | 3 ++ Content/Player/CPlayerCharacter_BP.uasset | 4 +-- .../Crunch/Private/Character/CCharacter.cpp | 34 +++++++++++++++++++ .../Private/GAS/CAbilitySystemComponent.cpp | 19 +++++++++++ .../Private/GAS/UCAbilitySystemStatics.cpp | 5 +++ Source/Crunch/Public/Character/CCharacter.h | 9 +++++ .../Public/GAS/CAbilitySystemComponent.h | 6 ++++ .../Public/GAS/UCAbilitySystemStatics.h | 1 + 9 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 Content/GameplayAbilities/GameplayEffects/GE_Death.uasset diff --git a/Config/DefaultGameplayTags.ini b/Config/DefaultGameplayTags.ini index 6494412..a34860a 100644 --- a/Config/DefaultGameplayTags.ini +++ b/Config/DefaultGameplayTags.ini @@ -21,4 +21,5 @@ NetIndexFirstBitSegment=16 +GameplayTagList=(Tag="GameplayCue.cameraShake",DevComment="") +GameplayTagList=(Tag="GameplayCue.hit.crunch.punch",DevComment="") +GameplayTagList=(Tag="GameplayCue.hit.reaction",DevComment="") ++GameplayTagList=(Tag="stats.dead",DevComment="") diff --git a/Content/GameplayAbilities/GameplayEffects/GE_Death.uasset b/Content/GameplayAbilities/GameplayEffects/GE_Death.uasset new file mode 100644 index 0000000..59a4d35 --- /dev/null +++ b/Content/GameplayAbilities/GameplayEffects/GE_Death.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:28d57f6ee5352d9c9c46aa80f371dce25205a56dc35dd8062ccdaf814fe6dfaf +size 7447 diff --git a/Content/Player/CPlayerCharacter_BP.uasset b/Content/Player/CPlayerCharacter_BP.uasset index 0b47a11..403b10a 100644 --- a/Content/Player/CPlayerCharacter_BP.uasset +++ b/Content/Player/CPlayerCharacter_BP.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:976a6300bd6c67d6f81b22658526a204b6c5e411c621e87c5b4f77b80d5a464f -size 83781 +oid sha256:56ef0ee8fb933990a7c1bdac292d746c086d5df8294c0d741cd0e5f89cfef280 +size 82119 diff --git a/Source/Crunch/Private/Character/CCharacter.cpp b/Source/Crunch/Private/Character/CCharacter.cpp index f559b11..e01e4cc 100644 --- a/Source/Crunch/Private/Character/CCharacter.cpp +++ b/Source/Crunch/Private/Character/CCharacter.cpp @@ -6,6 +6,7 @@ #include "Components/WidgetComponent.h" #include "GAS/CAbilitySystemComponent.h" #include "GAS/CAttributeSet.h" +#include "GAS/UCAbilitySystemStatics.h" #include "Kismet/GameplayStatics.h" #include "Widgets/OverHeadStatsGauge.h" @@ -29,6 +30,8 @@ ACCharacter::ACCharacter() **/ OverHeadWidgetComponent = CreateDefaultSubobject("OverHead Widget Component"); OverHeadWidgetComponent->SetupAttachment(GetRootComponent()); + + BindGASChangeDelegate(); } void ACCharacter::ServerSideInit() @@ -67,6 +70,27 @@ UAbilitySystemComponent* ACCharacter::GetAbilitySystemComponent() const return CAbilitySystemComponent; } +void ACCharacter::DeadTagUpdated(FGameplayTag GameplayTag, int32 NewCount) +{ + if (NewCount != 0) + { + StartDeathSequence(); + } + else + { + ReSpawn(); + } +} + +void ACCharacter::BindGASChangeDelegate() +{ + if (CAbilitySystemComponent) + { + CAbilitySystemComponent->RegisterGameplayTagEvent(UCAbilitySystemStatics::GetDeadStatTag()) + .AddUObject(this, &ThisClass::DeadTagUpdated); + } +} + void ACCharacter::ConfigureOverHeadStatusWidget() { if (!OverHeadWidgetComponent) return; @@ -100,3 +124,13 @@ void ACCharacter::UpdateHeadStatGaugeVisibility() OverHeadWidgetComponent->SetHiddenInGame(DistSquared > HeadStatGaugeVisibilityRangeSquared); } } + +void ACCharacter::StartDeathSequence() +{ + UE_LOG(LogTemp, Warning, TEXT("----------------------------DEAD")); +} + +void ACCharacter::ReSpawn() +{ + UE_LOG(LogTemp, Warning, TEXT("----------------------------Respawn")); +} diff --git a/Source/Crunch/Private/GAS/CAbilitySystemComponent.cpp b/Source/Crunch/Private/GAS/CAbilitySystemComponent.cpp index 44baebd..978aff7 100644 --- a/Source/Crunch/Private/GAS/CAbilitySystemComponent.cpp +++ b/Source/Crunch/Private/GAS/CAbilitySystemComponent.cpp @@ -3,6 +3,15 @@ #include "GAS/CAbilitySystemComponent.h" +#include "GAS/CAttributeSet.h" + + + +UCAbilitySystemComponent::UCAbilitySystemComponent() +{ + GetGameplayAttributeValueChangeDelegate(UCAttributeSet::GetHealthAttribute()) + .AddUObject(this, &UCAbilitySystemComponent::HealthUpdated); +} void UCAbilitySystemComponent::ApplyInitialEffects() { @@ -43,3 +52,13 @@ void UCAbilitySystemComponent::GiveInitialAbilities() )); } } + +void UCAbilitySystemComponent::HealthUpdated(const FOnAttributeChangeData& ChangeData) +{ + if (!GetOwner() && !GetOwner()->HasAuthority()) return; + if (ChangeData.NewValue <= 0 && DeathEffectClass) + { + const auto GameplayEffectSpecHandle{ MakeOutgoingSpec(DeathEffectClass, 1, MakeEffectContext() )}; + ApplyGameplayEffectSpecToSelf(*GameplayEffectSpecHandle.Data.Get()); + } +} diff --git a/Source/Crunch/Private/GAS/UCAbilitySystemStatics.cpp b/Source/Crunch/Private/GAS/UCAbilitySystemStatics.cpp index 7a0f9bf..3445470 100644 --- a/Source/Crunch/Private/GAS/UCAbilitySystemStatics.cpp +++ b/Source/Crunch/Private/GAS/UCAbilitySystemStatics.cpp @@ -7,3 +7,8 @@ FGameplayTag UCAbilitySystemStatics::GetBasicAttackAbilityTag() { return FGameplayTag::RequestGameplayTag("ability.basicattack"); } + +FGameplayTag UCAbilitySystemStatics::GetDeadStatTag() +{ + return FGameplayTag::RequestGameplayTag("stats.dead"); +} diff --git a/Source/Crunch/Public/Character/CCharacter.h b/Source/Crunch/Public/Character/CCharacter.h index ec76353..bae3764 100644 --- a/Source/Crunch/Public/Character/CCharacter.h +++ b/Source/Crunch/Public/Character/CCharacter.h @@ -4,6 +4,7 @@ #include "CoreMinimal.h" #include "AbilitySystemInterface.h" +#include "GameplayTagContainer.h" #include "GameFramework/Character.h" #include "CCharacter.generated.h" @@ -34,6 +35,8 @@ public: virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override; private: + void DeadTagUpdated(FGameplayTag GameplayTag, int32 NewCount); + void BindGASChangeDelegate(); UPROPERTY(EditDefaultsOnly, Category="Gameplay Ability") TObjectPtr CAbilitySystemComponent; UPROPERTY() @@ -54,4 +57,10 @@ private: FTimerHandle HeadStatGaugeVisibilityUpdateTimerHandle; void UpdateHeadStatGaugeVisibility(); + + /********************************************************************************************/ + /* Death & Respawning */ + /********************************************************************************************/ + void StartDeathSequence(); + void ReSpawn(); }; diff --git a/Source/Crunch/Public/GAS/CAbilitySystemComponent.h b/Source/Crunch/Public/GAS/CAbilitySystemComponent.h index a21ce6a..8cc6451 100644 --- a/Source/Crunch/Public/GAS/CAbilitySystemComponent.h +++ b/Source/Crunch/Public/GAS/CAbilitySystemComponent.h @@ -4,6 +4,7 @@ #include "CoreMinimal.h" #include "AbilitySystemComponent.h" +#include "GameplayEffectTypes.h" #include "CAbilitySystemComponent.generated.h" @@ -15,13 +16,18 @@ class CRUNCH_API UCAbilitySystemComponent : public UAbilitySystemComponent GENERATED_BODY() public: + UCAbilitySystemComponent(); void ApplyInitialEffects(); void GiveInitialAbilities(); + void HealthUpdated(const FOnAttributeChangeData& ChangeData); private: UPROPERTY(EditDefaultsOnly, Category="Gameplay Effects") TArray> InitialEffects; + UPROPERTY(EditDefaultsOnly, Category="Gameplay Effects") + TSubclassOf DeathEffectClass; + UPROPERTY(EditDefaultsOnly, Category="Gameplay Ability") TMap> Abilities; diff --git a/Source/Crunch/Public/GAS/UCAbilitySystemStatics.h b/Source/Crunch/Public/GAS/UCAbilitySystemStatics.h index 40175f4..294dc38 100644 --- a/Source/Crunch/Public/GAS/UCAbilitySystemStatics.h +++ b/Source/Crunch/Public/GAS/UCAbilitySystemStatics.h @@ -11,6 +11,7 @@ class UCAbilitySystemStatics: public UObject GENERATED_BODY() public: static FGameplayTag GetBasicAttackAbilityTag(); + static FGameplayTag GetDeadStatTag(); };