From 9c747a96c244ac9cceb9792b66e61273f7773340 Mon Sep 17 00:00:00 2001 From: PHILIP White Date: Mon, 22 May 2023 17:37:53 +0100 Subject: [PATCH] Bugfix Soft Lock when Combat is Initialised on Dialogue or Merchant --- .../Dialogue/InteractNPC.cpp | 20 ++++++++++++++++ .../the_twilight_abyss/Dialogue/InteractNPC.h | 3 +++ .../PlayerTemp/TempCharacter.cpp | 24 +++++++++++++++++++ .../PlayerTemp/TempCharacter.h | 4 +++- .../TurnBasedCombatV2/TurnBaseCombatV2.cpp | 10 ++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) diff --git a/Source/the_twilight_abyss/Dialogue/InteractNPC.cpp b/Source/the_twilight_abyss/Dialogue/InteractNPC.cpp index 0c49cf2..a9b88c5 100644 --- a/Source/the_twilight_abyss/Dialogue/InteractNPC.cpp +++ b/Source/the_twilight_abyss/Dialogue/InteractNPC.cpp @@ -49,6 +49,7 @@ void UInteractNPC::Interact() { //DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 5.0f, 0, 10.0f); if (Cast(GetOwner())->bShopKeeperText) return; + if (Cast(GetWorld()->GetGameState())->bIsInCombat) return; UDialogueNPC* DialogueNPC = HitResult.GetActor()->FindComponentByClass(); if (DialogueNPC->bIsInDialogue) { @@ -61,3 +62,22 @@ void UInteractNPC::Interact() } } +void UInteractNPC::EndInteract() +{ + FVector Start = Cast(GetOwner()->FindComponentByClass())->GetComponentLocation(); + FVector End = GetOwner()->GetActorForwardVector() * 300.0f + Start; + FCollisionQueryParams CollisionParams; + CollisionParams.AddIgnoredActor(GetOwner()); + if (FHitResult HitResult; GetWorld()->LineTraceSingleByChannel(HitResult, Start, End, ECC_Pawn, CollisionParams)) + { + //UE_LOG(LogTemp, Warning, TEXT("Hit: %s"), *HitResult.GetActor()->GetName()); + if (HitResult.GetActor()->Tags.Contains("NPC")) + { + //DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 5.0f, 0, 10.0f); + UDialogueNPC* DialogueNPC = HitResult.GetActor()->FindComponentByClass(); + DialogueNPC->EndDialogue(); + } + //DrawDebugLine(GetWorld(), Start, End, FColor::Red, false, 5.0f, 0, 10.0f); + } +} + diff --git a/Source/the_twilight_abyss/Dialogue/InteractNPC.h b/Source/the_twilight_abyss/Dialogue/InteractNPC.h index 6c76b27..0bd7c11 100644 --- a/Source/the_twilight_abyss/Dialogue/InteractNPC.h +++ b/Source/the_twilight_abyss/Dialogue/InteractNPC.h @@ -26,4 +26,7 @@ public: UFUNCTION(BlueprintCallable) void Interact(); + + UFUNCTION(BlueprintCallable) + void EndInteract(); }; diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp index 85f2c3e..6d3725e 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp @@ -114,6 +114,8 @@ void ATempCharacter::Tick(float DeltaTime) FVector WidgetLocation; FirstPlayerController->DeprojectMousePositionToWorld(WidgetLocation, VectorRotation); WidgetPointer->SetWorldLocationAndRotation(WidgetLocation, VectorRotation.Rotation().Quaternion()); + CrossHair->SetBrush(FSlateBrush()); + CrossHair->SetDesiredSizeOverride(FVector2D(5, 5)); } else { @@ -242,6 +244,28 @@ void ATempCharacter::LineTraceLogic() } } +void ATempCharacter::ExitMerchant() +{ + ThisCamera = Cast(this->FindComponentByClass()); + const float GlobalTrace = TraceDistance; + const FVector Start = ThisCamera->GetComponentLocation(); + const FVector End = Start + GlobalTrace * ThisCamera->GetForwardVector(); + FCollisionQueryParams TraceParams; + TraceParams.AddIgnoredActor(this); + bHit = GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Pawn, TraceParams); + if (bHit) + { + if (OutHit.GetActor() == nullptr) return; + if (AInteraction* MyInteractable = Cast(OutHit.GetActor())) + { + if (MyInteractable->ShopDialogWidget->IsVisible()) + { + MyInteractable->ExitScreen(); + } + } + } +} + void ATempCharacter::AddToInventory() { if (OutHit.GetActor()->FindComponentByClass()) diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h index dd3d05f..55601a0 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h @@ -56,7 +56,6 @@ public: UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = "true")) class UInventoryComponent* Inventory; //Using the InventoryComponent class - // Called to bind functionality to input virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; @@ -70,6 +69,9 @@ public: void LineTraceLogic(); + UFUNCTION(BlueprintCallable) + void ExitMerchant(); + UPROPERTY() class UPawnNoiseEmitterComponent* NoiseEmitter; diff --git a/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp b/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp index 9dfb719..7f5e986 100644 --- a/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp +++ b/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp @@ -12,6 +12,7 @@ #include "Kismet/GameplayStatics.h" #include "Kismet/KismetMathLibrary.h" #include "Misc/OutputDeviceNull.h" +#include "the_twilight_abyss/Dialogue/InteractNPC.h" #include "the_twilight_abyss/PlayerTemp/TempCharacter.h" #include "the_twilight_abyss/Quest/QuestSystem.h" @@ -57,6 +58,15 @@ void ATurnBaseCombatV2::StartCombat(AActor* Enemy, const bool bWasShot) Cast(PlayerActor->GetComponentByClass(UQuestSystem::StaticClass()))->QuestWidgetInstance->SetVisibility(ESlateVisibility::Hidden); HealingJellyAmountTextBlock->SetText(FText::FromString(FString::FromInt(FMath::Clamp(Cast(PlayerActor)->Inventory->GetItemAmount(0), 0, 99)))); + if (Cast(PlayerActor)->bIsInDialogue) + { + Cast(PlayerActor->GetComponentByClass(UInteractNPC::StaticClass()))->EndInteract(); + } + if (Cast(PlayerActor)->bShopKeeperText) + { + Cast(PlayerActor)->ExitMerchant(); + } + FOutputDeviceNull AR; const FString Command = FString::Printf(TEXT("CloseInventory")); PlayerActor->CallFunctionByNameWithArguments(*Command, AR, nullptr, true);