add respawn with health regen

This commit is contained in:
Caleb Buhungiro
2025-09-13 11:17:31 +08:00
parent cddfd8175c
commit 16869188b9
4 changed files with 32 additions and 7 deletions

Binary file not shown.

View File

@@ -162,6 +162,14 @@ void ACCharacter::StartDeathSequence()
void ACCharacter::ReSpawn()
{
OnRespawn();
GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
GetCharacterMovement()->SetMovementMode(MOVE_Walking);
GetMesh()->GetAnimInstance()->StopAllMontages(0.f);
SetStatusGaugeEnabled(true);
if (CAbilitySystemComponent)
{
CAbilitySystemComponent->ApplyFullStatEffect();
}
}
void ACCharacter::OnDead()

View File

@@ -24,8 +24,7 @@ void UCAbilitySystemComponent::ApplyInitialEffects()
* const auto Effect{EffectClass->GetDefaultObject<UGameplayEffect>()};
* ApplyGameplayEffectToSelf(Effect, 0.f, MakeEffectContext());
**/
auto GameplayEffectSpecHandle{MakeOutgoingSpec(EffectClass, 1, MakeEffectContext())};
ApplyGameplayEffectSpecToSelf(*GameplayEffectSpecHandle.Data.Get());
AuthApplyGameplayEffect(EffectClass);
}
}
@@ -55,10 +54,23 @@ void UCAbilitySystemComponent::GiveInitialAbilities()
void UCAbilitySystemComponent::HealthUpdated(const FOnAttributeChangeData& ChangeData)
{
if (!GetOwner() && !GetOwner()->HasAuthority()) return;
// if (!GetOwner() && !GetOwner()->HasAuthority()) return;
if (ChangeData.NewValue <= 0 && DeathEffectClass)
{
const auto GameplayEffectSpecHandle{ MakeOutgoingSpec(DeathEffectClass, 1, MakeEffectContext() )};
ApplyGameplayEffectSpecToSelf(*GameplayEffectSpecHandle.Data.Get());
AuthApplyGameplayEffect(DeathEffectClass);
}
}
void UCAbilitySystemComponent::ApplyFullStatEffect()
{
if (!IsValid(FullStatEffectClass)) return;
AuthApplyGameplayEffect(FullStatEffectClass);
}
void UCAbilitySystemComponent::AuthApplyGameplayEffect(const TSubclassOf<UGameplayEffect> EffectClass, const int Level)
{
if (!GetOwner() || !GetOwner()->HasAuthority()) return;
const auto FullStatEffectSpec { MakeOutgoingSpec(EffectClass, Level, MakeEffectContext())};
ApplyGameplayEffectSpecToSelf(*FullStatEffectSpec.Data.Get());
}

View File

@@ -20,10 +20,15 @@ public:
void ApplyInitialEffects();
void GiveInitialAbilities();
void HealthUpdated(const FOnAttributeChangeData& ChangeData);
void ApplyFullStatEffect();
private:
void AuthApplyGameplayEffect(TSubclassOf<UGameplayEffect> EffectClass, int Level = 1);
UPROPERTY(EditDefaultsOnly, Category="Gameplay Effects")
TArray<TSubclassOf<UGameplayEffect>> InitialEffects;
UPROPERTY(EditDefaultsOnly, Category="Gameplay Effects")
TSubclassOf<UGameplayEffect> FullStatEffectClass;
UPROPERTY(EditDefaultsOnly, Category="Gameplay Effects")
TSubclassOf<UGameplayEffect> DeathEffectClass;