Added More GOAP Actions

This commit is contained in:
Philip W 2023-03-22 05:36:20 +00:00
parent 3c8ab3b25e
commit 08fbc2180d
13 changed files with 113 additions and 44 deletions

View File

@ -0,0 +1,12 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Combo_P.h"
void UCOMBO_P::Init()
{
ActionCost = 3.0f;
PreConditions.Add("ProbertiumResource", 1);
Effects.Add("PlayerHealth", 5);
Effects.Add("ProbertiumResource", 1);
}

View File

@ -10,11 +10,10 @@
* *
*/ */
UCLASS() UCLASS()
class COMP250_1_2101327_AI_API UCombo_P : public UGOAPAction class COMP250_1_2101327_AI_API UCOMBO_P : public UGOAPAction
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
virtual void Init() override; virtual void Init() override;
virtual bool Perform() override;
}; };

View File

@ -0,0 +1,12 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "COMBO_PP.h"
void UCOMBO_PP::Init()
{
ActionCost = 2.0f;
PreConditions.Add("ProbertiumResource", 2);
Effects.Add("PlayerHealth", 10);
Effects.Add("ProbertiumResource", 2);
}

View File

@ -0,0 +1,19 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "../GOAPAction.h"
#include "COMBO_PP.generated.h"
/**
*
*/
UCLASS()
class COMP250_1_2101327_AI_API UCOMBO_PP : public UGOAPAction
{
GENERATED_BODY()
public:
virtual void Init() override;
};

View File

@ -0,0 +1,12 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "COMBO_PPP.h"
void UCOMBO_PPP::Init()
{
ActionCost = 1.0f;
PreConditions.Add("ProbertiumResource", 3);
Effects.Add("PlayerHealth", 15);
Effects.Add("ProbertiumResource", 3);
}

View File

@ -0,0 +1,19 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "../GOAPAction.h"
#include "COMBO_PPP.generated.h"
/**
*
*/
UCLASS()
class COMP250_1_2101327_AI_API UCOMBO_PPP : public UGOAPAction
{
GENERATED_BODY()
public:
virtual void Init() override;
};

View File

@ -1,20 +0,0 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Combo_P.h"
void UCombo_P::Init()
{
PreConditions.Add("PlayerHealth", 15);
PreConditions.Add("ProbertiumResource", 5);
Effects.Add("PlayerHealth", 15);
Effects.Add("ProbertiumResource", 5);
}
bool UCombo_P::Perform()
{
ATurnBaseCombatV2* CombatSystem = Cast<ATurnBaseCombatV2>(GetWorld()->GetGameState());
CombatSystem->DamagePlayer(15, "P");
return true;
}

View File

@ -9,11 +9,3 @@ void UDefaultAttack::Init()
PreConditions.Add("PlayerHealth", 1); PreConditions.Add("PlayerHealth", 1);
Effects.Add("PlayerHealth", 1); Effects.Add("PlayerHealth", 1);
} }
bool UDefaultAttack::Perform()
{
ATurnBaseCombatV2* CombatSystem = Cast<ATurnBaseCombatV2>(GetWorld()->GetGameState());
CombatSystem->DamagePlayer(1, "Punch");
return true;
}

View File

@ -16,5 +16,4 @@ class COMP250_1_2101327_AI_API UDefaultAttack : public UGOAPAction
public: public:
virtual void Init() override; virtual void Init() override;
virtual bool Perform() override;
}; };

View File

@ -3,31 +3,33 @@
#include "GOAPAction.h" #include "GOAPAction.h"
bool UGOAPAction::CheckPreConditions(TMap<FString, int> WorldState) bool UGOAPAction::CheckPreConditions(UWorldState* WorldState)
{ {
for (TPair<FString, int> PreCondition : PreConditions) for (TPair<FString, int> PreCondition : PreConditions)
{ {
if (WorldState.Contains(PreCondition.Key)) if (WorldState->State.Contains(PreCondition.Key))
{ {
if (WorldState[PreCondition.Key] < PreCondition.Value) return false; if (WorldState->State[PreCondition.Key] < PreCondition.Value) return false;
} }
} }
return true; return true;
} }
TMap<FString, int> UGOAPAction::ApplyEffects(TMap<FString, int> WorldState) UWorldState* UGOAPAction::ApplyEffects(UWorldState* WorldState)
{ {
UWorldState* NewWorldState = NewObject<UWorldState>();
NewWorldState->State.Append(WorldState->State);
for (TPair<FString, int> Effect : Effects) for (TPair<FString, int> Effect : Effects)
{ {
if (WorldState.Contains(Effect.Key)) if (NewWorldState->State.Contains(Effect.Key))
{ {
WorldState[Effect.Key] -= Effect.Value; NewWorldState->State[Effect.Key] -= Effect.Value;
} }
} }
return WorldState; return NewWorldState;
} }
bool UGOAPAction::Perform() int UGOAPAction::Perform()
{ {
return false; return Effects["PlayerHealth"];
} }

View File

@ -4,7 +4,7 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "UObject/Object.h" #include "UObject/Object.h"
#include "COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.h" #include "WorldState.h"
#include "GOAPAction.generated.h" #include "GOAPAction.generated.h"
/** /**
@ -19,11 +19,11 @@ public:
float ActionCost = 1.0f; float ActionCost = 1.0f;
UFUNCTION() UFUNCTION()
bool CheckPreConditions(TMap<FString, int> WorldState); bool CheckPreConditions(UWorldState* WorldState);
UFUNCTION() UFUNCTION()
TMap<FString, int> ApplyEffects(TMap<FString, int> WorldState); UWorldState* ApplyEffects(UWorldState* WorldState);
UFUNCTION() UFUNCTION()
virtual bool Perform(); virtual int Perform();
UPROPERTY() UPROPERTY()
TMap<FString, int> PreConditions; TMap<FString, int> PreConditions;

View File

@ -0,0 +1,4 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "WorldState.h"

View File

@ -0,0 +1,19 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "UObject/Object.h"
#include "WorldState.generated.h"
/**
*
*/
UCLASS()
class COMP250_1_2101327_AI_API UWorldState : public UObject
{
GENERATED_BODY()
public:
TMap<FString, int> State;
};