Updated Merchant for Pendant Quest & Attempted to Replace Open Dialogue

This commit is contained in:
Philip W 2023-05-11 08:52:30 +01:00
parent 814c2d6aaa
commit 902163d4fe
13 changed files with 121 additions and 63 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

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

Binary file not shown.

Binary file not shown.

BIN
Content/Levels/Build.umap (Stored with Git LFS)

Binary file not shown.

View File

@ -7,6 +7,7 @@
#include "GameFramework/Character.h"
#include "Kismet/KismetStringLibrary.h"
#include "Misc/OutputDeviceNull.h"
#include "the_twilight_abyss/PlayerTemp/TempCharacter.h"
#include "the_twilight_abyss/Quest/QuestSystem.h"
// Sets default values for this component's properties
@ -69,6 +70,17 @@ void UDialogueNPC::NextDialogue()
FOutputDeviceNull AR;
const FString Command = BlueprintFunctions[UKismetStringLibrary::Conv_StringToInt(CurrentDialogueStringPath[DialogueIndex].RightChop(3))];;
GetOwner()->CallFunctionByNameWithArguments(*Command, AR, nullptr, true);
if (Command == "OpenShop") bInShop = true;
DialogueIndex++;
}
else if (CurrentDialogueStringPath[FMath::Clamp(DialogueIndex + 1, 0, CurrentDialogueStringPath.Num() - 1)].Mid(0, 2) == "$$")
{
Cast<UInventoryComponent>(GetWorld()->GetFirstPlayerController()->GetPawn()->GetComponentByClass(UInventoryComponent::StaticClass()))->AddItem(ItemsToGive[UKismetStringLibrary::Conv_StringToInt(CurrentDialogueStringPath[DialogueIndex].RightChop(3))]);
DialogueIndex++;
}
else if (CurrentDialogueStringPath[FMath::Clamp(DialogueIndex + 1, 0, CurrentDialogueStringPath.Num() - 1)].Mid(0, 2) == "%%")
{
Cast<UQuestSystem>(GetWorld()->GetFirstPlayerController()->GetPawn()->GetComponentByClass(UQuestSystem::StaticClass()))->AddQuestFlag(QuestFlags[UKismetStringLibrary::Conv_StringToInt(CurrentDialogueStringPath[DialogueIndex].RightChop(3))], true);
DialogueIndex++;
}
@ -127,6 +139,7 @@ void UDialogueNPC::TickComponent(float DeltaTime, ELevelTick TickType, FActorCom
void UDialogueNPC::StartDialogue()
{
Quests.Empty();
bInShop = false;
FOutputDeviceNull AR;
const FString Command = FString::Printf(TEXT("SetRootDialoguePath"));
GetOwner()->CallFunctionByNameWithArguments(*Command, AR, nullptr, true);
@ -165,15 +178,18 @@ void UDialogueNPC::EndDialogue()
TextAnimationTimerHandle.Invalidate();
DialogueWidgetInstance->RemoveFromParent();
//Enable Character Movement
if (ACharacter* PlayerCharacter = Cast<ACharacter>(GetWorld()->GetFirstPlayerController()->GetPawn()))
if (!bInShop)
{
PlayerCharacter->EnableInput(GetWorld()->GetFirstPlayerController());
//Enable Character Movement
if (ACharacter* PlayerCharacter = Cast<ACharacter>(GetWorld()->GetFirstPlayerController()->GetPawn()))
{
PlayerCharacter->EnableInput(GetWorld()->GetFirstPlayerController());
}
//Reset UI Mode
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
PlayerController->SetInputMode(FInputModeGameOnly());
PlayerController->bShowMouseCursor = false;
}
//Reset UI Mode
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
PlayerController->SetInputMode(FInputModeGameOnly());
PlayerController->bShowMouseCursor = false;
}
UDialoguePath* UDialogueNPC::CreateRootDialoguePath()
@ -210,11 +226,25 @@ UDialoguePath* UDialogueNPC::AddQuest(UDialoguePath* DialoguePath, UQuest* Quest
UDialoguePath* UDialogueNPC::CallBlueprintFunction(UDialoguePath* DialoguePath, const FString FunctionName)
{
DialoguePath->Dialogue.Add(FText::FromString("@@ " + FunctionName).ToString());
DialoguePath->Dialogue.Add(FText::FromString("@@ " + FString::FromInt(BlueprintFunctions.Num())).ToString());
BlueprintFunctions.Add(BlueprintFunctions.Num(), FunctionName);
return DialoguePath;
}
UDialoguePath* UDialogueNPC::AddItem(UDialoguePath* DialoguePath, const int ItemIndex)
{
DialoguePath->Dialogue.Add(FText::FromString("$$ " + FString::FromInt(ItemIndexes.Num())).ToString());
ItemIndexes.Add(ItemIndexes.Num(), ItemIndex);
return DialoguePath;
}
UDialoguePath* UDialogueNPC::AddQuestFlag(UDialoguePath* DialoguePath, FString Flag)
{
DialoguePath->Dialogue.Add(FText::FromString("%% " + FString::FromInt(QuestFlags.Num())).ToString());
QuestFlags.Add(QuestFlags.Num(), Flag);
return DialoguePath;
}
void UDialogueNPC::Choice1()
{
CurrentDialoguePath = CurrentDialoguePath->Choices[0];

View File

@ -44,6 +44,9 @@ public:
UPROPERTY(EditAnywhere)
UTexture2D* NPCPortrait;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Instanced)
TArray<UBaseItem*> ItemsToGive;
UPROPERTY(EditAnywhere)
float TextAnimationSpeed = 0.05f;
@ -96,6 +99,13 @@ private:
TMap<int, UQuest*> Quests;
UPROPERTY()
TMap<int, FString> BlueprintFunctions;
UPROPERTY()
TMap<int, int> ItemIndexes;
UPROPERTY()
TMap<int, FString> QuestFlags;
UPROPERTY()
bool bInShop = false;
void ResetDialogueUI();
@ -120,9 +130,12 @@ public:
UFUNCTION(BlueprintCallable)
UDialoguePath* AddQuest(UDialoguePath* DialoguePath, UQuest* Quest);
UFUNCTION(BlueprintCallable)
UDialoguePath* CallBlueprintFunction(UDialoguePath* DialoguePath, FString FunctionName);
UFUNCTION(BlueprintCallable)
UDialoguePath* AddItem(UDialoguePath* DialoguePath, int ItemIndex);
UFUNCTION(BlueprintCallable)
UDialoguePath* AddQuestFlag(UDialoguePath* DialoguePath, FString Flag);
UFUNCTION()
void Choice1();

View File

@ -3,6 +3,7 @@
#include "InteractNPC.h"
#include "DialogueNPC.h"
#include "Camera/CameraComponent.h"
// Sets default values for this component's properties
@ -36,8 +37,8 @@ void UInteractNPC::TickComponent(float DeltaTime, ELevelTick TickType, FActorCom
void UInteractNPC::Interact()
{
FVector Start = GetOwner()->GetActorLocation();
FVector End = GetOwner()->GetActorForwardVector() * 100.0f + Start;
FVector Start = Cast<UCameraComponent>(GetOwner()->FindComponentByClass<UCameraComponent>())->GetComponentLocation();
FVector End = GetOwner()->GetActorForwardVector() * 300.0f + Start;
FCollisionQueryParams CollisionParams;
CollisionParams.AddIgnoredActor(GetOwner());
if (FHitResult HitResult; GetWorld()->LineTraceSingleByChannel(HitResult, Start, End, ECC_Pawn, CollisionParams))

View File

@ -10,6 +10,7 @@
#include "Components/WidgetComponent.h"
#include "Kismet/KismetMathLibrary.h"
#include "the_twilight_abyss/PlayerTemp/TempCharacter.h"
#include "the_twilight_abyss/Quest/QuestSystem.h"
// Sets default values
@ -69,40 +70,41 @@ void AInteraction::Tick(float DeltaTime)
void AInteraction::OnInteract()
{
bDisableShopDialMove = true;
if (ShopDialogWidget == nullptr)
{
UE_LOG(LogTemp, Display, TEXT("ShopDialogWidget is null"));
return;
}
else
{
//Shop Widget to visible
ShopDialogWidget->SetVisibility(ESlateVisibility::Visible);
//Call a custom event in a blueprint called "PlayText"
ShopDialogWidget->CallFunctionByNameWithArguments(TEXT("PlayText"), *GLog, nullptr, true);
}
//handles the widget disappearing from the viewport
FTimerHandle WidgetTimer;
GetWorldTimerManager().SetTimer(WidgetTimer, this, &AInteraction::RemoveWidget, WaitTimer, false);
// bDisableShopDialMove = true;
// if (ShopDialogWidget == nullptr)
// {
// UE_LOG(LogTemp, Display, TEXT("ShopDialogWidget is null"));
// return;
// }
// else
// {
// //Shop Widget to visible
// ShopDialogWidget->SetVisibility(ESlateVisibility::Visible);
// //Call a custom event in a blueprint called "PlayText"
// ShopDialogWidget->CallFunctionByNameWithArguments(TEXT("PlayText"), *GLog, nullptr, true);
// }
// //handles the widget disappearing from the viewport
// FTimerHandle WidgetTimer;
// GetWorldTimerManager().SetTimer(WidgetTimer, this, &AInteraction::RemoveWidget, WaitTimer, false);
}
void AInteraction::RemoveWidget()
{
bDisableShopDialMove = true;
bisDisabled = true;
//Setting ShopWidgetText back to hidden
ShopDialogWidget->SetVisibility(ESlateVisibility::Hidden);
if (ShopDialogWidget->IsVisible())
{
return;
}
else
{
UE_LOG(LogTemp, Display, TEXT("You cant open this widget when this widget is open"));
}
// ShopDialogWidget->SetVisibility(ESlateVisibility::Hidden);
// if (ShopDialogWidget->IsVisible())
// {
// return;
// }
// else
// {
// UE_LOG(LogTemp, Display, TEXT("You cant open this widget when this widget is open"));
// }
UE_LOG(LogTemp, Display, TEXT("setting isDisabled to true"));
Cast<UQuestSystem>(GetWorld()->GetFirstPlayerController()->GetCharacter()->GetComponentByClass(UQuestSystem::StaticClass()))->QuestWidgetInstance->SetVisibility(ESlateVisibility::Hidden);
if (Property == nullptr)
{
UE_LOG(LogTemp, Error, TEXT("Property not found"));
@ -209,6 +211,7 @@ void AInteraction::ExitScreen()
{
TempCharacterRef->InputEnabler();
ItemSelectorWidget->SetVisibility(ESlateVisibility::Hidden);
Cast<UQuestSystem>(GetWorld()->GetFirstPlayerController()->GetCharacter()->GetComponentByClass(UQuestSystem::StaticClass()))->QuestWidgetInstance->SetVisibility(ESlateVisibility::HitTestInvisible);
}
}

View File

@ -28,7 +28,7 @@ public:
UPROPERTY(EditAnywhere, Category= "Widgets")
TSubclassOf<UUserWidget> ShopDialog;
UPROPERTY(EditAnywhere, Category= "Widgets")
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category= "Widgets")
TSubclassOf<UUserWidget> ItemSelector;
UPROPERTY(EditAnywhere, Category = "Widgets")
@ -39,6 +39,7 @@ public:
virtual void OnInteract();
UFUNCTION(BlueprintCallable)
virtual void RemoveWidget();
UPROPERTY()

View File

@ -202,19 +202,19 @@ void ATempCharacter::LineTraceLogic()
else
{
//DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f);
MyInteractable->OnInteract();
UE_LOG(LogTemp, Display, TEXT("OnInteract activated"));
UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName());
// While loop to check bisDisabled var until it changes to true
while (MyInteractable->bisDisabled == false || MyInteractable->bDisableShopDialMove == false)
{
if (MyInteractable->bisDisabled == true || MyInteractable->bDisableShopDialMove == true)
{
InputDisabler();
break;
}
}
// MyInteractable->OnInteract();
// UE_LOG(LogTemp, Display, TEXT("OnInteract activated"));
// UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName());
//
// // While loop to check bisDisabled var until it changes to true
// while (MyInteractable->bisDisabled == false || MyInteractable->bDisableShopDialMove == false)
// {
// if (MyInteractable->bisDisabled == true || MyInteractable->bDisableShopDialMove == true)
// {
// InputDisabler();
// break;
// }
// }
}
}
}

View File

@ -115,7 +115,14 @@ bool UQuestSystem::AddQuest(UQuest* Quest)
void UQuestSystem::AddQuestFlag(const FString FlagName, const bool FlagValue)
{
QuestFlags.Add(FlagName, FlagValue);
if (HasQuestFlag(FlagName))
{
QuestFlags[FlagName] = FlagValue;
}
else
{
QuestFlags.Add(FlagName, FlagValue);
}
CheckActiveQuestConditions();
}