2023-02-20 17:58:32 +00:00
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
#include "StatusEffect.h"
|
|
|
|
|
2023-02-25 01:25:32 +00:00
|
|
|
#include "StatusSystem.h"
|
|
|
|
#include "Kismet/GameplayStatics.h"
|
|
|
|
|
|
|
|
void UStatusEffect::Invoke(AActor* Character, float TimeOfExpiry)
|
2023-02-20 17:58:32 +00:00
|
|
|
{
|
2023-02-25 01:25:32 +00:00
|
|
|
GetWorld()->GetTimerManager().SetTimer(ExpiryTimerHandle, [this, Character, TimeOfExpiry] { CheckForExpiry(TimeOfExpiry, Character); }, 1, true, 0);
|
2023-02-23 03:05:09 +00:00
|
|
|
}
|
2023-02-20 17:58:32 +00:00
|
|
|
|
2023-02-23 03:05:09 +00:00
|
|
|
void UStatusEffect::OnExpiry(AActor* Character)
|
|
|
|
{
|
2023-02-25 01:25:32 +00:00
|
|
|
GetWorld()->GetTimerManager().ClearTimer(ExpiryTimerHandle);
|
|
|
|
UStatusSystem* StatusSystem = Cast<UStatusSystem>(Character->GetComponentByClass(UStatusSystem::StaticClass()));
|
|
|
|
if (StatusSystem->GetActiveStatusEffect(this).StatusIcon == nullptr) return;
|
|
|
|
StatusSystem->GetActiveStatusEffect(this).StatusIcon->RemoveFromParent();
|
|
|
|
StatusSystem->RemoveStatusEffect(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UStatusEffect::CheckForExpiry(const float TimeOfExpiry, AActor* Character)
|
|
|
|
{
|
|
|
|
if (TimeOfExpiry <= UGameplayStatics::GetRealTimeSeconds(GetWorld()))
|
|
|
|
{
|
|
|
|
OnExpiry(Character);
|
|
|
|
}
|
2023-02-20 17:58:32 +00:00
|
|
|
}
|