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()
|
||||
void RemoveItem(UEatableItems* Item);
|
||||
|
||||
};
|
||||
|
Binary file not shown.
@ -3,18 +3,45 @@
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/NoExportTypes.h"
|
||||
#include "../PlayerTemp/TempCharacter.h"
|
||||
#include "UWorldState.h"
|
||||
#include "Quest.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
UENUM(BlueprintType)
|
||||
enum class EQuestLine : uint8
|
||||
{
|
||||
Main UMETA(DisplayName="Main"),
|
||||
Sub UMETA(DisplayName="Sub")
|
||||
};
|
||||
|
||||
UCLASS(Abstract, BlueprintType, Blueprintable, EditInlineNew, DefaultToInstanced)
|
||||
class THE_TWILIGHT_ABYSS_API UQuest : public UObject
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
FText Title;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
FText Description;
|
||||
FString QuestLine;
|
||||
UQuest* ParentQuest;
|
||||
FJsonObject Conditions;
|
||||
FJsonObject PreConditions;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
EQuestLine QuestLine;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, NoClear, Instanced)
|
||||
UWorldState* Goals;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Instanced)
|
||||
UWorldState* PreConditions;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, NoClear, Instanced)
|
||||
TArray<UBaseItem*> Rewards;
|
||||
|
||||
//TODO: Rewards
|
||||
|
||||
bool CheckConditions(FJsonObject WorldState);
|
||||
bool CheckPreConditions(FJsonObject WorldState);
|
||||
void ApplyRewards();
|
||||
//TODO: CreateQuest
|
||||
bool CheckConditions(UWorldState* WorldState) const;
|
||||
bool CheckPreConditions(UWorldState* WorldState) const;
|
||||
void ApplyRewards(UInventoryComponent* Inventory);
|
||||
static bool WorldStateMatch(UWorldState* A, UWorldState* B);
|
||||
};
|
||||
|
@ -20,8 +20,8 @@ UQuestSystem::UQuestSystem()
|
||||
void UQuestSystem::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)
|
||||
{
|
||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||
|
||||
}
|
||||
|
||||
void UQuestSystem::CheckActiveQuestConditions()
|
||||
@ -38,15 +37,28 @@ void UQuestSystem::CheckActiveQuestConditions()
|
||||
{
|
||||
if (Quest->CheckConditions(GetWorldState()))
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Quest Completed!"));
|
||||
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;
|
||||
}
|
||||
|
||||
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 "Blueprint/UserWidget.h"
|
||||
#include "Quest.h"
|
||||
#include "UWorldState.h"
|
||||
#include "../BaseItems/InventoryComponent.h"
|
||||
#include "QuestSystem.generated.h"
|
||||
|
||||
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
|
||||
@ -18,9 +20,11 @@ public:
|
||||
// Sets default values for this component's properties
|
||||
UQuestSystem();
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly)
|
||||
TArray<UQuest*> ActiveQuests;
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
|
||||
TArray<UQuest*> CompletedQuests;
|
||||
TArray<FString> CompletedQuestLines;
|
||||
UPROPERTY(EditAnywhere)
|
||||
TMap<FString, bool> QuestFlags;
|
||||
|
||||
protected:
|
||||
@ -36,5 +40,13 @@ public:
|
||||
// Called every frame
|
||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||
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