2022-11-09 20:32:31 +00:00
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
#include "TurnBaseCombat.h"
|
2022-11-14 00:04:44 +00:00
|
|
|
#include "CoreMinimal.h"
|
2022-11-13 21:32:35 +00:00
|
|
|
#include "Blueprint/UserWidget.h"
|
2022-11-14 00:04:44 +00:00
|
|
|
#include "Components/TextBlock.h"
|
|
|
|
#include "Components/ProgressBar.h"
|
2022-11-09 21:24:36 +00:00
|
|
|
#include "Kismet/GameplayStatics.h"
|
2022-11-09 20:32:31 +00:00
|
|
|
|
2022-11-13 21:32:35 +00:00
|
|
|
ATurnBaseCombat::ATurnBaseCombat()
|
|
|
|
{
|
|
|
|
if (HUDWidget == nullptr)
|
|
|
|
{
|
|
|
|
// Load the HUD widget from the specified path
|
|
|
|
static ConstructorHelpers::FClassFinder<UUserWidget> HUDWidgetClass(TEXT("/Game/Blueprints/Combat_UI/Combat_UI"));
|
|
|
|
HUDWidget = HUDWidgetClass.Class;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-09 20:32:31 +00:00
|
|
|
void ATurnBaseCombat::BeginPlay()
|
|
|
|
{
|
|
|
|
Super::BeginPlay();
|
2022-11-13 21:32:35 +00:00
|
|
|
|
2022-11-09 21:24:36 +00:00
|
|
|
TArray<AActor*> AllCharacterActorsInScene;
|
2022-11-14 00:04:44 +00:00
|
|
|
UGameplayStatics::GetAllActorsOfClassWithTag(GetWorld(), AActor::StaticClass(), FName("Character"), AllCharacterActorsInScene);
|
2022-11-13 21:32:35 +00:00
|
|
|
ActiveActionPoints = DefaultActionPoints;
|
|
|
|
|
|
|
|
UUserWidget* HUD = CreateWidget<UUserWidget>(GetWorld(), HUDWidget);
|
|
|
|
HUD->AddToViewport();
|
2022-11-14 00:04:44 +00:00
|
|
|
|
|
|
|
TurnIndicator = Cast<UTextBlock>(HUD->GetWidgetFromName("TurnIndicator"));
|
|
|
|
PlayerHealthBar = Cast<UProgressBar>(HUD->GetWidgetFromName("PlayerHealthBar"));
|
|
|
|
EnemyHealthBar = Cast<UProgressBar>(HUD->GetWidgetFromName("EnemyHealthBar"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ATurnBaseCombat::ExecuteCast(FString Combo)
|
|
|
|
{
|
|
|
|
if (!IsValidCombo(Combo))
|
|
|
|
{
|
|
|
|
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Invalid Combo"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (bIsPlayerTurn)
|
|
|
|
{
|
|
|
|
case true:
|
|
|
|
// Player Turn
|
|
|
|
DamageEnemy(ValidCombos[Combo]);
|
|
|
|
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Enemy Damaged %f"), ValidCombos[Combo]);
|
|
|
|
break;
|
|
|
|
case false:
|
|
|
|
// Enemy Turn
|
|
|
|
DamagePlayer(ValidCombos[Combo]);
|
|
|
|
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Player Damaged %f"), ValidCombos[Combo]);
|
|
|
|
break;
|
|
|
|
}
|
2022-11-09 20:32:31 +00:00
|
|
|
}
|
|
|
|
|
2022-11-13 21:32:35 +00:00
|
|
|
void ATurnBaseCombat::UseActionPoint()
|
2022-11-09 20:32:31 +00:00
|
|
|
{
|
2022-11-13 21:32:35 +00:00
|
|
|
ActiveActionPoints -= 1;
|
|
|
|
ActiveActionPoints = FMath::Clamp(ActiveActionPoints, 0, DefaultActionPoints);
|
2022-11-09 21:03:47 +00:00
|
|
|
}
|
|
|
|
|
2022-11-13 21:32:35 +00:00
|
|
|
void ATurnBaseCombat::ReuseActionPoint()
|
2022-11-09 21:03:47 +00:00
|
|
|
{
|
2022-11-13 21:32:35 +00:00
|
|
|
ActiveActionPoints += 1;
|
|
|
|
ActiveActionPoints = FMath::Clamp(ActiveActionPoints, 0, DefaultActionPoints);
|
2022-11-09 20:32:31 +00:00
|
|
|
}
|
|
|
|
|
2022-11-13 21:32:35 +00:00
|
|
|
void ATurnBaseCombat::RevertActionPoints()
|
2022-11-09 20:32:31 +00:00
|
|
|
{
|
2022-11-13 21:32:35 +00:00
|
|
|
ActiveActionPoints = DefaultActionPoints;
|
2022-11-09 20:32:31 +00:00
|
|
|
}
|
|
|
|
|
2022-11-14 00:04:44 +00:00
|
|
|
void ATurnBaseCombat::DamagePlayer(int Damage)
|
|
|
|
{
|
|
|
|
PlayerHealth -= FMath::Clamp(Damage, 0, 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ATurnBaseCombat::DamageEnemy(int Damage)
|
|
|
|
{
|
|
|
|
EnemyHealth -= FMath::Clamp(Damage, 0, 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ATurnBaseCombat::UpdateProgressBars() const
|
|
|
|
{
|
|
|
|
PlayerHealthBar->SetPercent(PlayerHealth / 100);
|
|
|
|
EnemyHealthBar->SetPercent(EnemyHealth / 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ATurnBaseCombat::IsValidCombo(FString Combo) const
|
|
|
|
{
|
|
|
|
return ValidCombos.Contains(Combo);
|
|
|
|
}
|
|
|
|
|
2022-11-13 21:32:35 +00:00
|
|
|
void ATurnBaseCombat::SwitchTurn()
|
2022-11-09 21:03:47 +00:00
|
|
|
{
|
2022-11-13 21:32:35 +00:00
|
|
|
activeActor = bIsPlayerTurn ? enemyActor : playerActor;
|
2022-11-09 21:03:47 +00:00
|
|
|
}
|