add respawn with health regen
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user