127 - Restart Game

This commit is contained in:
Kingsmedia 2022-05-10 19:05:04 +02:00
parent cdca489c56
commit 68ef1dd118
3 changed files with 17 additions and 26 deletions

View File

@ -49,7 +49,7 @@ void ABlasterGameMode::Tick(float DeltaSeconds)
}
else if (MatchState == MatchState::Cooldown)
{
CountDownTime = WarmupTime + MatchTime + CooldownTime - GetWorld()->GetTimeSeconds() + LevelStartingTime;
CountDownTime = CooldownTime + WarmupTime + MatchTime - GetWorld()->GetTimeSeconds() + LevelStartingTime;
if (CountDownTime <= 0.f)
{
RestartGame();

View File

@ -73,7 +73,6 @@ void ABlasterPlayerController::CheckTimeSync(float DeltaSeconds)
float ABlasterPlayerController::GetServerTime()
{
if (HasAuthority()) return GetWorld()->GetTimeSeconds();
return GetWorld()->GetTimeSeconds() + ClientServerDelta;
}
@ -158,7 +157,6 @@ void ABlasterPlayerController::ServerCheckMatchState_Implementation()
}
}
void ABlasterPlayerController::ClientJoinMidGame_Implementation(FName StateOfMatch, float Warmup, float Match, float Cooldown, float StartingTime)
{
LevelStartingTime = StartingTime;
@ -184,7 +182,6 @@ void ABlasterPlayerController::ClientReportServerTime_Implementation(float TimeO
{
const float RoundTripTime = GetWorld()->GetTimeSeconds() - TimeOfClientRequest;
const float CurrentServerTime = TimeServerReceivedClientRequest + (0.5f * RoundTripTime);
ClientServerDelta = CurrentServerTime - GetWorld()->GetTimeSeconds();
}
@ -193,22 +190,19 @@ void ABlasterPlayerController::SetHUDTime()
float TimeLeft = 0.f;
if (MatchState == MatchState::WaitingToStart) TimeLeft = WarmupTime - GetServerTime() + LevelStartingTime;
else if (MatchState == MatchState::InProgress) TimeLeft = WarmupTime + MatchTime - GetServerTime() + LevelStartingTime;
else if (MatchState == MatchState::Cooldown) TimeLeft = WarmupTime + MatchTime + CooldownTime - GetServerTime() + LevelStartingTime;
else if (MatchState == MatchState::Cooldown) TimeLeft = CooldownTime + WarmupTime + MatchTime - GetServerTime() + LevelStartingTime;
uint32 SecondsLeft = FMath::CeilToInt(TimeLeft);
if (HasAuthority())
{
BlasterGameMode = BlasterGameMode == nullptr ? Cast<ABlasterGameMode>(UGameplayStatics::GetGameMode(this)) : BlasterGameMode;
if (BlasterGameMode)
{
SecondsLeft = FMath::CeilToInt(BlasterGameMode->GetCountdownTime() + LevelStartingTime);
}
}
if (CountdownInt != SecondsLeft)
{
if (MatchState == MatchState::WaitingToStart || MatchState == MatchState::Cooldown) SetHUDAnnouncementCountdown(TimeLeft);
if (MatchState == MatchState::InProgress) SetHUDMatchCountdown(TimeLeft);
if (MatchState == MatchState::WaitingToStart || MatchState == MatchState::Cooldown)
{
SetHUDAnnouncementCountdown(TimeLeft);
}
if (MatchState == MatchState::InProgress)
{
SetHUDMatchCountdown(TimeLeft);
}
}
CountdownInt = SecondsLeft;

View File

@ -15,7 +15,6 @@ class BLASTER_API ABlasterPlayerController : public APlayerController
GENERATED_BODY()
public:
virtual void Tick(float DeltaSeconds) override;
virtual void OnPossess(APawn* InPawn) override;
virtual void ReceivedPlayer() override; // Sync with server clock as soon as possible
@ -36,7 +35,6 @@ public:
void HandleCooldown();
protected:
virtual void BeginPlay() override;
void CheckTimeSync(float DeltaSeconds);
void HandleMatchHasStarted();
@ -54,7 +52,7 @@ protected:
void ClientReportServerTime(float TimeOfClientRequest, float TimeServerReceivedClientRequest);
// Difference between client and server time
float ClientServerDelta = 0;
float ClientServerDelta = 0.f;
UPROPERTY(EditAnywhere, Category = Time)
float TimeSyncFrequency = 5.f;
@ -66,8 +64,8 @@ protected:
UFUNCTION(Client, Reliable)
void ClientJoinMidGame(FName StateOfMatch, float Warmup, float Match, float Cooldown, float StartingTime);
private:
private:
UPROPERTY()
class ABlasterHUD* BlasterHUD;
@ -80,7 +78,7 @@ private:
float CooldownTime = 0.f;
uint32 CountdownInt = 0;
UPROPERTY(ReplicatedUsing=OnRep_MatchState)
UPROPERTY(ReplicatedUsing = OnRep_MatchState)
FName MatchState;
UFUNCTION()
@ -94,5 +92,4 @@ private:
float HUDMaxHealth;
float HUDScore;
int32 HUDDefeats;
};