157 - Healing the Character
This commit is contained in:
parent
5eec76005b
commit
babbfda3cf
|
@ -628,10 +628,10 @@ void ABlasterCharacter::HideCameraIfCharacterClose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ABlasterCharacter::OnRep_Health()
|
void ABlasterCharacter::OnRep_Health(float LastHealth)
|
||||||
{
|
{
|
||||||
UpdateHUDHealth();
|
UpdateHUDHealth();
|
||||||
if (Health > 0.f)
|
if (Health < LastHealth)
|
||||||
{
|
{
|
||||||
PlayHitReactMontage();
|
PlayHitReactMontage();
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,8 @@ public:
|
||||||
UFUNCTION(BlueprintImplementableEvent)
|
UFUNCTION(BlueprintImplementableEvent)
|
||||||
void ShowSniperScopeWidget(bool bShowScope);
|
void ShowSniperScopeWidget(bool bShowScope);
|
||||||
|
|
||||||
|
void UpdateHUDHealth();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
@ -65,7 +67,6 @@ protected:
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void ReceiveDamage(AActor* DamagedActor, float Damage, const UDamageType* DamageType, class AController* InstigatorController, AActor* DamageCauser);
|
void ReceiveDamage(AActor* DamagedActor, float Damage, const UDamageType* DamageType, class AController* InstigatorController, AActor* DamageCauser);
|
||||||
|
|
||||||
void UpdateHUDHealth();
|
|
||||||
// Poll for any relevant classes and initialize them
|
// Poll for any relevant classes and initialize them
|
||||||
void PollInit();
|
void PollInit();
|
||||||
|
|
||||||
|
@ -145,7 +146,7 @@ private:
|
||||||
float Health = 100.f;
|
float Health = 100.f;
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void OnRep_Health();
|
void OnRep_Health(float LastHealth);
|
||||||
|
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
class ABlasterPlayerController* BlasterPlayerController;
|
class ABlasterPlayerController* BlasterPlayerController;
|
||||||
|
@ -206,9 +207,11 @@ public:
|
||||||
FORCEINLINE bool ShouldRotateRootBone() const { return bRotateRootBone; }
|
FORCEINLINE bool ShouldRotateRootBone() const { return bRotateRootBone; }
|
||||||
FORCEINLINE bool IsEliminated() const { return bEliminated; }
|
FORCEINLINE bool IsEliminated() const { return bEliminated; }
|
||||||
FORCEINLINE float GetHealth() const { return Health; }
|
FORCEINLINE float GetHealth() const { return Health; }
|
||||||
|
FORCEINLINE void SetHealth(float Amount) { Health = Amount; }
|
||||||
FORCEINLINE float GetMaxHealth() const { return MaxHealth; }
|
FORCEINLINE float GetMaxHealth() const { return MaxHealth; }
|
||||||
ECombatState GetCombatState() const;
|
ECombatState GetCombatState() const;
|
||||||
FORCEINLINE UCombatComponent* GetCombat() const { return Combat; }
|
FORCEINLINE UCombatComponent* GetCombat() const { return Combat; }
|
||||||
|
FORCEINLINE UBuffComponent* GetBuff() const { return Buff; }
|
||||||
FORCEINLINE bool GetDisableGameplay() const { return bDisableGameplay; }
|
FORCEINLINE bool GetDisableGameplay() const { return bDisableGameplay; }
|
||||||
FORCEINLINE UAnimMontage* GetReloadMontage() const { return ReloadMontage; }
|
FORCEINLINE UAnimMontage* GetReloadMontage() const { return ReloadMontage; }
|
||||||
FORCEINLINE UStaticMeshComponent* GetAttachedGrenade() const { return AttachedGrenade; }
|
FORCEINLINE UStaticMeshComponent* GetAttachedGrenade() const { return AttachedGrenade; }
|
||||||
|
|
|
@ -3,12 +3,21 @@
|
||||||
|
|
||||||
#include "BuffComponent.h"
|
#include "BuffComponent.h"
|
||||||
|
|
||||||
|
#include "Blaster/Character/BlasterCharacter.h"
|
||||||
|
|
||||||
UBuffComponent::UBuffComponent()
|
UBuffComponent::UBuffComponent()
|
||||||
{
|
{
|
||||||
PrimaryComponentTick.bCanEverTick = true;
|
PrimaryComponentTick.bCanEverTick = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UBuffComponent::Heal(float HealAmount, float HealingTime)
|
||||||
|
{
|
||||||
|
bHealing = true;
|
||||||
|
HealingRate = HealAmount / HealingTime;
|
||||||
|
AmountToHeal += HealAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void UBuffComponent::BeginPlay()
|
void UBuffComponent::BeginPlay()
|
||||||
{
|
{
|
||||||
|
@ -16,10 +25,26 @@ void UBuffComponent::BeginPlay()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UBuffComponent::HealRampUp(float DeltaTime)
|
||||||
|
{
|
||||||
|
if (!bHealing || Character == nullptr || Character->IsEliminated()) return;
|
||||||
|
|
||||||
|
const float HealThisFrame = HealingRate * DeltaTime;
|
||||||
|
Character->SetHealth(FMath::Clamp(Character->GetHealth() + HealThisFrame, 0, Character->GetMaxHealth()));
|
||||||
|
Character->UpdateHUDHealth();
|
||||||
|
AmountToHeal -= HealThisFrame;
|
||||||
|
|
||||||
|
if (AmountToHeal <= 0 || Character->GetHealth() >= Character->GetMaxHealth())
|
||||||
|
{
|
||||||
|
bHealing = false;
|
||||||
|
AmountToHeal = 0.f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void UBuffComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
void UBuffComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
||||||
{
|
{
|
||||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||||
|
|
||||||
|
HealRampUp(DeltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,20 @@ public:
|
||||||
UBuffComponent();
|
UBuffComponent();
|
||||||
friend class ABlasterCharacter;
|
friend class ABlasterCharacter;
|
||||||
|
|
||||||
|
void Heal(float HealAmount, float HealingTime);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
void HealRampUp(float DeltaTime);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
class ABlasterCharacter* Character;
|
class ABlasterCharacter* Character;
|
||||||
|
|
||||||
|
bool bHealing = false;
|
||||||
|
float HealingRate = 0;
|
||||||
|
float AmountToHeal = 0.f;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "NiagaraComponent.h"
|
#include "NiagaraComponent.h"
|
||||||
#include "NiagaraFunctionLibrary.h"
|
#include "NiagaraFunctionLibrary.h"
|
||||||
#include "Blaster/Character/BlasterCharacter.h"
|
#include "Blaster/Character/BlasterCharacter.h"
|
||||||
|
#include "Blaster/Components/BuffComponent.h"
|
||||||
|
|
||||||
AHealthPickup::AHealthPickup()
|
AHealthPickup::AHealthPickup()
|
||||||
{
|
{
|
||||||
|
@ -22,7 +23,11 @@ void AHealthPickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AA
|
||||||
ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(OtherActor);
|
ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(OtherActor);
|
||||||
if (BlasterCharacter)
|
if (BlasterCharacter)
|
||||||
{
|
{
|
||||||
|
UBuffComponent* Buff = BlasterCharacter->GetBuff();
|
||||||
|
if (Buff)
|
||||||
|
{
|
||||||
|
Buff->Heal(HealAmount, HealingTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Destroy();
|
Destroy();
|
||||||
|
|
Loading…
Reference in New Issue