// 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) { if (Rewards.IsEmpty()) return; for (UBaseItem* Item : Rewards) { Inventory->AddItem(Item); } } bool UQuest::WorldStateMatch(UWorldState* A, UWorldState* B) { if (A->Items.IsEmpty() && !B->Items.IsEmpty()) return false; for (UBaseItem* Item : B->Items) { if (!A->Items.Contains(Item) && Item->StackCount > A->Items[A->Items.Find(Item)]->StackCount) { return false; } } if (A->QuestFlags.IsEmpty() && !B->QuestFlags.IsEmpty()) return false; for (TTuple Flag : B->QuestFlags) { if (!A->QuestFlags.Contains(Flag.Key) || A->QuestFlags[Flag.Key] != Flag.Value) { return false; } } return true; } bool UQuest::FlagTrueMatch(const UWorldState* WorldState, const FString& FlagName) { if (!WorldState->QuestFlags.Contains(FlagName)) return false; return true; } 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; }