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