2023-03-13 05:19:13 +00:00
|
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "QuestSystem.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Sets default values for this component's properties
|
|
|
|
|
UQuestSystem::UQuestSystem()
|
|
|
|
|
{
|
|
|
|
|
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
|
|
|
|
|
// off to improve performance if you don't need them.
|
|
|
|
|
PrimaryComponentTick.bCanEverTick = true;
|
|
|
|
|
|
2023-03-14 03:26:14 +00:00
|
|
|
|
static ConstructorHelpers::FClassFinder<UUserWidget> QuestWidgetClass(TEXT("/Game/Blueprints/Quest_UI/Quest_UI"));
|
2023-03-13 18:11:42 +00:00
|
|
|
|
QuestWidget = QuestWidgetClass.Class;
|
2023-03-13 05:19:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Called when the game starts
|
|
|
|
|
void UQuestSystem::BeginPlay()
|
|
|
|
|
{
|
|
|
|
|
Super::BeginPlay();
|
2023-05-02 04:42:48 +00:00
|
|
|
|
PlayerInventory = GetOwner()->FindComponentByClass<UInventoryComponent>();
|
|
|
|
|
PlayerInventory->OnInventoryUpdated.AddDynamic(this, &UQuestSystem::CheckActiveQuestConditions);
|
2023-03-13 05:19:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Called every frame
|
|
|
|
|
void UQuestSystem::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
|
|
|
|
{
|
|
|
|
|
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-29 16:36:24 +00:00
|
|
|
|
void UQuestSystem::CheckActiveQuestConditions()
|
|
|
|
|
{
|
|
|
|
|
for (UQuest* Quest : ActiveQuests)
|
|
|
|
|
{
|
|
|
|
|
if (Quest->CheckConditions(GetWorldState()))
|
|
|
|
|
{
|
2023-05-02 04:42:48 +00:00
|
|
|
|
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Quest Completed!"));
|
2023-03-29 16:36:24 +00:00
|
|
|
|
CompletedQuests.Add(Quest);
|
2023-05-02 04:42:48 +00:00
|
|
|
|
Quest->ApplyRewards(PlayerInventory);
|
2023-03-29 16:36:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-02 04:42:48 +00:00
|
|
|
|
UWorldState* UQuestSystem::GetWorldState() const
|
2023-03-29 16:36:24 +00:00
|
|
|
|
{
|
2023-05-02 04:42:48 +00:00
|
|
|
|
UWorldState* WorldState = NewObject<UWorldState>();
|
|
|
|
|
WorldState->Items = PlayerInventory->Items;
|
|
|
|
|
WorldState->QuestFlags = QuestFlags;
|
2023-03-29 16:36:24 +00:00
|
|
|
|
return WorldState;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-02 04:42:48 +00:00
|
|
|
|
void UQuestSystem::AddQuest(UQuest* Quest)
|
|
|
|
|
{
|
|
|
|
|
ActiveQuests.Add(Quest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UQuestSystem::AddQuestFlag(const FString FlagName, const bool FlagValue)
|
|
|
|
|
{
|
|
|
|
|
QuestFlags.Add(FlagName, FlagValue);
|
|
|
|
|
CheckActiveQuestConditions();
|
|
|
|
|
}
|