Bugfix StatusEffects Not Being Added to Player

This commit is contained in:
Philip W 2023-02-25 00:20:49 +00:00
parent 88323e4ea6
commit 939d1e8b92
3 changed files with 10 additions and 12 deletions

Binary file not shown.

View File

@ -26,7 +26,7 @@ void UEatableItems::Use(ATempCharacter* Character)
UE_LOG(LogTemp, Display, TEXT("Healed"));
Character->Inventory->RemoveItem(this);*/
UStatusSystem* StatusSystem = Cast<UStatusSystem>(Character);
UStatusSystem* StatusSystem = Character->FindComponentByClass<UStatusSystem>();
StatusSystem->AddStatusEffect(NewObject<UStatusEffect>(this, HealOverTimeStatusEffect));
}
else if (Character->Health >= 100)

View File

@ -14,14 +14,10 @@ UStatusSystem::UStatusSystem()
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
if (HUDStatusIndicatorsWidget != nullptr)
{
static ConstructorHelpers::FClassFinder<UUserWidget> HUDStatusIndicatorsWidgetClassFinder(TEXT("/Game/Blueprints/Status_UI/StatusIndicator"));
HUDStatusIndicatorsWidget = HUDStatusIndicatorsWidgetClassFinder.Class;
static ConstructorHelpers::FClassFinder<UUserWidget> HUDStatusIconWidgetClassFinder(TEXT("/Game/Blueprints/Status_UI/StatusIcon"));
HUDStatusIconWidget = HUDStatusIconWidgetClassFinder.Class;
}
static ConstructorHelpers::FClassFinder<UUserWidget> HUDStatusIndicatorsWidgetClassFinder(TEXT("/Game/Blueprints/Status_UI/StatusIndicator"));
HUDStatusIndicatorsWidget = HUDStatusIndicatorsWidgetClassFinder.Class;
static ConstructorHelpers::FClassFinder<UUserWidget> HUDStatusIconWidgetClassFinder(TEXT("/Game/Blueprints/Status_UI/StatusIcon"));
HUDStatusIconWidget = HUDStatusIconWidgetClassFinder.Class;
}
@ -43,17 +39,19 @@ void UStatusSystem::TickComponent(float DeltaTime, ELevelTick TickType, FActorCo
for (FActiveStatusEffect ActiveStatusEffect : ActiveStatusEffects)
{
UE_LOG(LogTemp, Warning, TEXT("TimeTillExpiry: %f"), UGameplayStatics::GetRealTimeSeconds(GetWorld()) - ActiveStatusEffect.TimeTillExpiry);
if (ActiveStatusEffect.TimeTillExpiry >= UGameplayStatics::GetRealTimeSeconds(GetWorld()))
{
ActiveStatusEffect.StatusEffect->OnExpiry(GetOwner());
ActiveStatusEffects.Remove(ActiveStatusEffect);
ActiveStatusEffect.StatusIcon->RemoveFromParent();
}
}
}
void UStatusSystem::AddStatusEffect(UStatusEffect* StatusEffect, const float DurationMultiplier)
{
FActiveStatusEffect NewStatusEffect{};
FActiveStatusEffect NewStatusEffect;
NewStatusEffect.StatusEffect = StatusEffect;
NewStatusEffect.TimeInitiated = UGameplayStatics::GetRealTimeSeconds(GetWorld());
NewStatusEffect.TimeTillExpiry = UGameplayStatics::GetRealTimeSeconds(GetWorld()) + StatusEffect->BaseDuration * DurationMultiplier;