Updated Combat to Perform GOAP Action List

This commit is contained in:
Philip W 2023-03-22 05:37:43 +00:00
parent 3121176310
commit 1677419ef8
2 changed files with 38 additions and 49 deletions

View File

@ -7,7 +7,6 @@
#include "StatusSystem.h" #include "StatusSystem.h"
#include "Blueprint/UserWidget.h" #include "Blueprint/UserWidget.h"
#include "BehaviorTree/BlackboardComponent.h" #include "BehaviorTree/BlackboardComponent.h"
#include "COMP250_1_2101327_AI/GOAP/GOAPAgent.h"
#include "Components/TextBlock.h" #include "Components/TextBlock.h"
#include "Components/ProgressBar.h" #include "Components/ProgressBar.h"
#include "GameFramework/Character.h" #include "GameFramework/Character.h"
@ -35,24 +34,10 @@ ATurnBaseCombatV2::ATurnBaseCombatV2()
void ATurnBaseCombatV2::StartCombat(AActor* Enemy) void ATurnBaseCombatV2::StartCombat(AActor* Enemy)
{ {
if (Enemy == nullptr) return; if (Enemy == nullptr) return;
//UBlackboardComponent* EnemyBlackboard = Cast<AAIController>(Enemy->GetInstigatorController())->GetBlackboardComponent();
//if (EnemyBlackboard->GetValueAsBool("IsInCombat")) return;
//EnemyBlackboard->SetValueAsBool("IsInCombat", true);
FProperty* HealthProperty = Enemy->GetClass()->FindPropertyByName(FName("Health")); FProperty* HealthProperty = Enemy->GetClass()->FindPropertyByName(FName("Health"));
int32* EnemyHealthPtr = HealthProperty->ContainerPtrToValuePtr<int32>(Enemy); int32* EnemyHealthPtr = HealthProperty->ContainerPtrToValuePtr<int32>(Enemy);
EnemyHealth = EnemyHealthPtr; EnemyHealth = EnemyHealthPtr;
// if (EnemyBlackboard->GetValueAsBool("Sight"))
// {
// //bEnemyHasExtraTurn = true;
// SwitchTurn();
// }
// else
// {
// bPlayerHasExtraTurn = true;
// }
if (HUD->IsInViewport()) return; if (HUD->IsInViewport()) return;
HUD->AddToViewport(); HUD->AddToViewport();
EnemyActor = Enemy; EnemyActor = Enemy;
@ -77,14 +62,6 @@ void ATurnBaseCombatV2::StartCombat(AActor* Enemy)
PlayerController->SetInputMode(FInputModeUIOnly()); PlayerController->SetInputMode(FInputModeUIOnly());
PlayerController->bShowMouseCursor = true; 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 = ""; CurrentComboString = "";
UpdateComboString(CurrentComboString); UpdateComboString(CurrentComboString);
RevertActionPoints(); RevertActionPoints();
@ -92,8 +69,8 @@ void ATurnBaseCombatV2::StartCombat(AActor* Enemy)
UpdateResourceBars(); UpdateResourceBars();
ClearBattleLog(); ClearBattleLog();
UGOAPAgent* EnemyGOAPAgent = Cast<UGOAPAgent>(Enemy->GetComponentByClass(UGOAPAgent::StaticClass())); EnemyGOAPAgent = Cast<UGOAPAgent>(EnemyActor->GetComponentByClass(UGOAPAgent::StaticClass()));
TArray<UGOAPAction*> Plannn = EnemyGOAPAgent->Plan(EnemyGOAPAgent->GetWorldState(), EnemyGOAPAgent->Goals); EnemyActionPlan = EnemyGOAPAgent->Plan(GetWorldState(), EnemyGOAPAgent->Goals);
} }
void ATurnBaseCombatV2::EndCombat() void ATurnBaseCombatV2::EndCombat()
@ -120,16 +97,6 @@ void ATurnBaseCombatV2::EndCombat()
PlayerController->bShowMouseCursor = false; PlayerController->bShowMouseCursor = false;
} }
// void ATurnBaseCombatV2::FKeyPressed()
// {
// PButtonOnClick();
// }
//
// void ATurnBaseCombatV2::WKeyPressed()
// {
// EButtonOnClick();
// }
void ATurnBaseCombatV2::BeginPlay() void ATurnBaseCombatV2::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
@ -227,13 +194,6 @@ void ATurnBaseCombatV2::ExecuteCast(FString Combo)
} }
} }
// if (GunEffect)
// {
// const UStaticMeshComponent* GunComponent = Cast<UStaticMeshComponent>(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 = ""; CurrentComboString = "";
UpdateComboString(CurrentComboString); UpdateComboString(CurrentComboString);
RevertActionPoints(); RevertActionPoints();
@ -250,9 +210,9 @@ void ATurnBaseCombatV2::ExecuteCast(FString Combo)
break; break;
case false: case false:
// Enemy Turn // Enemy Turn
DamagePlayer(*ValidCombos.Find(Combo)); // DamagePlayer(*ValidCombos.Find(Combo));
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("Player Damaged %d"), *ValidCombos.Find(Combo))); // GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("Player Damaged %d"), *ValidCombos.Find(Combo)));
OnEnemyTurn.Broadcast(EnemyActor, PlayerActor); // OnEnemyTurn.Broadcast(EnemyActor, PlayerActor);
break; break;
} }
@ -509,8 +469,29 @@ void ATurnBaseCombatV2::ToggleButtons() const
void ATurnBaseCombatV2::EnemyTurn() 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); OnEnemyTurn.Broadcast(EnemyActor, PlayerActor);
TurnIndicatorTextBlock->SetText(FText::FromString("Player Turn")); TurnIndicatorTextBlock->SetText(FText::FromString("Player Turn"));
ToggleButtons(); ToggleButtons();
} }
UWorldState* ATurnBaseCombatV2::GetWorldState() const
{
UWorldState* WorldState = NewObject<UWorldState>();
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;
}

View File

@ -10,7 +10,7 @@
#include "NiagaraComponent.h" #include "NiagaraComponent.h"
#include "NiagaraFunctionLibrary.h" #include "NiagaraFunctionLibrary.h"
#include "GameFramework/GameStateBase.h" #include "GameFramework/GameStateBase.h"
#include "StatusEffects/Thorns.h" #include "COMP250_1_2101327_AI/GOAP/GOAPAgent.h"
#include "TurnBaseCombatV2.generated.h" #include "TurnBaseCombatV2.generated.h"
//class UNiagaraSystem; //class UNiagaraSystem;
@ -217,4 +217,12 @@ private:
UUserWidget* DeathScreenWidget; UUserWidget* DeathScreenWidget;
UPROPERTY() UPROPERTY()
TSubclassOf<UUserWidget> DeathScreenWidgetSubclass; TSubclassOf<UUserWidget> DeathScreenWidgetSubclass;
UPROPERTY()
UGOAPAgent* EnemyGOAPAgent;
UPROPERTY()
TArray<UGOAPAction*> EnemyActionPlan;
UFUNCTION()
UWorldState* GetWorldState() const;
}; };