Updated RealTimeCombat Script for Action Points Regen
This commit is contained in:
parent
9780242271
commit
dabaf24c65
@ -11,6 +11,7 @@
|
||||
|
||||
ARealTimeCombat::ARealTimeCombat()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
if (HUDWidget == nullptr)
|
||||
{
|
||||
// Load the HUD widget from the specified path
|
||||
@ -19,11 +20,12 @@ ARealTimeCombat::ARealTimeCombat()
|
||||
}
|
||||
}
|
||||
|
||||
void ARealTimeCombat::StartCombat(AActor* Enemy)
|
||||
void ARealTimeCombat::StartCombat()
|
||||
{
|
||||
|
||||
if (HUD->IsInViewport()) return;
|
||||
HUD->AddToViewport();
|
||||
EnemyActor = Enemy;
|
||||
//EnemyActor = Enemy;
|
||||
|
||||
// if (APlayerController* PC = Cast<APlayerController>(GetWorld()->GetFirstPlayerController()))
|
||||
// {
|
||||
@ -46,31 +48,31 @@ void ARealTimeCombat::OnMouseClick()
|
||||
|
||||
void ARealTimeCombat::OnQPress()
|
||||
{
|
||||
if (ActiveActionPoints >= HeldActionPoints)
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("No More Action Points"));
|
||||
return;
|
||||
}
|
||||
if (IronResource <= 0)
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("No More Iron"));
|
||||
return;
|
||||
}
|
||||
UseActionPoint();
|
||||
CurrentComboString.AppendChar('F');
|
||||
UpdateComboString(CurrentComboString);
|
||||
IronResource -= 1;
|
||||
UpdateResourceBars();
|
||||
}
|
||||
|
||||
void ARealTimeCombat::OnEPress()
|
||||
{
|
||||
if (ActiveActionPoints >= HeldActionPoints)
|
||||
if (ActiveActionPoints <= 0)
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("No More Action Points"));
|
||||
return;
|
||||
}
|
||||
if (IronResource <= 0)
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("No More Iron"));
|
||||
return;
|
||||
}
|
||||
UseActionPoint();
|
||||
CurrentComboString.AppendChar('F');
|
||||
UpdateComboString(CurrentComboString);
|
||||
IronResource -= 1;
|
||||
UpdateResourceBars();
|
||||
}
|
||||
|
||||
void ARealTimeCombat::OnEPress()
|
||||
{
|
||||
if (ActiveActionPoints <= 0)
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("No More Action Points"));
|
||||
return;
|
||||
}
|
||||
if (SulfurResource <= 0)
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("No More Sulfur"));
|
||||
return;
|
||||
@ -82,12 +84,37 @@ void ARealTimeCombat::OnEPress()
|
||||
UpdateResourceBars();
|
||||
}
|
||||
|
||||
void ARealTimeCombat::OnBackspacePress()
|
||||
{
|
||||
if (CurrentComboString.Len() <= 0)
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Blank Combo"));
|
||||
return;
|
||||
}
|
||||
ReuseActionPoint();
|
||||
if (CurrentComboString.Right(1) == "F")
|
||||
{
|
||||
IronResource += 1;
|
||||
}
|
||||
else if (CurrentComboString.Right(1) == "W")
|
||||
{
|
||||
SulfurResource += 1;
|
||||
}
|
||||
CurrentComboString.RemoveAt(CurrentComboString.Len() - 1);
|
||||
UpdateComboString(CurrentComboString);
|
||||
UpdateResourceBars();
|
||||
}
|
||||
|
||||
void ARealTimeCombat::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
TArray<AActor*> AllCharacterActorsInScene;
|
||||
UGameplayStatics::GetAllActorsOfClassWithTag(GetWorld(), AActor::StaticClass(), FName("Character"), AllCharacterActorsInScene);
|
||||
UGameplayStatics::GetAllActorsOfClassWithTag(GetWorld(), AActor::StaticClass(), FName("Enemy"), AllCharacterActorsInScene);
|
||||
for (AActor* Actor : AllCharacterActorsInScene)
|
||||
{
|
||||
EnemyActor = Cast<AActor>(Actor);
|
||||
}
|
||||
|
||||
HUD = CreateWidget<UUserWidget>(GetWorld(), HUDWidget);
|
||||
|
||||
@ -162,7 +189,7 @@ void ARealTimeCombat::ExecuteCast(FString Combo)
|
||||
|
||||
void ARealTimeCombat::UseActionPoint()
|
||||
{
|
||||
if (HeldActionPoints > 0 && ActiveActionPoints < MaxActionPoints)
|
||||
if (HeldActionPoints > 0 && ActiveActionPoints <= HeldActionPoints)
|
||||
{
|
||||
ActiveActionPoints -= 1;
|
||||
UpdateActionPoints();
|
||||
@ -204,15 +231,19 @@ void ARealTimeCombat::UpdateProgressBars() const
|
||||
void ARealTimeCombat::Tick(float DeltaSeconds)
|
||||
{
|
||||
Super::Tick(DeltaSeconds);
|
||||
UE_LOG(LogTemp, Warning, TEXT( "%f" ), DeltaSeconds);
|
||||
//Every second add 1 action point
|
||||
if (ActionPointsTimer >= 1.0f && ActiveActionPoints < MaxActionPoints)
|
||||
if (ActionPointsTimer >= 1.0f && HeldActionPoints < MaxActionPoints)
|
||||
{
|
||||
HeldActionPoints += 1;
|
||||
ActiveActionPoints += 1;
|
||||
UpdateActionPoints();
|
||||
ActionPointsTimer = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
ActionPointsTimer += DeltaSeconds;
|
||||
ActionPointsBar->SetPercent(ActionPointsTimer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "RealTimeCombat.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class THE_TWILIGHT_ABYSS_API ARealTimeCombat : public AActor
|
||||
class THE_TWILIGHT_ABYSS_API ARealTimeCombat : public AGameStateBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
ARealTimeCombat();
|
||||
@ -52,7 +52,7 @@ class THE_TWILIGHT_ABYSS_API ARealTimeCombat : public AActor
|
||||
FString BattleLog;
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void StartCombat(AActor* Enemy);
|
||||
void StartCombat();
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void EndCombat();
|
||||
UFUNCTION(BlueprintCallable)
|
||||
@ -61,6 +61,8 @@ class THE_TWILIGHT_ABYSS_API ARealTimeCombat : public AActor
|
||||
void OnQPress();
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void OnEPress();
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void OnBackspacePress();
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
Loading…
Reference in New Issue
Block a user