AzureAbyss/Source/the_twilight_abyss/Quest/Quest.cpp

48 lines
1.0 KiB
C++
Raw Normal View History

2023-03-29 16:36:24 +00:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "Quest.h"
2023-05-02 04:42:48 +00:00
#include "the_twilight_abyss/BaseItems/InventoryComponent.h"
bool UQuest::CheckConditions(UWorldState* WorldState) const
2023-03-29 16:36:24 +00:00
{
if (!IsValid(Goals)) return true;
2023-05-02 04:42:48 +00:00
if (WorldStateMatch(WorldState, Goals)) return true;
2023-03-29 16:36:24 +00:00
return false;
}
2023-05-02 04:42:48 +00:00
bool UQuest::CheckPreConditions(UWorldState* WorldState) const
2023-03-29 16:36:24 +00:00
{
if (!IsValid(PreConditions)) return true;
2023-05-02 04:42:48 +00:00
if (WorldStateMatch(WorldState, PreConditions)) return true;
2023-03-29 16:36:24 +00:00
return false;
}
2023-05-02 04:42:48 +00:00
void UQuest::ApplyRewards(UInventoryComponent* Inventory)
{
for (UBaseItem* Item : Rewards)
{
Inventory->AddItem(Item);
}
}
bool UQuest::WorldStateMatch(UWorldState* A, UWorldState* B)
2023-03-29 16:36:24 +00:00
{
2023-05-02 04:42:48 +00:00
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;
2023-03-29 16:36:24 +00:00
}