51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#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()
|
|
{
|
|
Super::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);
|
|
}
|
|
|