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
|
|
|
{
|
2023-05-02 06:16:40 +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
|
|
|
{
|
2023-05-02 06:16:40 +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)
|
|
|
|
{
|
2023-05-04 04:04:37 +00:00
|
|
|
if (Rewards.IsEmpty()) return;
|
2023-05-02 04:42:48 +00:00
|
|
|
for (UBaseItem* Item : Rewards)
|
|
|
|
{
|
|
|
|
Inventory->AddItem(Item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UQuest::WorldStateMatch(UWorldState* A, UWorldState* B)
|
2023-03-29 16:36:24 +00:00
|
|
|
{
|
2023-05-04 04:04:37 +00:00
|
|
|
if (A->Items.IsEmpty() && !B->Items.IsEmpty()) return false;
|
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;
|
|
|
|
}
|
|
|
|
}
|
2023-05-04 04:04:37 +00:00
|
|
|
|
|
|
|
if (A->QuestFlags.IsEmpty() && !B->QuestFlags.IsEmpty()) return false;
|
2023-05-02 04:42:48 +00:00
|
|
|
for (TTuple<FString, bool> Flag : B->QuestFlags)
|
|
|
|
{
|
|
|
|
if (!A->QuestFlags.Contains(Flag.Key) || A->QuestFlags[Flag.Key] != Flag.Value)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2023-05-04 04:04:37 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UQuest::FlagTrueMatch(const UWorldState* WorldState, const FString& FlagName)
|
|
|
|
{
|
|
|
|
if (!WorldState->QuestFlags.Contains(FlagName)) return false;
|
2023-05-02 04:42:48 +00:00
|
|
|
return true;
|
2023-03-29 16:36:24 +00:00
|
|
|
}
|
2023-05-04 04:04:37 +00:00
|
|
|
|
|
|
|
FString UQuest::GetItemCountAndGoalAmount(const UWorldState* WorldState, UBaseItem* Item) const
|
|
|
|
{
|
|
|
|
FString Result;
|
|
|
|
if (WorldState->Items.Contains(Item))
|
|
|
|
{
|
|
|
|
Result += FString::FromInt(WorldState->Items[WorldState->Items.Find(Item)]->StackCount);
|
|
|
|
Result += "/";
|
|
|
|
Result += FString::FromInt(Goals->Items[Goals->Items.Find(Item)]->StackCount);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
Result += "0/";
|
|
|
|
Result += FString::FromInt(Goals->Items[Goals->Items.Find(Item)]->StackCount);
|
|
|
|
return Result;
|
|
|
|
}
|