From cdca489c56efa5b9aa44cd5623e20f8f60221634 Mon Sep 17 00:00:00 2001 From: Kingsmedia Date: Tue, 10 May 2022 17:32:48 +0200 Subject: [PATCH] 127 - Restart Game --- .../BlasterPlayerController.cpp | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.cpp b/Source/Blaster/PlayerController/BlasterPlayerController.cpp index 9906af8..a3d292d 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.cpp +++ b/Source/Blaster/PlayerController/BlasterPlayerController.cpp @@ -183,7 +183,7 @@ void ABlasterPlayerController::ServerRequestServerTime_Implementation(float Time void ABlasterPlayerController::ClientReportServerTime_Implementation(float TimeOfClientRequest, float TimeServerReceivedClientRequest) { const float RoundTripTime = GetWorld()->GetTimeSeconds() - TimeOfClientRequest; - const float CurrentServerTime = TimeServerReceivedClientRequest + 0.5f * RoundTripTime; + const float CurrentServerTime = TimeServerReceivedClientRequest + (0.5f * RoundTripTime); ClientServerDelta = CurrentServerTime - GetWorld()->GetTimeSeconds(); } @@ -195,7 +195,7 @@ void ABlasterPlayerController::SetHUDTime() else if (MatchState == MatchState::InProgress) TimeLeft = WarmupTime + MatchTime - GetServerTime() + LevelStartingTime; else if (MatchState == MatchState::Cooldown) TimeLeft = WarmupTime + MatchTime + CooldownTime - GetServerTime() + LevelStartingTime; uint32 SecondsLeft = FMath::CeilToInt(TimeLeft); - + if (HasAuthority()) { BlasterGameMode = BlasterGameMode == nullptr ? Cast(UGameplayStatics::GetGameMode(this)) : BlasterGameMode; @@ -204,7 +204,7 @@ void ABlasterPlayerController::SetHUDTime() SecondsLeft = FMath::CeilToInt(BlasterGameMode->GetCountdownTime() + LevelStartingTime); } } - + if (CountdownInt != SecondsLeft) { if (MatchState == MatchState::WaitingToStart || MatchState == MatchState::Cooldown) SetHUDAnnouncementCountdown(TimeLeft); @@ -234,7 +234,11 @@ void ABlasterPlayerController::PollInit() void ABlasterPlayerController::SetHUDHealth(float Health, float MaxHealth) { BlasterHUD = BlasterHUD == nullptr ? Cast(GetHUD()) : BlasterHUD; - bool bHUDValid = CharacterOverlay && CharacterOverlay->HealthBar && CharacterOverlay->HealthText; + bool bHUDValid = + BlasterHUD && + BlasterHUD->CharacterOverlay && + BlasterHUD->CharacterOverlay->HealthBar && + BlasterHUD->CharacterOverlay->HealthText; if (bHUDValid) { @@ -254,7 +258,10 @@ void ABlasterPlayerController::SetHUDHealth(float Health, float MaxHealth) void ABlasterPlayerController::SetHUDScore(float Score) { BlasterHUD = BlasterHUD == nullptr ? Cast(GetHUD()) : BlasterHUD; - bool bHUDValid = CharacterOverlay && CharacterOverlay->ScoreValue; + bool bHUDValid = + BlasterHUD && + BlasterHUD->CharacterOverlay && + BlasterHUD->CharacterOverlay->ScoreValue; if (bHUDValid) { @@ -271,7 +278,10 @@ void ABlasterPlayerController::SetHUDScore(float Score) void ABlasterPlayerController::SetHUDDefeats(int32 Defeats) { BlasterHUD = BlasterHUD == nullptr ? Cast(GetHUD()) : BlasterHUD; - bool bHUDValid = CharacterOverlay && CharacterOverlay->DefeatsValue; + bool bHUDValid = + BlasterHUD && + BlasterHUD->CharacterOverlay && + BlasterHUD->CharacterOverlay->DefeatsValue; if (bHUDValid) { @@ -288,7 +298,10 @@ void ABlasterPlayerController::SetHUDDefeats(int32 Defeats) void ABlasterPlayerController::SetHUDWeaponAmmo(int32 Ammo) { BlasterHUD = BlasterHUD == nullptr ? Cast(GetHUD()) : BlasterHUD; - bool bHUDValid = CharacterOverlay && CharacterOverlay->WeaponAmmoValue; + bool bHUDValid = + BlasterHUD && + BlasterHUD->CharacterOverlay && + BlasterHUD->CharacterOverlay->WeaponAmmoValue; if (bHUDValid) { @@ -300,7 +313,10 @@ void ABlasterPlayerController::SetHUDWeaponAmmo(int32 Ammo) void ABlasterPlayerController::SetHUDCarriedAmmo(int32 Ammo) { BlasterHUD = BlasterHUD == nullptr ? Cast(GetHUD()) : BlasterHUD; - bool bHUDValid = CharacterOverlay && CharacterOverlay->CarriedAmmoValue; + bool bHUDValid = + BlasterHUD && + BlasterHUD->CharacterOverlay && + BlasterHUD->CharacterOverlay->CarriedAmmoValue; if (bHUDValid) { @@ -312,7 +328,10 @@ void ABlasterPlayerController::SetHUDCarriedAmmo(int32 Ammo) void ABlasterPlayerController::SetHUDMatchCountdown(float CountdownTime) { BlasterHUD = BlasterHUD == nullptr ? Cast(GetHUD()) : BlasterHUD; - bool bHUDValid = CharacterOverlay && CharacterOverlay->MatchCountdownText; + bool bHUDValid = + BlasterHUD && + BlasterHUD->CharacterOverlay && + BlasterHUD->CharacterOverlay->MatchCountdownText; if (bHUDValid) { @@ -335,7 +354,6 @@ void ABlasterPlayerController::SetHUDAnnouncementCountdown(float CountdownTime) bool bHUDValid = BlasterHUD && BlasterHUD->Announcement && - BlasterHUD->Announcement->AnnouncementText && BlasterHUD->Announcement->CountdownText; if (bHUDValid)