Updated Quest & Dialogue to Add Quests from Dialogue

This commit is contained in:
Philip W 2023-05-02 07:16:40 +01:00
parent e3027fcd24
commit d1f959a9dc
12 changed files with 120 additions and 10 deletions

Binary file not shown.

BIN
Content/Blueprints/Quests/Quest_SistersPendant.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

View File

@ -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<UQuestSystem>(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];

View File

@ -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<int, UQuest*> 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()

View File

@ -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;
}

View File

@ -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)

View File

@ -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);
// ...
}

View File

@ -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<UQuest*> 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;
};

View File

@ -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;
}

View File

@ -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;