Updated Quest System for Functionality
This commit is contained in:
parent
bff44b56a7
commit
e3027fcd24
BIN
Content/Blueprints/Combat_UI/CombatCharacter.uasset
(Stored with Git LFS)
BIN
Content/Blueprints/Combat_UI/CombatCharacter.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Blueprints/Quests/Quest_Start.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Blueprints/Quests/Quest_Start.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -45,5 +45,4 @@ public:
|
|||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void RemoveItem(UEatableItems* Item);
|
void RemoveItem(UEatableItems* Item);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Binary file not shown.
@ -3,18 +3,45 @@
|
|||||||
|
|
||||||
#include "Quest.h"
|
#include "Quest.h"
|
||||||
|
|
||||||
bool UQuest::CheckConditions(FJsonObject WorldState)
|
#include "the_twilight_abyss/BaseItems/InventoryComponent.h"
|
||||||
|
|
||||||
|
bool UQuest::CheckConditions(UWorldState* WorldState) const
|
||||||
{
|
{
|
||||||
if (Conditions.Values.IsEmpty()) return true;
|
if (IsValid(Goals)) return true;
|
||||||
|
if (WorldStateMatch(WorldState, Goals)) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UQuest::CheckPreConditions(FJsonObject WorldState)
|
bool UQuest::CheckPreConditions(UWorldState* WorldState) const
|
||||||
{
|
{
|
||||||
if (PreConditions.Values.IsEmpty()) return true;
|
if (IsValid(PreConditions)) return true;
|
||||||
|
if (WorldStateMatch(WorldState, PreConditions)) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UQuest::ApplyRewards()
|
void UQuest::ApplyRewards(UInventoryComponent* Inventory)
|
||||||
{
|
{
|
||||||
|
for (UBaseItem* Item : Rewards)
|
||||||
|
{
|
||||||
|
Inventory->AddItem(Item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UQuest::WorldStateMatch(UWorldState* A, UWorldState* B)
|
||||||
|
{
|
||||||
|
for (UBaseItem* Item : B->Items)
|
||||||
|
{
|
||||||
|
if (!A->Items.Contains(Item) && Item->StackCount > A->Items[A->Items.Find(Item)]->StackCount)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (TTuple<FString, bool> Flag : B->QuestFlags)
|
||||||
|
{
|
||||||
|
if (!A->QuestFlags.Contains(Flag.Key) || A->QuestFlags[Flag.Key] != Flag.Value)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -3,29 +3,37 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "UObject/NoExportTypes.h"
|
#include "UWorldState.h"
|
||||||
#include "../PlayerTemp/TempCharacter.h"
|
|
||||||
#include "Quest.generated.h"
|
#include "Quest.generated.h"
|
||||||
|
|
||||||
/**
|
UENUM(BlueprintType)
|
||||||
*
|
enum class EQuestLine : uint8
|
||||||
*/
|
{
|
||||||
UCLASS()
|
Main UMETA(DisplayName="Main"),
|
||||||
|
Sub UMETA(DisplayName="Sub")
|
||||||
|
};
|
||||||
|
|
||||||
|
UCLASS(Abstract, BlueprintType, Blueprintable, EditInlineNew, DefaultToInstanced)
|
||||||
class THE_TWILIGHT_ABYSS_API UQuest : public UObject
|
class THE_TWILIGHT_ABYSS_API UQuest : public UObject
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
FText Title;
|
FText Title;
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
FText Description;
|
FText Description;
|
||||||
FString QuestLine;
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
UQuest* ParentQuest;
|
EQuestLine QuestLine;
|
||||||
FJsonObject Conditions;
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, NoClear, Instanced)
|
||||||
FJsonObject PreConditions;
|
UWorldState* Goals;
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Instanced)
|
||||||
|
UWorldState* PreConditions;
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, NoClear, Instanced)
|
||||||
|
TArray<UBaseItem*> Rewards;
|
||||||
|
|
||||||
//TODO: Rewards
|
bool CheckConditions(UWorldState* WorldState) const;
|
||||||
|
bool CheckPreConditions(UWorldState* WorldState) const;
|
||||||
bool CheckConditions(FJsonObject WorldState);
|
void ApplyRewards(UInventoryComponent* Inventory);
|
||||||
bool CheckPreConditions(FJsonObject WorldState);
|
static bool WorldStateMatch(UWorldState* A, UWorldState* B);
|
||||||
void ApplyRewards();
|
|
||||||
//TODO: CreateQuest
|
|
||||||
};
|
};
|
||||||
|
@ -20,8 +20,8 @@ UQuestSystem::UQuestSystem()
|
|||||||
void UQuestSystem::BeginPlay()
|
void UQuestSystem::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
PlayerInventory = GetOwner()->FindComponentByClass<UInventoryComponent>();
|
||||||
|
PlayerInventory->OnInventoryUpdated.AddDynamic(this, &UQuestSystem::CheckActiveQuestConditions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -29,7 +29,6 @@ void UQuestSystem::BeginPlay()
|
|||||||
void UQuestSystem::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
void UQuestSystem::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
||||||
{
|
{
|
||||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UQuestSystem::CheckActiveQuestConditions()
|
void UQuestSystem::CheckActiveQuestConditions()
|
||||||
@ -38,15 +37,28 @@ void UQuestSystem::CheckActiveQuestConditions()
|
|||||||
{
|
{
|
||||||
if (Quest->CheckConditions(GetWorldState()))
|
if (Quest->CheckConditions(GetWorldState()))
|
||||||
{
|
{
|
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Quest Completed!"));
|
||||||
CompletedQuests.Add(Quest);
|
CompletedQuests.Add(Quest);
|
||||||
Quest->ApplyRewards();
|
Quest->ApplyRewards(PlayerInventory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FJsonObject UQuestSystem::GetWorldState()
|
UWorldState* UQuestSystem::GetWorldState() const
|
||||||
{
|
{
|
||||||
FJsonObject WorldState = FJsonObject();
|
UWorldState* WorldState = NewObject<UWorldState>();
|
||||||
|
WorldState->Items = PlayerInventory->Items;
|
||||||
|
WorldState->QuestFlags = QuestFlags;
|
||||||
return WorldState;
|
return WorldState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UQuestSystem::AddQuest(UQuest* Quest)
|
||||||
|
{
|
||||||
|
ActiveQuests.Add(Quest);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UQuestSystem::AddQuestFlag(const FString FlagName, const bool FlagValue)
|
||||||
|
{
|
||||||
|
QuestFlags.Add(FlagName, FlagValue);
|
||||||
|
CheckActiveQuestConditions();
|
||||||
|
}
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#include "Components/TextBlock.h"
|
#include "Components/TextBlock.h"
|
||||||
#include "Blueprint/UserWidget.h"
|
#include "Blueprint/UserWidget.h"
|
||||||
#include "Quest.h"
|
#include "Quest.h"
|
||||||
|
#include "UWorldState.h"
|
||||||
|
#include "../BaseItems/InventoryComponent.h"
|
||||||
#include "QuestSystem.generated.h"
|
#include "QuestSystem.generated.h"
|
||||||
|
|
||||||
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
|
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
|
||||||
@ -18,9 +20,11 @@ public:
|
|||||||
// Sets default values for this component's properties
|
// Sets default values for this component's properties
|
||||||
UQuestSystem();
|
UQuestSystem();
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadOnly)
|
||||||
TArray<UQuest*> ActiveQuests;
|
TArray<UQuest*> ActiveQuests;
|
||||||
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
|
||||||
TArray<UQuest*> CompletedQuests;
|
TArray<UQuest*> CompletedQuests;
|
||||||
TArray<FString> CompletedQuestLines;
|
UPROPERTY(EditAnywhere)
|
||||||
TMap<FString, bool> QuestFlags;
|
TMap<FString, bool> QuestFlags;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -36,5 +40,13 @@ public:
|
|||||||
// Called every frame
|
// Called every frame
|
||||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||||
void CheckActiveQuestConditions();
|
void CheckActiveQuestConditions();
|
||||||
FJsonObject GetWorldState();
|
UWorldState* GetWorldState() const;
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void AddQuest(UQuest* Quest);
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void AddQuestFlag(FString FlagName, bool FlagValue);
|
||||||
|
|
||||||
|
private:
|
||||||
|
UInventoryComponent* PlayerInventory;
|
||||||
};
|
};
|
||||||
|
BIN
Source/the_twilight_abyss/Quest/UWorldState.h
Normal file
BIN
Source/the_twilight_abyss/Quest/UWorldState.h
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user