Updated Combat to Perform GOAP Action List
This commit is contained in:
parent
3121176310
commit
1677419ef8
@ -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<UStatusEffect> StatusEffectDOTClassFinder(TEXT("/Game/Blueprints/StatusEffects/BP_DamageOverTime"));
|
||||
DOTStatusEffect = StatusEffectDOTClassFinder.Class;
|
||||
|
||||
|
||||
//static ConstructorHelpers::FClassFinder<UUserWidget> 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<AAIController>(Enemy->GetInstigatorController())->GetBlackboardComponent();
|
||||
|
||||
//if (EnemyBlackboard->GetValueAsBool("IsInCombat")) return;
|
||||
//EnemyBlackboard->SetValueAsBool("IsInCombat", true);
|
||||
FProperty* HealthProperty = Enemy->GetClass()->FindPropertyByName(FName("Health"));
|
||||
int32* EnemyHealthPtr = HealthProperty->ContainerPtrToValuePtr<int32>(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<UGOAPAgent>(Enemy->GetComponentByClass(UGOAPAgent::StaticClass()));
|
||||
TArray<UGOAPAction*> Plannn = EnemyGOAPAgent->Plan(EnemyGOAPAgent->GetWorldState(), EnemyGOAPAgent->Goals);
|
||||
|
||||
EnemyGOAPAgent = Cast<UGOAPAgent>(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<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 = "";
|
||||
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<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;
|
||||
}
|
||||
|
@ -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<UUserWidget> DeathScreenWidgetSubclass;
|
||||
|
||||
UPROPERTY()
|
||||
UGOAPAgent* EnemyGOAPAgent;
|
||||
UPROPERTY()
|
||||
TArray<UGOAPAction*> EnemyActionPlan;
|
||||
|
||||
UFUNCTION()
|
||||
UWorldState* GetWorldState() const;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user