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