Updated TurnBasedCombat to Link Enemy Health
This commit is contained in:
parent
8b2b9d56cb
commit
6092c22a2b
@ -3,6 +3,7 @@
|
||||
|
||||
#include "TurnBaseCombatV2.h"
|
||||
#include "CoreMinimal.h"
|
||||
#include "BehaviorTree/BlackboardComponent.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "Components/TextBlock.h"
|
||||
#include "Components/ProgressBar.h"
|
||||
@ -12,7 +13,6 @@
|
||||
// Sets default values
|
||||
ATurnBaseCombatV2::ATurnBaseCombatV2()
|
||||
{
|
||||
|
||||
if (HUDWidget == nullptr)
|
||||
{
|
||||
// Load the HUD widget from the specified path
|
||||
@ -23,6 +23,14 @@ ATurnBaseCombatV2::ATurnBaseCombatV2()
|
||||
|
||||
void ATurnBaseCombatV2::StartCombat(AActor* Enemy)
|
||||
{
|
||||
if (Enemy == nullptr) return;
|
||||
UBlackboardComponent* EnemyBlackboard = Cast<UBlackboardComponent>(Enemy->GetComponentByClass(UBlackboardComponent::StaticClass()));
|
||||
if (EnemyBlackboard->GetValueAsBool("IsInCombat")) return;
|
||||
FProperty* HealthProperty = Enemy->GetClass()->FindPropertyByName(FName("Health"));
|
||||
int32* EnemyHealthPtr = HealthProperty->ContainerPtrToValuePtr<int32>(Enemy);
|
||||
|
||||
EnemyHealth = EnemyHealthPtr;
|
||||
|
||||
if (HUD->IsInViewport()) return;
|
||||
HUD->AddToViewport();
|
||||
EnemyActor = Enemy;
|
||||
@ -48,7 +56,7 @@ void ATurnBaseCombatV2::StartCombat(AActor* Enemy)
|
||||
void ATurnBaseCombatV2::EndCombat()
|
||||
{
|
||||
//Remove the HUD from the viewport
|
||||
HUD->RemoveFromViewport();
|
||||
HUD->RemoveFromParent();
|
||||
APawn* PlayerPawn = Cast<APawn>(GetWorld()->GetFirstPlayerController()->GetPawn());
|
||||
PlayerPawn->bUseControllerRotationYaw = true;
|
||||
PlayerPawn->bUseControllerRotationPitch = true;
|
||||
@ -153,7 +161,7 @@ void ATurnBaseCombatV2::ExecuteCast(FString Combo)
|
||||
break;
|
||||
}
|
||||
//End Combat if either the player or enemy is dead
|
||||
if (EnemyHealth <= 0)
|
||||
if (*EnemyHealth <= 0)
|
||||
{
|
||||
EndCombat();
|
||||
EnemyActor->Destroy();
|
||||
@ -195,7 +203,7 @@ void ATurnBaseCombatV2::DamagePlayer(int Damage)
|
||||
|
||||
void ATurnBaseCombatV2::DamageEnemy(int Damage)
|
||||
{
|
||||
EnemyHealth -= FMath::Clamp(Damage, 0, 100);
|
||||
*EnemyHealth -= FMath::Clamp(Damage, 0, 100);
|
||||
UpdateProgressBars();
|
||||
AddBattleLogMessage("Enemy was damaged for " + FString::FromInt(Damage) + " damage.");
|
||||
}
|
||||
@ -203,7 +211,7 @@ void ATurnBaseCombatV2::DamageEnemy(int Damage)
|
||||
void ATurnBaseCombatV2::UpdateProgressBars() const
|
||||
{
|
||||
PlayerHealthBar->SetPercent(PlayerHealth / 100.0f);
|
||||
EnemyHealthBar->SetPercent(EnemyHealth / 100.0f);
|
||||
EnemyHealthBar->SetPercent(*EnemyHealth / 100.0f);
|
||||
}
|
||||
|
||||
bool ATurnBaseCombatV2::IsValidCombo(FString Combo) const
|
||||
@ -220,7 +228,7 @@ void ATurnBaseCombatV2::SwitchTurn()
|
||||
//wait for 2 seconds
|
||||
FTimerHandle UnusedHandle;
|
||||
GetWorldTimerManager().SetTimer(UnusedHandle, this, &ATurnBaseCombatV2::EnemyTurn, 2.0f, false);
|
||||
|
||||
|
||||
//activeActor = bIsPlayerTurn ? enemyActor : playerActor;
|
||||
}
|
||||
|
||||
@ -338,4 +346,4 @@ void ATurnBaseCombatV2::EnemyTurn()
|
||||
DamagePlayer(10);
|
||||
TurnIndicatorTextBlock->SetText(FText::FromString("Player Turn"));
|
||||
ToggleButtons();
|
||||
}
|
||||
}
|
||||
|
@ -21,11 +21,10 @@ class THE_TWILIGHT_ABYSS_API ATurnBaseCombatV2 : public AGameStateBase
|
||||
public:
|
||||
ATurnBaseCombatV2();
|
||||
|
||||
int* EnemyHealth = nullptr;
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
int PlayerHealth = 100;
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
int EnemyHealth = 100;
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
int DefaultActionPoints = 3;
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
int ActiveActionPoints = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user