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 "GameFramework/Character.h"
#include "Kismet/KismetStringLibrary.h" #include "Kismet/KismetStringLibrary.h"
#include "Misc/OutputDeviceNull.h" #include "Misc/OutputDeviceNull.h"
#include "the_twilight_abyss/PlayerTemp/TempCharacter.h"
#include "the_twilight_abyss/Quest/QuestSystem.h" #include "the_twilight_abyss/Quest/QuestSystem.h"
// Sets default values for this component's properties // Sets default values for this component's properties
@ -69,6 +70,17 @@ void UDialogueNPC::NextDialogue()
FOutputDeviceNull AR; FOutputDeviceNull AR;
const FString Command = BlueprintFunctions[UKismetStringLibrary::Conv_StringToInt(CurrentDialogueStringPath[DialogueIndex].RightChop(3))];; const FString Command = BlueprintFunctions[UKismetStringLibrary::Conv_StringToInt(CurrentDialogueStringPath[DialogueIndex].RightChop(3))];;
GetOwner()->CallFunctionByNameWithArguments(*Command, AR, nullptr, true); 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++; DialogueIndex++;
} }
@ -127,6 +139,7 @@ void UDialogueNPC::TickComponent(float DeltaTime, ELevelTick TickType, FActorCom
void UDialogueNPC::StartDialogue() void UDialogueNPC::StartDialogue()
{ {
Quests.Empty(); Quests.Empty();
bInShop = false;
FOutputDeviceNull AR; FOutputDeviceNull AR;
const FString Command = FString::Printf(TEXT("SetRootDialoguePath")); const FString Command = FString::Printf(TEXT("SetRootDialoguePath"));
GetOwner()->CallFunctionByNameWithArguments(*Command, AR, nullptr, true); GetOwner()->CallFunctionByNameWithArguments(*Command, AR, nullptr, true);
@ -165,15 +178,18 @@ void UDialogueNPC::EndDialogue()
TextAnimationTimerHandle.Invalidate(); TextAnimationTimerHandle.Invalidate();
DialogueWidgetInstance->RemoveFromParent(); DialogueWidgetInstance->RemoveFromParent();
//Enable Character Movement if (!bInShop)
if (ACharacter* PlayerCharacter = Cast<ACharacter>(GetWorld()->GetFirstPlayerController()->GetPawn()))
{ {
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() UDialoguePath* UDialogueNPC::CreateRootDialoguePath()
@ -210,11 +226,25 @@ UDialoguePath* UDialogueNPC::AddQuest(UDialoguePath* DialoguePath, UQuest* Quest
UDialoguePath* UDialogueNPC::CallBlueprintFunction(UDialoguePath* DialoguePath, const FString FunctionName) 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); BlueprintFunctions.Add(BlueprintFunctions.Num(), FunctionName);
return DialoguePath; 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() void UDialogueNPC::Choice1()
{ {
CurrentDialoguePath = CurrentDialoguePath->Choices[0]; CurrentDialoguePath = CurrentDialoguePath->Choices[0];

View File

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

View File

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

View File

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

View File

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

View File

@ -115,7 +115,14 @@ bool UQuestSystem::AddQuest(UQuest* Quest)
void UQuestSystem::AddQuestFlag(const FString FlagName, const bool FlagValue) 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(); CheckActiveQuestConditions();
} }