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"
|
2023-02-28 16:48:30 +00:00
|
|
|
#include "TurnBaseCombatV2.h"
|
2023-02-27 03:46:06 +00:00
|
|
|
#include "Components/TextBlock.h"
|
2023-02-25 01:25:32 +00:00
|
|
|
|
2023-02-27 03:46:06 +00:00
|
|
|
void UStatusEffect::Invoke(AActor* Character, float TimeOfInit)
|
2023-02-20 17:58:32 +00:00
|
|
|
{
|
2023-02-27 03:46:06 +00:00
|
|
|
GetWorld()->GetTimerManager().SetTimer(ExpiryTimerHandle, [this, Character, TimeOfInit] { CheckForExpiry(TimeOfInit, 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()));
|
2023-02-27 03:46:06 +00:00
|
|
|
if (StatusSystem->GetActiveStatusEffect(this).StatusIcon == nullptr) return;
|
2023-02-25 01:25:32 +00:00
|
|
|
StatusSystem->GetActiveStatusEffect(this).StatusIcon->RemoveFromParent();
|
|
|
|
StatusSystem->RemoveStatusEffect(this);
|
|
|
|
}
|
|
|
|
|
2023-02-28 16:48:30 +00:00
|
|
|
void UStatusEffect::OnPlayerTurn(AActor* Character, AActor* Enemy)
|
2023-02-27 17:32:34 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-02-28 16:48:30 +00:00
|
|
|
void UStatusEffect::OnEnemyTurn(AActor* Enemy, AActor* Character)
|
2023-02-27 17:32:34 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-02-28 16:48:30 +00:00
|
|
|
void UStatusEffect::OnStatusEffectAdd()
|
|
|
|
{
|
|
|
|
ATurnBaseCombatV2* CombatSystem = Cast<ATurnBaseCombatV2>(GetWorld()->GetGameState());
|
|
|
|
CombatSystem->OnPlayerTurn.AddUObject(this, &UStatusEffect::OnPlayerTurn);
|
|
|
|
CombatSystem->OnEnemyTurn.AddUObject(this, &UStatusEffect::OnEnemyTurn);
|
|
|
|
}
|
|
|
|
|
2023-02-25 01:25:32 +00:00
|
|
|
void UStatusEffect::CheckForExpiry(const float TimeOfExpiry, AActor* Character)
|
|
|
|
{
|
2023-02-27 17:32:34 +00:00
|
|
|
if (TimeOfExpiry <= UGameplayStatics::GetRealTimeSeconds(GetWorld())) OnExpiry(Character);
|
2023-02-27 03:46:06 +00:00
|
|
|
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()))));
|
2023-02-20 17:58:32 +00:00
|
|
|
}
|