diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.cpp b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.cpp index 36b54a7..cfd4f5a 100644 --- a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.cpp +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.cpp @@ -7,7 +7,6 @@ #include "StatusSystem.h" #include "Blueprint/UserWidget.h" #include "BehaviorTree/BlackboardComponent.h" -#include "COMP250_1_2101327_AI/GOAP/GOAPAgent.h" #include "Components/TextBlock.h" #include "Components/ProgressBar.h" #include "GameFramework/Character.h" @@ -26,7 +25,7 @@ ATurnBaseCombatV2::ATurnBaseCombatV2() ThornsStatusEffect = StatusEffectThornsClassFinder.Class; static ConstructorHelpers::FClassFinder StatusEffectDOTClassFinder(TEXT("/Game/Blueprints/StatusEffects/BP_DamageOverTime")); DOTStatusEffect = StatusEffectDOTClassFinder.Class; - + //static ConstructorHelpers::FClassFinder DeathScreenWidgetClass(TEXT("/Game/Blueprints/Death_UI/Death_UI")); //DeathScreenWidgetSubclass = DeathScreenWidgetClass.Class; } @@ -35,23 +34,9 @@ ATurnBaseCombatV2::ATurnBaseCombatV2() void ATurnBaseCombatV2::StartCombat(AActor* Enemy) { if (Enemy == nullptr) return; - //UBlackboardComponent* EnemyBlackboard = Cast(Enemy->GetInstigatorController())->GetBlackboardComponent(); - - //if (EnemyBlackboard->GetValueAsBool("IsInCombat")) return; - //EnemyBlackboard->SetValueAsBool("IsInCombat", true); FProperty* HealthProperty = Enemy->GetClass()->FindPropertyByName(FName("Health")); int32* EnemyHealthPtr = HealthProperty->ContainerPtrToValuePtr(Enemy); EnemyHealth = EnemyHealthPtr; - - // if (EnemyBlackboard->GetValueAsBool("Sight")) - // { - // //bEnemyHasExtraTurn = true; - // SwitchTurn(); - // } - // else - // { - // bPlayerHasExtraTurn = true; - // } if (HUD->IsInViewport()) return; HUD->AddToViewport(); @@ -77,23 +62,15 @@ void ATurnBaseCombatV2::StartCombat(AActor* Enemy) PlayerController->SetInputMode(FInputModeUIOnly()); PlayerController->bShowMouseCursor = true; - // FVector Direction = Enemy->GetActorLocation() - PlayerActor->GetActorLocation(); - // Direction.Normalize(); - // FRotator LookAtRotation = FRotationMatrix::MakeFromX(Direction).Rotator(); - // LookAtRotation.Pitch = -9.0f; - // PlayerController->SetControlRotation(LookAtRotation); - - //DrawDebugPoint(GetWorld(), Enemy->GetActorLocation(), 10, FColor::Red, false, 10); - CurrentComboString = ""; UpdateComboString(CurrentComboString); RevertActionPoints(); UpdateActionPoints(); UpdateResourceBars(); ClearBattleLog(); - - UGOAPAgent* EnemyGOAPAgent = Cast(Enemy->GetComponentByClass(UGOAPAgent::StaticClass())); - TArray Plannn = EnemyGOAPAgent->Plan(EnemyGOAPAgent->GetWorldState(), EnemyGOAPAgent->Goals); + + EnemyGOAPAgent = Cast(EnemyActor->GetComponentByClass(UGOAPAgent::StaticClass())); + EnemyActionPlan = EnemyGOAPAgent->Plan(GetWorldState(), EnemyGOAPAgent->Goals); } void ATurnBaseCombatV2::EndCombat() @@ -120,16 +97,6 @@ void ATurnBaseCombatV2::EndCombat() PlayerController->bShowMouseCursor = false; } -// void ATurnBaseCombatV2::FKeyPressed() -// { -// PButtonOnClick(); -// } -// -// void ATurnBaseCombatV2::WKeyPressed() -// { -// EButtonOnClick(); -// } - void ATurnBaseCombatV2::BeginPlay() { Super::BeginPlay(); @@ -227,13 +194,6 @@ void ATurnBaseCombatV2::ExecuteCast(FString Combo) } } - // if (GunEffect) - // { - // const UStaticMeshComponent* GunComponent = Cast(PlayerActor->GetComponentsByTag(UPrimitiveComponent::StaticClass(), FName("Gun"))[0]); - // const FVector GunLocationOffset = GunComponent->GetSocketTransform("Muzzle").TransformPosition(FVector(-100, 0, 0)); - // UNiagaraFunctionLibrary::SpawnSystemAtLocation(GetWorld(), GunEffect, GunLocationOffset, PlayerActor->GetActorRotation()); - // } - CurrentComboString = ""; UpdateComboString(CurrentComboString); RevertActionPoints(); @@ -250,9 +210,9 @@ void ATurnBaseCombatV2::ExecuteCast(FString Combo) break; case false: // Enemy Turn - DamagePlayer(*ValidCombos.Find(Combo)); - GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("Player Damaged %d"), *ValidCombos.Find(Combo))); - OnEnemyTurn.Broadcast(EnemyActor, PlayerActor); + // DamagePlayer(*ValidCombos.Find(Combo)); + // GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("Player Damaged %d"), *ValidCombos.Find(Combo))); + // OnEnemyTurn.Broadcast(EnemyActor, PlayerActor); break; } @@ -509,8 +469,29 @@ void ATurnBaseCombatV2::ToggleButtons() const void ATurnBaseCombatV2::EnemyTurn() { - DamagePlayer(10); + //DamagePlayer(10); + if (EnemyActionPlan.Num() > 0) + { + DamagePlayer(EnemyActionPlan[0]->Perform()); + EnemyActionPlan.RemoveAt(0); + } + else + { + EnemyActionPlan = EnemyGOAPAgent->Plan(GetWorldState(), EnemyGOAPAgent->Goals); + } OnEnemyTurn.Broadcast(EnemyActor, PlayerActor); TurnIndicatorTextBlock->SetText(FText::FromString("Player Turn")); ToggleButtons(); } + +UWorldState* ATurnBaseCombatV2::GetWorldState() const +{ + UWorldState* WorldState = NewObject(); + WorldState->State.Add("PlayerHealth", *PlayerHealth); + WorldState->State.Add("EnemyHealth", *EnemyHealth); + WorldState->State.Add("ProbertiumResource", EnemyProbertiumResource); + WorldState->State.Add("EisResource", EnemyEisResource); + WorldState->State.Add("AzosResource", EnemyAzosResource); + WorldState->State.Add("IroquoidResource", EnemyIroquoidResource); + return WorldState; +} diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.h b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.h index a4cbdae..c03ca7b 100644 --- a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.h +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.h @@ -10,7 +10,7 @@ #include "NiagaraComponent.h" #include "NiagaraFunctionLibrary.h" #include "GameFramework/GameStateBase.h" -#include "StatusEffects/Thorns.h" +#include "COMP250_1_2101327_AI/GOAP/GOAPAgent.h" #include "TurnBaseCombatV2.generated.h" //class UNiagaraSystem; @@ -217,4 +217,12 @@ private: UUserWidget* DeathScreenWidget; UPROPERTY() TSubclassOf DeathScreenWidgetSubclass; + + UPROPERTY() + UGOAPAgent* EnemyGOAPAgent; + UPROPERTY() + TArray EnemyActionPlan; + + UFUNCTION() + UWorldState* GetWorldState() const; };