Updated StatusSystem for One Status Effect of Each Type Can be Active

This commit is contained in:
Philip W 2023-05-11 05:13:19 +01:00
parent aa2f1fabcb
commit f4a27fa5fe

View File

@ -40,6 +40,17 @@ void UStatusSystem::TickComponent(float DeltaTime, ELevelTick TickType, FActorCo
void UStatusSystem::AddStatusEffect(UStatusEffect* StatusEffect, const float DurationMultiplier, const bool Invoke)
{
for (FActiveStatusEffect ActiveStatusEffect : ActiveStatusEffects)
{
if (ActiveStatusEffect.StatusEffect->Name == StatusEffect->Name)
{
ActiveStatusEffect.TimeTillExpiry = StatusEffect->BaseDuration * DurationMultiplier;
UTextBlock* StatusText = Cast<UTextBlock>(ActiveStatusEffect.StatusIcon->GetWidgetFromName(TEXT("DurationText")));
StatusText->SetText(FText::FromString(FString::FromInt(ActiveStatusEffect.TimeTillExpiry)));
if (Invoke) ActiveStatusEffect.StatusEffect->Invoke(GetOwner(), ActiveStatusEffect.TimeTillExpiry);
return;
}
}
FActiveStatusEffect NewStatusEffect;
NewStatusEffect.StatusEffect = StatusEffect;
NewStatusEffect.TimeInitiated = UGameplayStatics::GetRealTimeSeconds(GetWorld());