AzureAbyss/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffect.cpp

42 lines
1.6 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "StatusEffect.h"
#include "StatusSystem.h"
#include "Kismet/GameplayStatics.h"
#include "Components/TextBlock.h"
void UStatusEffect::Invoke(AActor* Character, float TimeOfInit)
{
GetWorld()->GetTimerManager().SetTimer(ExpiryTimerHandle, [this, Character, TimeOfInit] { CheckForExpiry(TimeOfInit, Character); }, 1, true, 0);
}
void UStatusEffect::OnExpiry(AActor* Character)
{
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::OnPlayerTurn(AActor* Character)
{
return;
}
void UStatusEffect::OnEnemyTurn(AActor* Character)
{
return;
}
void UStatusEffect::CheckForExpiry(const float TimeOfExpiry, AActor* Character)
{
if (TimeOfExpiry <= UGameplayStatics::GetRealTimeSeconds(GetWorld())) OnExpiry(Character);
UStatusSystem* StatusSystem = Cast<UStatusSystem>(Character->GetComponentByClass(UStatusSystem::StaticClass()));
if (StatusSystem->GetActiveStatusEffect(this).StatusIcon == nullptr) return;
UTextBlock* StatusText = Cast<UTextBlock>(StatusSystem->GetActiveStatusEffect(this).StatusIcon->GetWidgetFromName(TEXT("DurationText")));
StatusText->SetText(FText::FromString(FString::FromInt(TimeOfExpiry - UGameplayStatics::GetRealTimeSeconds(GetWorld()))));
}