AzureAbyss/Source/the_twilight_abyss/TurnBasedCombat/TurnBaseCombat.cpp

53 lines
1.3 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "TurnBaseCombat.h"
#include "Blueprint/UserWidget.h"
#include "Kismet/GameplayStatics.h"
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;
}
}
void ATurnBaseCombat::BeginPlay()
{
Super::BeginPlay();
TArray<AActor*> AllCharacterActorsInScene;
UGameplayStatics::GetAllActorsOfClassWithTag(GetWorld(), AActor::StaticClass(), FName("Character"),
AllCharacterActorsInScene);
ActiveActionPoints = DefaultActionPoints;
UUserWidget* HUD = CreateWidget<UUserWidget>(GetWorld(), HUDWidget);
HUD->AddToViewport();
}
void ATurnBaseCombat::UseActionPoint()
{
ActiveActionPoints -= 1;
ActiveActionPoints = FMath::Clamp(ActiveActionPoints, 0, DefaultActionPoints);
}
void ATurnBaseCombat::ReuseActionPoint()
{
ActiveActionPoints += 1;
ActiveActionPoints = FMath::Clamp(ActiveActionPoints, 0, DefaultActionPoints);
}
void ATurnBaseCombat::RevertActionPoints()
{
ActiveActionPoints = DefaultActionPoints;
}
void ATurnBaseCombat::SwitchTurn()
{
activeActor = bIsPlayerTurn ? enemyActor : playerActor;
}