diff --git a/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp b/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp index 7a73bb1..a249022 100644 --- a/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp +++ b/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp @@ -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(Enemy->GetComponentByClass(UBlackboardComponent::StaticClass())); + if (EnemyBlackboard->GetValueAsBool("IsInCombat")) return; + FProperty* HealthProperty = Enemy->GetClass()->FindPropertyByName(FName("Health")); + int32* EnemyHealthPtr = HealthProperty->ContainerPtrToValuePtr(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(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(); -} \ No newline at end of file +} diff --git a/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.h b/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.h index 9260d84..7d019e2 100644 --- a/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.h +++ b/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.h @@ -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;