Removed LZs from Save System and Replaced with Last Location

This commit is contained in:
Rafal Swierczek 2024-02-26 17:57:39 +00:00
parent a2018e02ac
commit d45f659af9
2 changed files with 21 additions and 20 deletions

View File

@ -149,25 +149,26 @@ void ABountyHunterCharacter::EndPlay(const EEndPlayReason::Type EndPlayReason)
if (UGameplayStatics::GetCurrentLevelName(GetWorld()) != OpenWorldLevelName) return; if (UGameplayStatics::GetCurrentLevelName(GetWorld()) != OpenWorldLevelName) return;
UEVGameInstance* GI = Cast<UEVGameInstance>(GetGameInstance()); UEVGameInstance* GI = Cast<UEVGameInstance>(GetGameInstance());
if (!IsValid(GI->MainSaveGameInstanceRef)) return; if (!IsValid(GI->MainSaveGameInstanceRef)) return;
TArray<AActor*> LandingZones; GI->MainSaveGameInstanceRef->PlayerOpenWorldSpawnTransformSave = GetActorTransform();
ALandingZone* ClosestLandingZone = nullptr; // TArray<AActor*> LandingZones;
double DistToClosestLandingZone; // ALandingZone* ClosestLandingZone = nullptr;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), ALandingZone::StaticClass(), LandingZones); // double DistToClosestLandingZone;
for (AActor* LZ_Actor : LandingZones) // UGameplayStatics::GetAllActorsOfClass(GetWorld(), ALandingZone::StaticClass(), LandingZones);
{ // for (AActor* LZ_Actor : LandingZones)
ALandingZone* LZ = Cast<ALandingZone>(LZ_Actor); // {
double DistToLZ = FVector::Dist(LZ->GetExitTransform().GetLocation(), GetActorLocation()); // ALandingZone* LZ = Cast<ALandingZone>(LZ_Actor);
if (!IsValid(ClosestLandingZone)) // double DistToLZ = FVector::Dist(LZ->GetExitTransform().GetLocation(), GetActorLocation());
{ // if (!IsValid(ClosestLandingZone))
ClosestLandingZone = LZ; // {
DistToClosestLandingZone = DistToLZ; // ClosestLandingZone = LZ;
continue; // DistToClosestLandingZone = DistToLZ;
} // continue;
ClosestLandingZone = DistToClosestLandingZone >= DistToLZ ? LZ : ClosestLandingZone; // }
DistToClosestLandingZone = DistToClosestLandingZone >= DistToLZ ? DistToLZ : DistToClosestLandingZone; // ClosestLandingZone = DistToClosestLandingZone >= DistToLZ ? LZ : ClosestLandingZone;
} // DistToClosestLandingZone = DistToClosestLandingZone >= DistToLZ ? DistToLZ : DistToClosestLandingZone;
if (!IsValid(ClosestLandingZone)) return; // }
GI->MainSaveGameInstanceRef->PlayerOpenWorldSpawnTransformSave = ClosestLandingZone->GetExitTransform(); // if (!IsValid(ClosestLandingZone)) return;
// GI->MainSaveGameInstanceRef->PlayerOpenWorldSpawnTransformSave = ClosestLandingZone->GetExitTransform();
UGameplayStatics::SaveGameToSlot(GI->MainSaveGameInstanceRef, "MainSave", 0); UGameplayStatics::SaveGameToSlot(GI->MainSaveGameInstanceRef, "MainSave", 0);
} }