// Fill out your copyright notice in the Description page of Project Settings. #include "StatusEffect.h" #include "StatusSystem.h" #include "Kismet/GameplayStatics.h" #include "TurnBaseCombatV2.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(Character->GetComponentByClass(UStatusSystem::StaticClass())); if (StatusSystem->GetActiveStatusEffect(this).StatusIcon == nullptr) return; StatusSystem->GetActiveStatusEffect(this).StatusIcon->RemoveFromParent(); StatusSystem->RemoveStatusEffect(this); } void UStatusEffect::OnPlayerTurn(AActor* Character, AActor* Enemy) { return; } void UStatusEffect::OnEnemyTurn(AActor* Enemy, AActor* Character) { return; } void UStatusEffect::OnStatusEffectAdd() { ATurnBaseCombatV2* CombatSystem = Cast(GetWorld()->GetGameState()); CombatSystem->OnPlayerTurn.AddUObject(this, &UStatusEffect::OnPlayerTurn); CombatSystem->OnEnemyTurn.AddUObject(this, &UStatusEffect::OnEnemyTurn); } void UStatusEffect::CheckForExpiry(const float TimeOfExpiry, AActor* Character) { if (TimeOfExpiry <= UGameplayStatics::GetRealTimeSeconds(GetWorld())) OnExpiry(Character); UStatusSystem* StatusSystem = Cast(Character->GetComponentByClass(UStatusSystem::StaticClass())); if (StatusSystem->GetActiveStatusEffect(this).StatusIcon == nullptr) return; UTextBlock* StatusText = Cast(StatusSystem->GetActiveStatusEffect(this).StatusIcon->GetWidgetFromName(TEXT("DurationText"))); StatusText->SetText(FText::FromString(FString::FromInt(TimeOfExpiry - UGameplayStatics::GetRealTimeSeconds(GetWorld())))); }