From d1f959a9dcc9fceadd4ce3c0a0fab91cd2a7f927 Mon Sep 17 00:00:00 2001 From: PHILIP White Date: Tue, 2 May 2023 07:16:40 +0100 Subject: [PATCH] Updated Quest & Dialogue to Add Quests from Dialogue --- .../Combat_UI/CombatCharacter.uasset | 4 +- .../Quests/Quest_SistersPendant.uasset | 3 ++ Content/Dialogue/SM_Merchant_Blueprint.uasset | 4 +- .../Dialogue/DialogueNPC.cpp | 15 ++++++++ .../the_twilight_abyss/Dialogue/DialogueNPC.h | 7 ++++ Source/the_twilight_abyss/Quest/Quest.cpp | 4 +- Source/the_twilight_abyss/Quest/Quest.h | 4 +- .../Quest/QuestContainer.cpp | 35 ++++++++++++++++++ .../the_twilight_abyss/Quest/QuestContainer.h | 30 +++++++++++++++ .../the_twilight_abyss/Quest/QuestSystem.cpp | 16 +++++++- Source/the_twilight_abyss/Quest/QuestSystem.h | 8 +++- .../Quest/{UWorldState.h => WorldState.h} | Bin 846 -> 844 bytes 12 files changed, 120 insertions(+), 10 deletions(-) create mode 100644 Content/Blueprints/Quests/Quest_SistersPendant.uasset create mode 100644 Source/the_twilight_abyss/Quest/QuestContainer.cpp create mode 100644 Source/the_twilight_abyss/Quest/QuestContainer.h rename Source/the_twilight_abyss/Quest/{UWorldState.h => WorldState.h} (91%) diff --git a/Content/Blueprints/Combat_UI/CombatCharacter.uasset b/Content/Blueprints/Combat_UI/CombatCharacter.uasset index 017cf9c..6099ffa 100644 --- a/Content/Blueprints/Combat_UI/CombatCharacter.uasset +++ b/Content/Blueprints/Combat_UI/CombatCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e139c8980e9de73d4d1274c639429bb451901b34cfa778e41c4e9a274d55ea33 -size 167176 +oid sha256:a7437070c9f3bb65f9fd9d77cec30f886ca9f39ae2aa8d03e805d16c9a5a1ad6 +size 159760 diff --git a/Content/Blueprints/Quests/Quest_SistersPendant.uasset b/Content/Blueprints/Quests/Quest_SistersPendant.uasset new file mode 100644 index 0000000..d2fe7e3 --- /dev/null +++ b/Content/Blueprints/Quests/Quest_SistersPendant.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1f424e061a8f4889a4942c0fced4329eaa79c9b6f6090c5242c75d92488e7031 +size 6835 diff --git a/Content/Dialogue/SM_Merchant_Blueprint.uasset b/Content/Dialogue/SM_Merchant_Blueprint.uasset index 7f33387..73d3e78 100644 --- a/Content/Dialogue/SM_Merchant_Blueprint.uasset +++ b/Content/Dialogue/SM_Merchant_Blueprint.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2fbcd0c1e5a6a9e3e6b82dc866e61c650eb77d1cd5b231f7cbee66d70f223344 -size 74580 +oid sha256:4e595b95daa285ae1f4343aaaa303bd957f2ea9cfdd4f1c9841afa099e2543a5 +size 87521 diff --git a/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp b/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp index 6c8dea0..20ea9f1 100644 --- a/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp +++ b/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp @@ -5,6 +5,9 @@ #include "Blueprint/UserWidget.h" #include "Components/TextBlock.h" #include "GameFramework/Character.h" +#include "Kismet/KismetStringLibrary.h" +#include "the_twilight_abyss/PlayerTemp/TempCharacter.h" +#include "the_twilight_abyss/Quest/QuestSystem.h" // Sets default values for this component's properties UDialogueNPC::UDialogueNPC() @@ -55,6 +58,11 @@ void UDialogueNPC::NextDialogue() DialogueText->SetText(FText::FromString(CurrentDialogue)); return; } + if (CurrentDialogueStringPath[FMath::Clamp(DialogueIndex + 1, 0, CurrentDialogueStringPath.Num() - 1)].Mid(0, 2) == "##") + { + Cast(GetWorld()->GetFirstPlayerController()->GetPawn()->GetComponentByClass(UQuestSystem::StaticClass()))->AddQuest(Quests[UKismetStringLibrary::Conv_StringToInt(CurrentDialogueStringPath[DialogueIndex].RightChop(3))]); + DialogueIndex++; + } DialogueIndex++; if (DialogueIndex >= CurrentDialogueStringPath.Num()) @@ -167,6 +175,13 @@ void UDialogueNPC::AddChoices(UDialoguePath* ParentPath, FText ChoiceText1, FTex Choice3Text->SetText(ChoiceText3); } +UDialoguePath* UDialogueNPC::AddQuest(UDialoguePath* DialoguePath, UQuest* Quest) +{ + DialoguePath->Dialogue.Add(FText::FromString("## " + Quests.Num()).ToString()); + Quests.Add(Quests.Num(), Quest); + return DialoguePath; +} + void UDialogueNPC::Choice1() { CurrentDialoguePath = CurrentDialoguePath->Choices[0]; diff --git a/Source/the_twilight_abyss/Dialogue/DialogueNPC.h b/Source/the_twilight_abyss/Dialogue/DialogueNPC.h index 04ca90c..7122936 100644 --- a/Source/the_twilight_abyss/Dialogue/DialogueNPC.h +++ b/Source/the_twilight_abyss/Dialogue/DialogueNPC.h @@ -7,6 +7,7 @@ #include "Components/Button.h" #include "Components/TextBlock.h" #include "Components/Image.h" +#include "../Quest/Quest.h" #include "DialogueNPC.generated.h" UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) @@ -91,6 +92,9 @@ private: void NextDialogue(); void NextCharacter(); + UPROPERTY() + TMap Quests; + public: // Called every frame virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; @@ -110,6 +114,9 @@ public: void AddChoices(UDialoguePath* ParentPath, FText ChoiceText1, FText ChoiceText2, FText ChoiceText3, UDialoguePath*& ChoicePath1, UDialoguePath*& ChoicePath2, UDialoguePath*& ChoicePath3); + UFUNCTION(BlueprintCallable) + UDialoguePath* AddQuest(UDialoguePath* DialoguePath, UQuest* Quest); + UFUNCTION() void Choice1(); UFUNCTION() diff --git a/Source/the_twilight_abyss/Quest/Quest.cpp b/Source/the_twilight_abyss/Quest/Quest.cpp index 30a51cf..b73f48d 100644 --- a/Source/the_twilight_abyss/Quest/Quest.cpp +++ b/Source/the_twilight_abyss/Quest/Quest.cpp @@ -7,14 +7,14 @@ bool UQuest::CheckConditions(UWorldState* WorldState) const { - if (IsValid(Goals)) return true; + 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 (!IsValid(PreConditions)) return true; if (WorldStateMatch(WorldState, PreConditions)) return true; return false; } diff --git a/Source/the_twilight_abyss/Quest/Quest.h b/Source/the_twilight_abyss/Quest/Quest.h index 50a249c..e2e3659 100644 --- a/Source/the_twilight_abyss/Quest/Quest.h +++ b/Source/the_twilight_abyss/Quest/Quest.h @@ -3,7 +3,7 @@ #pragma once #include "CoreMinimal.h" -#include "UWorldState.h" +#include "WorldState.h" #include "Quest.generated.h" UENUM(BlueprintType) @@ -19,6 +19,8 @@ class THE_TWILIGHT_ABYSS_API UQuest : public UObject GENERATED_BODY() public: + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) + int QuestID; UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) FText Title; UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) diff --git a/Source/the_twilight_abyss/Quest/QuestContainer.cpp b/Source/the_twilight_abyss/Quest/QuestContainer.cpp new file mode 100644 index 0000000..27695f2 --- /dev/null +++ b/Source/the_twilight_abyss/Quest/QuestContainer.cpp @@ -0,0 +1,35 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "QuestContainer.h" + + +// Sets default values for this component's properties +UQuestContainer::UQuestContainer() +{ + // 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; + + // ... +} + + +// Called when the game starts +void UQuestContainer::BeginPlay() +{ + Super::BeginPlay(); + + // ... + +} + + +// Called every frame +void UQuestContainer::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + + // ... +} + diff --git a/Source/the_twilight_abyss/Quest/QuestContainer.h b/Source/the_twilight_abyss/Quest/QuestContainer.h new file mode 100644 index 0000000..0595009 --- /dev/null +++ b/Source/the_twilight_abyss/Quest/QuestContainer.h @@ -0,0 +1,30 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Components/ActorComponent.h" +#include "Quest.h" +#include "QuestContainer.generated.h" + + +UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) +class THE_TWILIGHT_ABYSS_API UQuestContainer : public UActorComponent +{ + GENERATED_BODY() + +public: + // Sets default values for this component's properties + UQuestContainer(); + + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, NoClear, Instanced) + TArray Quests; + +protected: + // Called when the game starts + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; +}; diff --git a/Source/the_twilight_abyss/Quest/QuestSystem.cpp b/Source/the_twilight_abyss/Quest/QuestSystem.cpp index 2860e3c..9087ac5 100644 --- a/Source/the_twilight_abyss/Quest/QuestSystem.cpp +++ b/Source/the_twilight_abyss/Quest/QuestSystem.cpp @@ -52,9 +52,11 @@ UWorldState* UQuestSystem::GetWorldState() const return WorldState; } -void UQuestSystem::AddQuest(UQuest* Quest) +bool UQuestSystem::AddQuest(UQuest* Quest) { + if (!Quest->CheckPreConditions(GetWorldState())) return false; ActiveQuests.Add(Quest); + return true; } void UQuestSystem::AddQuestFlag(const FString FlagName, const bool FlagValue) @@ -62,3 +64,15 @@ void UQuestSystem::AddQuestFlag(const FString FlagName, const bool FlagValue) QuestFlags.Add(FlagName, FlagValue); CheckActiveQuestConditions(); } + +bool UQuestSystem::CheckPreConditions(UQuest* Quest) const +{ + if (Quest->CheckPreConditions(GetWorldState())) return true; + return false; +} + +bool UQuestSystem::HasActiveQuest(UQuest* Quest) const +{ + if (ActiveQuests.Contains(Quest)) return true; + return false; +} diff --git a/Source/the_twilight_abyss/Quest/QuestSystem.h b/Source/the_twilight_abyss/Quest/QuestSystem.h index 247ff21..0a04290 100644 --- a/Source/the_twilight_abyss/Quest/QuestSystem.h +++ b/Source/the_twilight_abyss/Quest/QuestSystem.h @@ -7,7 +7,7 @@ #include "Components/TextBlock.h" #include "Blueprint/UserWidget.h" #include "Quest.h" -#include "UWorldState.h" +#include "WorldState.h" #include "../BaseItems/InventoryComponent.h" #include "QuestSystem.generated.h" @@ -43,9 +43,13 @@ public: UWorldState* GetWorldState() const; UFUNCTION(BlueprintCallable) - void AddQuest(UQuest* Quest); + bool AddQuest(UQuest* Quest); UFUNCTION(BlueprintCallable) void AddQuestFlag(FString FlagName, bool FlagValue); + UFUNCTION(BlueprintPure) + bool CheckPreConditions(UQuest* Quest) const; + UFUNCTION(BlueprintCallable) + bool HasActiveQuest(UQuest* Quest) const; private: UInventoryComponent* PlayerInventory; diff --git a/Source/the_twilight_abyss/Quest/UWorldState.h b/Source/the_twilight_abyss/Quest/WorldState.h similarity index 91% rename from Source/the_twilight_abyss/Quest/UWorldState.h rename to Source/the_twilight_abyss/Quest/WorldState.h index 1a17f5cf4349882d59feb8071b4b8398aa13fc0c..3e05547f80af3c1c05582e2606d06bc3fdfcfbff 100644 GIT binary patch delta 10 RcmX@dc7|=jzKsX^m;f9O1oi*` delta 14 WcmX@Zc8+brzR8mq#Wr55Vgdj#_69Hj