AzureAbyss/Source/the_twilight_abyss/Quest/Quest.cpp

48 lines
1.0 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "Quest.h"
#include "the_twilight_abyss/BaseItems/InventoryComponent.h"
bool UQuest::CheckConditions(UWorldState* WorldState) const
{
if (!IsValid(Goals)) return true;
if (WorldStateMatch(WorldState, Goals)) return true;
return false;
}
bool UQuest::CheckPreConditions(UWorldState* WorldState) const
{
if (!IsValid(PreConditions)) return true;
if (WorldStateMatch(WorldState, PreConditions)) return true;
return false;
}
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;
}