diff --git a/EndlessVendetta/Source/EndlessVendetta/BountySystem/MainBountyClass.cpp b/EndlessVendetta/Source/EndlessVendetta/BountySystem/MainBountyClass.cpp index 5499deb1..f4bd2732 100644 --- a/EndlessVendetta/Source/EndlessVendetta/BountySystem/MainBountyClass.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/BountySystem/MainBountyClass.cpp @@ -13,6 +13,7 @@ void AMainBountyClass::IncrementBountyCheckpoint() if (AOpenWorldCheckpoint* OWCP = Cast(BountyCheckpoints[0])) { OpenWorldRespawnTransform = OWCP->GetRespawnTransform(); + Ow_RespawnTransform.Broadcast(OpenWorldRespawnTransform); OpenWorldCheckpointClasses.RemoveAt(0); } // FString TipToDisplay = ""; @@ -51,6 +52,8 @@ void AMainBountyClass::SpawnOpenWorldCheckpoint() BountyCheckpoints.Add(GetWorld()->SpawnActor(OpenWorldCheckpointClass, Loc, Rot, SpawnParameters)); } ActivateFirstCheckpoint(); + if (BountyCheckpoints.IsEmpty() || BountyCheckpoints[0] == nullptr) return; + Ow_RespawnTransform.Broadcast(OpenWorldRespawnTransform); } void AMainBountyClass::SpawnCheckpoints() diff --git a/EndlessVendetta/Source/EndlessVendetta/BountySystem/MainBountyClass.h b/EndlessVendetta/Source/EndlessVendetta/BountySystem/MainBountyClass.h index 1154f7be..129d2eb0 100644 --- a/EndlessVendetta/Source/EndlessVendetta/BountySystem/MainBountyClass.h +++ b/EndlessVendetta/Source/EndlessVendetta/BountySystem/MainBountyClass.h @@ -35,6 +35,8 @@ struct FMainBountyStruct UTexture2D* Floorplan = nullptr; }; +DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(F_OW_RespawnTransform, FTransform, RespawnTransform); + UCLASS() class ENDLESSVENDETTA_API AMainBountyClass : public ABountyClass { @@ -66,6 +68,9 @@ public: UPROPERTY(EditDefaultsOnly, Category = "Bounty") FMainBountyStruct MainBountyStruct; + // Used to Update Open World Respawn in the Bounty Hunter Character + F_OW_RespawnTransform Ow_RespawnTransform; + // ------------------- METHODS --------------------------------- private: // Overrides to Display Correct Tip for Checkpoint diff --git a/EndlessVendetta/Source/EndlessVendetta/Characters/BountyHunterCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/Characters/BountyHunterCharacter.cpp index 0a7aa096..7029904d 100644 --- a/EndlessVendetta/Source/EndlessVendetta/Characters/BountyHunterCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/Characters/BountyHunterCharacter.cpp @@ -21,6 +21,7 @@ void ABountyHunterCharacter::SpawnMainBounty(UEVGameInstance* GI) const FAttachmentTransformRules AttachmentTransformRules(EAttachmentRule::SnapToTarget, true); CurrentMainBounty->AttachToComponent(GetRootComponent(), AttachmentTransformRules); CurrentMainBounty->CheckpointActivated.AddDynamic(this, &ABountyHunterCharacter::DisplayCheckpointTip); + CurrentMainBounty->Ow_RespawnTransform.AddDynamic(this, &ABountyHunterCharacter::SetOpenWorldRespawnTransform); MainBountyStruct = CurrentMainBounty->MainBountyStruct; if (UGameplayStatics::GetCurrentLevelName(GetWorld()) != OpenWorldLevelName) { @@ -136,9 +137,9 @@ void ABountyHunterCharacter::BeginPlay() SpawnSideBounties(GI); if (GI->MainSaveGameInstanceRef->PlayerOpenWorldSpawnTransformSave.GetLocation() != FVector(0 ,0 ,0)) { - FTransform SpawnTransfrom = GI->MainSaveGameInstanceRef->PlayerOpenWorldSpawnTransformSave; - SetActorTransform(SpawnTransfrom); - Cast(GetController())->SetControlRotation(SpawnTransfrom.GetRotation().Rotator()); + OpenWorldRespawnTransform = GI->MainSaveGameInstanceRef->PlayerOpenWorldSpawnTransformSave; + SetActorTransform(OpenWorldRespawnTransform); + Cast(GetController())->SetControlRotation(OpenWorldRespawnTransform.GetRotation().Rotator()); } } } @@ -151,8 +152,6 @@ void ABountyHunterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerIn { EnhancedInputComponent->BindAction(PauseMenuAction, ETriggerEvent::Started, this, &ABountyHunterCharacter::TogglePauseMenu); } - - UE_LOG(LogTemp, Warning, TEXT("Setup player input on bounty hunter character")); Super::SetupPlayerInputComponent(PlayerInputComponent); } @@ -165,13 +164,8 @@ void ABountyHunterCharacter::EndPlay(const EEndPlayReason::Type EndPlayReason) UEVGameInstance* GI = Cast(GetGameInstance()); if (!IsValid(GI->MainSaveGameInstanceRef)) return; - if (IsValid(CurrentMainBounty)) GI->MainSaveGameInstanceRef->OpenWorldCheckpointsClassesSave = CurrentMainBounty->GetOpenWorldCheckpointClasses(); - - // if main bounty exists, save its locally stored open world respawn transform - // otherwise, store it as 0,0,0 which will make the player spawn at player start instead - FTransform EmptyTransform; - GI->MainSaveGameInstanceRef->PlayerOpenWorldSpawnTransformSave = IsValid(CurrentMainBounty) ? CurrentMainBounty->GetOpenWorldRespawnTransform() : EmptyTransform; - //GI->MainSaveGameInstanceRef->PlayerOpenWorldSpawnTransformSave = GetActorTransform(); + if (IsValid(CurrentMainBounty)) GI->MainSaveGameInstanceRef->OpenWorldCheckpointsClassesSave = CurrentMainBounty->GetOpenWorldCheckpointClasses(); + GI->MainSaveGameInstanceRef->PlayerOpenWorldSpawnTransformSave = OpenWorldRespawnTransform; UGameplayStatics::SaveGameToSlot(GI->MainSaveGameInstanceRef, "MainSave", 0); } diff --git a/EndlessVendetta/Source/EndlessVendetta/Characters/BountyHunterCharacter.h b/EndlessVendetta/Source/EndlessVendetta/Characters/BountyHunterCharacter.h index 04b87c77..008db360 100644 --- a/EndlessVendetta/Source/EndlessVendetta/Characters/BountyHunterCharacter.h +++ b/EndlessVendetta/Source/EndlessVendetta/Characters/BountyHunterCharacter.h @@ -48,6 +48,9 @@ class ENDLESSVENDETTA_API ABountyHunterCharacter : public AEndlessVendettaCharac // Used to Check if all Main Bounties have been completed by the Bounties Tab bool CompletedMainBounties = false; + // Used to Decide Where in the Open World to Respawn the Player + FTransform OpenWorldRespawnTransform; + protected: public: @@ -85,6 +88,12 @@ protected: UFUNCTION(BlueprintImplementableEvent) void DisplayCheckpointTip(const FString& NewCheckpointTip); + UFUNCTION() + void SetOpenWorldRespawnTransform(FTransform RespawnTransform) + { + OpenWorldRespawnTransform = RespawnTransform; + } + // Overridden to Setup up Pause Menu Inputs virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;