Updated Combat System to Include Healing During Combat

This commit is contained in:
Philip W 2023-05-09 05:40:31 +01:00
parent cef7b1895b
commit 487c46d7b8
12 changed files with 101 additions and 24 deletions

Binary file not shown.

Binary file not shown.

BIN
Content/Blueprints/Items/BP_Azos.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Blueprints/Items/BP_Eis.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -3,7 +3,6 @@
#include "InventoryComponent.h"
#include "Items/BaseItem.h"
#include "the_twilight_abyss/PlayerTemp/TempCharacter.h"
// Sets default values for this component's properties
@ -91,3 +90,46 @@ void UInventoryComponent::RemoveItem(UEatableItems* Item)
OnInventoryUpdated.Broadcast();
}
int UInventoryComponent::GetItemAmount(const int& ItemID)
{
if (Items.Num() > 0)
{
for (UBaseItem* const& Item : Items)
{
if (Item->ItemID == ItemID)
{
return Item->StackCount;
}
}
}
return -1;
}
void UInventoryComponent::RemoveItemID(const int& ItemID)
{
if (Items.Num() > 0)
{
for (UBaseItem* const& Item : Items)
{
if (Item->ItemID == ItemID)
{
RemoveItem(Cast<UEatableItems>(Item));
}
}
}
}
UBaseItem* UInventoryComponent::GetItemByID(const int& ItemID)
{
if (Items.Num() > 0)
{
for (UBaseItem* const& Item : Items)
{
if (Item->ItemID == ItemID)
{
return Item;
}
}
}
return nullptr;
}

View File

@ -45,4 +45,13 @@ public:
UFUNCTION()
void RemoveItem(UEatableItems* Item);
UFUNCTION()
int GetItemAmount(const int& ItemID);
UFUNCTION()
void RemoveItemID(const int& ItemID);
UFUNCTION()
UBaseItem* GetItemByID(const int& ItemID);
};

View File

@ -22,8 +22,9 @@ void UEatableItems::Use(ATempCharacter* Character)
{
if (Character->Health < 100)
{
UStatusSystem* StatusSystem = Character->FindComponentByClass<UStatusSystem>();
StatusSystem->AddStatusEffect(NewObject<UStatusEffect>(Character, HealOverTimeStatusEffect));
// UStatusSystem* StatusSystem = Character->FindComponentByClass<UStatusSystem>();
// StatusSystem->AddStatusEffect(NewObject<UStatusEffect>(Character, HealOverTimeStatusEffect));
Character->Health += 20;
Character->Inventory->RemoveItem(this);
}
else if (Character->Health >= 100)

View File

@ -25,6 +25,6 @@ protected:
TSubclassOf<UStatusEffect> HealOverTimeStatusEffect;
private:
UPROPERTY()
ATurnBaseCombatV2* TurnBaseCombat;
};

View File

