Added Perform Function to Execute Actions from Planner

This commit is contained in:
Philip W 2023-03-20 15:27:06 +00:00
parent acdb4dde0e
commit 3c8ab3b25e
8 changed files with 35 additions and 9 deletions

Binary file not shown.

View File

@ -9,4 +9,12 @@ void UCombo_P::Init()
PreConditions.Add("ProbertiumResource", 5); PreConditions.Add("ProbertiumResource", 5);
Effects.Add("PlayerHealth", 15); Effects.Add("PlayerHealth", 15);
Effects.Add("ProbertiumResource", 5); Effects.Add("ProbertiumResource", 5);
} }
bool UCombo_P::Perform()
{
ATurnBaseCombatV2* CombatSystem = Cast<ATurnBaseCombatV2>(GetWorld()->GetGameState());
CombatSystem->DamagePlayer(15, "P");
return true;
}

View File

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

View File

@ -5,7 +5,15 @@
void UDefaultAttack::Init() void UDefaultAttack::Init()
{ {
ActionCost = 2.0f; ActionCost = 5.0f;
PreConditions.Add("PlayerHealth", 10); PreConditions.Add("PlayerHealth", 1);
Effects.Add("PlayerHealth", 10); Effects.Add("PlayerHealth", 1);
}
bool UDefaultAttack::Perform()
{
ATurnBaseCombatV2* CombatSystem = Cast<ATurnBaseCombatV2>(GetWorld()->GetGameState());
CombatSystem->DamagePlayer(1, "Punch");
return true;
} }

View File

@ -16,4 +16,5 @@ 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

@ -26,3 +26,8 @@ TMap<FString, int> UGOAPAction::ApplyEffects(TMap<FString, int> WorldState)
} }
return WorldState; return WorldState;
} }
bool UGOAPAction::Perform()
{
return false;
}

View File

@ -4,6 +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 "GOAPAction.generated.h" #include "GOAPAction.generated.h"
/** /**
@ -21,7 +22,9 @@ public:
bool CheckPreConditions(TMap<FString, int> WorldState); bool CheckPreConditions(TMap<FString, int> WorldState);
UFUNCTION() UFUNCTION()
TMap<FString, int> ApplyEffects(TMap<FString, int> WorldState); TMap<FString, int> ApplyEffects(TMap<FString, int> WorldState);
UFUNCTION()
virtual bool Perform();
UPROPERTY() UPROPERTY()
TMap<FString, int> PreConditions; TMap<FString, int> PreConditions;
UPROPERTY() UPROPERTY()