Added More GOAP Actions
This commit is contained in:
parent
3c8ab3b25e
commit
08fbc2180d
@ -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);
|
||||
}
|
@ -10,11 +10,10 @@
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class COMP250_1_2101327_AI_API UCombo_P : public UGOAPAction
|
||||
class COMP250_1_2101327_AI_API UCOMBO_P : public UGOAPAction
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
virtual void Init() override;
|
||||
virtual bool Perform() override;
|
||||
};
|
@ -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);
|
||||
}
|
@ -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;
|
||||
};
|
@ -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);
|
||||
}
|
@ -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;
|
||||
};
|
@ -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;
|
||||
}
|
@ -9,11 +9,3 @@ void UDefaultAttack::Init()
|
||||
PreConditions.Add("PlayerHealth", 1);
|
||||
Effects.Add("PlayerHealth", 1);
|
||||
}
|
||||
|
||||
bool UDefaultAttack::Perform()
|
||||
{
|
||||
ATurnBaseCombatV2* CombatSystem = Cast<ATurnBaseCombatV2>(GetWorld()->GetGameState());
|
||||
CombatSystem->DamagePlayer(1, "Punch");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -16,5 +16,4 @@ class COMP250_1_2101327_AI_API UDefaultAttack : public UGOAPAction
|
||||
|
||||
public:
|
||||
virtual void Init() override;
|
||||
virtual bool Perform() override;
|
||||
};
|
||||
|
@ -3,31 +3,33 @@
|
||||
|
||||
#include "GOAPAction.h"
|
||||
|
||||
bool UGOAPAction::CheckPreConditions(TMap<FString, int> WorldState)
|
||||
bool UGOAPAction::CheckPreConditions(UWorldState* WorldState)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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"];
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/Object.h"
|
||||
#include "COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.h"
|
||||
#include "WorldState.h"
|
||||
#include "GOAPAction.generated.h"
|
||||
|
||||
/**
|
||||
@ -19,11 +19,11 @@ public:
|
||||
float ActionCost = 1.0f;
|
||||
|
||||
UFUNCTION()
|
||||
bool CheckPreConditions(TMap<FString, int> WorldState);
|
||||
bool CheckPreConditions(UWorldState* WorldState);
|
||||
UFUNCTION()
|
||||
TMap<FString, int> ApplyEffects(TMap<FString, int> WorldState);
|
||||
UWorldState* ApplyEffects(UWorldState* WorldState);
|
||||
UFUNCTION()
|
||||
virtual bool Perform();
|
||||
virtual int Perform();
|
||||
|
||||
UPROPERTY()
|
||||
TMap<FString, int> PreConditions;
|
||||
|
@ -0,0 +1,4 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "WorldState.h"
|
@ -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;
|
||||
};
|
Loading…
Reference in New Issue
Block a user