// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "GameFramework/PlayerController.h" #include "BlasterPlayerController.generated.h" /** * */ UCLASS() 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 virtual void GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const override; void SetHUDHealth(float Health, float MaxHealth); void SetHUDScore(float Score); void SetHUDDefeats(int32 Defeats); void SetHUDWeaponAmmo(int32 Ammo); void SetHUDCarriedAmmo(int32 Ammo); void SetHUDMatchCountdown(float CountdownTime); void SetHUDAnnouncementCountdown(float CountdownTime); // Synced with server world clock virtual float GetServerTime(); void OnMatchStateSet(FName State); void HandleCooldown(); protected: virtual void BeginPlay() override; void CheckTimeSync(float DeltaSeconds); void HandleMatchHasStarted(); void SetHUDTime(); void PollInit(); // Sync time between client and server // Requests the current server time, passing in the client's time when the request was sent UFUNCTION(Server, Reliable) void ServerRequestServerTime(float TimeOfClientRequest); // Reports the current server time to the client in response to ServerRequestServerTime UFUNCTION(Client, Reliable) void ClientReportServerTime(float TimeOfClientRequest, float TimeServerReceivedClientRequest); // Difference between client and server time float ClientServerDelta = 0; UPROPERTY(EditAnywhere, Category = Time) float TimeSyncFrequency = 5.f; float TimeSyncRunningTime = 0.f; UFUNCTION(Server, Reliable) void ServerCheckMatchState(); UFUNCTION(Client, Reliable) void ClientJoinMidGame(FName StateOfMatch, float Warmup, float Match, float StartingTime); private: UPROPERTY() class ABlasterHUD* BlasterHUD; float LevelStartingTime = 0.f; float MatchTime = 0.f; float WarmupTime = 0.f; uint32 CountdownInt = 0; UPROPERTY(ReplicatedUsing=OnRep_MatchState) FName MatchState; UFUNCTION() void OnRep_MatchState(); UPROPERTY() class UCharacterOverlay* CharacterOverlay; bool bInitializeCharacterOverlay = false; float HUDHealth; float HUDMaxHealth; float HUDScore; int32 HUDDefeats; };