Updated EatableItems to Add Status Effects

This commit is contained in:
Philip W 2023-02-23 17:48:20 +00:00
parent 37deb51b5f
commit 88323e4ea6
5 changed files with 17 additions and 7 deletions

BIN
Content/Blueprints/StatusEffects/BP_HealOverTime.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

View File

@ -5,11 +5,13 @@
#include "the_twilight_abyss/BaseItems/InventoryComponent.h"
#include "the_twilight_abyss/PlayerTemp/TempCharacter.h"
#include "the_twilight_abyss/TurnBasedCombatV2/StatusSystem.h"
UEatableItems::UEatableItems()
{
static ConstructorHelpers::FClassFinder<UStatusEffect> StatusEffectClassFinder(TEXT("/Game/Blueprints/StatusEffects/BP_HealOverTime"));
HealOverTimeStatusEffect = StatusEffectClassFinder.Class;
}
void UEatableItems::Use(ATempCharacter* Character)
@ -20,9 +22,12 @@ void UEatableItems::Use(ATempCharacter* Character)
{
if (Character->Health < 100)
{
Character->Health += 10;
/*Character->Health += 10;
UE_LOG(LogTemp, Display, TEXT("Healed"));
Character->Inventory->RemoveItem(this);
Character->Inventory->RemoveItem(this);*/
UStatusSystem* StatusSystem = Cast<UStatusSystem>(Character);
StatusSystem->AddStatusEffect(NewObject<UStatusEffect>(this, HealOverTimeStatusEffect));
}
else if (Character->Health >= 100)
{

View File

@ -5,6 +5,7 @@
#include "CoreMinimal.h"
#include "BaseItem.h"
#include "the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.h"
#include "the_twilight_abyss/TurnBasedCombatV2/StatusEffect.h"
#include "EatableItems.generated.h"
/**
@ -20,7 +21,8 @@ class THE_TWILIGHT_ABYSS_API UEatableItems : public UBaseItem
protected:
virtual void Use(class ATempCharacter* Character) override;
UPROPERTY()
TSubclassOf<UStatusEffect> HealOverTimeStatusEffect;
private:

View File

@ -53,7 +53,7 @@ void UStatusSystem::TickComponent(float DeltaTime, ELevelTick TickType, FActorCo
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;