AzureAbyss/Source/the_twilight_abyss/BaseItems/Items/EatableItems.cpp
PHILIP White 14f4ff4d35 Bugfix Focus Issues in Inventory & Able to Open Inventory in Shop
Able to consistently open & close the inventory without losing focus on root widget
2023-05-21 15:19:18 +01:00

94 lines
2.6 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "EatableItems.h"
#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> StrengthBuffClassFinder(TEXT("/Game/Blueprints/StatusEffects/BP_StrengthBuff"));
StrengthBuffStatusEffect = StrengthBuffClassFinder.Class;
}
void UEatableItems::Use(ATempCharacter* Character)
{
if (Character)
{
if (isHealingItem)
{
if (Character->Health < 100)
{
Character->Health = FMath::Clamp(Character->Health + 20, 0, 100);
Character->Inventory->RemoveItem(this);
return;
}
else if (Character->Health >= 100)
{
UE_LOG(LogTemp, Display, TEXT("Health is full"));
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Health is full"));
return;
}
}
if (isDamageBuffItem)
{
UStatusSystem* StatusSystem = Character->FindComponentByClass<UStatusSystem>();
StatusSystem->AddStatusEffect(NewObject<UStatusEffect>(Character, StrengthBuffStatusEffect));
UE_LOG(LogTemp, Display, TEXT("Damage Buffed"));
Character->Inventory->RemoveItem(this);
return;
}
if (isProbertiumType)
{
TurnBaseCombat = GetWorld()->GetGameState<ATurnBaseCombatV2>();
if (TurnBaseCombat->ProbertiumResource < 20)
{
UE_LOG(LogTemp, Warning, TEXT("Probertium eaten"));
TurnBaseCombat->ProbertiumResource = FMath::Clamp(TurnBaseCombat->ProbertiumResource + 2, 0, 20);
Character->Inventory->RemoveItem(this);
}
return;
}
if (isEisType)
{
TurnBaseCombat = GetWorld()->GetGameState<ATurnBaseCombatV2>();
if (TurnBaseCombat->EisResource < 20)
{
UE_LOG(LogTemp, Warning, TEXT("Eis eaten"));
TurnBaseCombat->EisResource = FMath::Clamp(TurnBaseCombat->EisResource + 2, 0, 20);
Character->Inventory->RemoveItem(this);
}
return;
}
if (isAzosType)
{
TurnBaseCombat = GetWorld()->GetGameState<ATurnBaseCombatV2>();
if (TurnBaseCombat->AzosResource < 20)
{
UE_LOG(LogTemp, Warning, TEXT("Azos eaten"));
TurnBaseCombat->AzosResource = FMath::Clamp(TurnBaseCombat->AzosResource + 2, 0, 20);
Character->Inventory->RemoveItem(this);
}
return;
}
if (isIroquoidType)
{
TurnBaseCombat = GetWorld()->GetGameState<ATurnBaseCombatV2>();
if (TurnBaseCombat->IroquoidResource < 20)
{
UE_LOG(LogTemp, Warning, TEXT("Iroq eaten"));
TurnBaseCombat->IroquoidResource = FMath::Clamp(TurnBaseCombat->IroquoidResource + 3, 0, 20);
Character->Inventory->RemoveItem(this);
}
}
}
}