@ -48,6 +48,7 @@ void ATurnBaseCombatV2::StartCombat(AActor* Enemy, const bool bWasShot)
bIsInCombat = true;
UBlackboardComponent* EnemyBlackboard = Cast<AAIController>(Enemy->GetInstigatorController())->GetBlackboardComponent();
Cast<UQuestSystem>(PlayerActor->GetComponentByClass(UQuestSystem::StaticClass()))->QuestWidgetInstance->SetVisibility(ESlateVisibility::Hidden);
HealingJellyAmountTextBlock->SetText(FText::FromString(FString::FromInt(FMath::Clamp(Cast<ATempCharacter>(PlayerActor)->Inventory->GetItemAmount(0), 0, 99))));
//Disable Character Movement
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
@ -237,6 +238,7 @@ void ATurnBaseCombatV2::BeginPlay()
BattleLogTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("BattleLog"));
EscapePercentageTextBlock = Cast<UTextBlock>(BookHUD->GetWidgetFromName("EscapePercentage_Text"));
DamageMultiplierTextBlock = Cast<UTextBlock>(BookHUD->GetWidgetFromName("DamageMultiplier_Text"));
HealingJellyAmountTextBlock = Cast<UTextBlock>(BookHUD->GetWidgetFromName("HealingAmount_Text"));
PlayerHealthBar = Cast<UProgressBar>(BookHUD->GetWidgetFromName("PlayerHealthBar"));
EnemyHealthBar = Cast<UProgressBar>(HUD->GetWidgetFromName("EnemyHealthBar"));
ProbertiumResourceBar = Cast<UProgressBar>(BookHUD->GetWidgetFromName("ProbertiumResourceBar"));
@ -250,6 +252,7 @@ void ATurnBaseCombatV2::BeginPlay()
IButton = Cast<UButton>(BookHUD->GetWidgetFromName("Iroquoid_Button"));
BackspaceButton = Cast<UButton>(BookHUD->GetWidgetFromName("Clear_Button"));
RunButton = Cast<UButton>(BookHUD->GetWidgetFromName("Escape_Button"));
HealButton = Cast<UButton>(BookHUD->GetWidgetFromName("Heal_Button"));
CastButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::CastButtonOnClick);
PButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::PButtonOnClick);
EButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::EButtonOnClick);
@ -257,6 +260,7 @@ void ATurnBaseCombatV2::BeginPlay()
IButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::IButtonOnClick);
BackspaceButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::BackspaceButtonOnClick);
RunButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::RunButtonOnClick);
HealButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::HealButtonOnClick);
}
void ATurnBaseCombatV2::ExecuteCast(FString Combo)
@ -607,6 +611,7 @@ void ATurnBaseCombatV2::RunButtonOnClick()
{
if (FMath::RandRange(0.0f, 1.0f) >= EscapePercentage)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Escape Failed"));
EscapePercentage = CalculateEscapePercentage();
EscapePercentageTextBlock->SetText(FText::Join(FText::FromString(""), FText::FromString(FString::FromInt(EscapePercentage * 100)), FText::FromString("%")));
SwitchTurn();
@ -620,6 +625,17 @@ void ATurnBaseCombatV2::RunButtonOnClick()
EndCombat();
}
void ATurnBaseCombatV2::HealButtonOnClick()
{
if (Cast<ATempCharacter>(PlayerActor)->Inventory->GetItemAmount(0) >= 1)
{
Cast<ATempCharacter>(PlayerActor)->Inventory->GetItemByID(0)->Use(Cast<ATempCharacter>(PlayerActor));
HealingJellyAmountTextBlock->SetText(FText::FromString(FString::FromInt(FMath::Clamp(Cast<ATempCharacter>(PlayerActor)->Inventory->GetItemAmount(0), 0, 99))));
UpdateResourceBars();
SwitchTurn();
}
}
void ATurnBaseCombatV2::UpdateComboString(const FString& NewCombo) const
{
CurrentComboTextBlock->SetText(FText::FromString("?"));
@ -693,6 +709,7 @@ void ATurnBaseCombatV2::DisableButtons() const
BackspaceButton->SetIsEnabled(false);
CastButton->SetIsEnabled(false);
RunButton->SetIsEnabled(false);
HealButton->SetIsEnabled(false);
}
void ATurnBaseCombatV2::EnableButtons() const
@ -721,4 +738,6 @@ void ATurnBaseCombatV2::ToggleButtonIfResourceAvailable() const
else AButton->SetIsEnabled(false);
if (IroquoidResource >= 1) IButton->SetIsEnabled(true);
else IButton->SetIsEnabled(false);
if (Cast<ATempCharacter>(PlayerActor)->Inventory->GetItemAmount(0) >= 1) HealButton->SetIsEnabled(true);
else HealButton->SetIsEnabled(false);
}

View File

@ -167,6 +167,8 @@ private:
UTextBlock* EscapePercentageTextBlock;
UPROPERTY()
UTextBlock* DamageMultiplierTextBlock;
UPROPERTY()
UTextBlock* HealingJellyAmountTextBlock;
UPROPERTY()
UProgressBar* PlayerHealthBar;
@ -198,6 +200,8 @@ private:
UButton* BackspaceButton;
UPROPERTY()
UButton* RunButton;
UPROPERTY()
UButton* HealButton;
UFUNCTION()
void CastButtonOnClick();
@ -215,6 +219,8 @@ private:
void BackspaceButtonOnClick();
UFUNCTION()
void RunButtonOnClick();
UFUNCTION()
void HealButtonOnClick();
void UpdateComboString(const FString& NewCombo) const;
static void UpdateActionPoints();