Added HealOverTime Status Effect for Testing

This commit is contained in:
Philip W 2023-02-23 03:50:26 +00:00
parent adba724dba
commit 37deb51b5f
4 changed files with 57 additions and 1 deletions

View File

@ -9,7 +9,7 @@
/** /**
* *
*/ */
UCLASS(Abstract) UCLASS(Abstract, Blueprintable)
class THE_TWILIGHT_ABYSS_API UStatusEffect : public UObject class THE_TWILIGHT_ABYSS_API UStatusEffect : public UObject
{ {
GENERATED_BODY() GENERATED_BODY()

View File

@ -0,0 +1,30 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "HealOverTime.h"
#include "the_twilight_abyss/PlayerTemp/TempCharacter.h"
void UHealOverTime::Heal(AActor* Character, const float Amount) const
{
if (ATempCharacter* CastedCharacter = Cast<ATempCharacter>(Character); CastedCharacter->Health < 100)
{
CastedCharacter->Health += Amount;
}
else
{
CastedCharacter->Health = 100;
}
}
void UHealOverTime::Invoke(AActor* Character)
{
Super::Invoke(Character);
GetWorld()->GetTimerManager().SetTimer(HealTimerHandle, [Character, this] { Heal(Character, 1); }, 1, true, 0);
}
void UHealOverTime::OnExpiry(AActor* Character)
{
Super::OnExpiry(Character);
HealTimerHandle.Invalidate();
}

View File

@ -0,0 +1,25 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "../StatusEffect.h"
#include "HealOverTime.generated.h"
/**
*
*/
UCLASS()
class THE_TWILIGHT_ABYSS_API UHealOverTime : public UStatusEffect
{
GENERATED_BODY()
protected:
UFUNCTION()
void Heal(AActor* Character, float Amount) const;
public:
FTimerHandle HealTimerHandle;
virtual void Invoke(AActor* Character) override;
virtual void OnExpiry(AActor* Character) override;
};

View File

@ -61,6 +61,7 @@ void UStatusSystem::AddStatusEffect(UStatusEffect* StatusEffect, const float Dur
UImage* StatusIconImage = Cast<UImage>(NewStatusEffect.StatusIcon->GetWidgetFromName(TEXT("StatusIconImage"))); UImage* StatusIconImage = Cast<UImage>(NewStatusEffect.StatusIcon->GetWidgetFromName(TEXT("StatusIconImage")));
StatusIconImage->SetBrushFromTexture(StatusEffect->Icon); StatusIconImage->SetBrushFromTexture(StatusEffect->Icon);
StatusIconsBox->AddChild(NewStatusEffect.StatusIcon); StatusIconsBox->AddChild(NewStatusEffect.StatusIcon);
NewStatusEffect.StatusEffect->Invoke(GetOwner());
ActiveStatusEffects.Add(NewStatusEffect); ActiveStatusEffects.Add(NewStatusEffect);
} }