blaster/Source/Blaster/PlayerController/BlasterPlayerController.cpp

587 lines
18 KiB
C++
Raw Normal View History

2022-05-05 15:57:57 +00:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "BlasterPlayerController.h"
2022-05-08 19:16:19 +00:00
#include "Blaster/Character/BlasterCharacter.h"
2022-05-10 14:03:35 +00:00
#include "Blaster/Components/CombatComponent.h"
2022-05-10 12:23:23 +00:00
#include "Blaster/GameMode/BlasterGameMode.h"
2022-05-17 22:41:31 +00:00
#include "Blaster/GameState/BlasterGameState.h"
2022-05-10 11:31:39 +00:00
#include "Blaster/HUD/Announcement.h"
2022-05-07 10:03:33 +00:00
#include "Blaster/HUD/BlasterHUD.h"
#include "Blaster/HUD/CharacterOverlay.h"
2022-05-12 15:05:30 +00:00
#include "Blaster/HUD/DebugWidget.h"
2022-05-17 22:41:31 +00:00
#include "Blaster/PlayerState/BlasterPlayerState.h"
2022-05-07 10:03:33 +00:00
#include "Components/ProgressBar.h"
#include "Components/TextBlock.h"
2022-05-10 10:42:09 +00:00
#include "GameFramework/GameMode.h"
2022-05-10 12:23:23 +00:00
#include "Kismet/GameplayStatics.h"
2022-05-10 10:42:09 +00:00
#include "Net/UnrealNetwork.h"
2022-05-07 10:03:33 +00:00
void ABlasterPlayerController::BeginPlay()
{
Super::BeginPlay();
2022-05-10 13:29:00 +00:00
2022-05-07 10:03:33 +00:00
BlasterHUD = Cast<ABlasterHUD>(GetHUD());
2022-05-10 12:23:23 +00:00
ServerCheckMatchState();
2022-05-07 10:03:33 +00:00
}
2022-05-10 10:42:09 +00:00
void ABlasterPlayerController::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(ABlasterPlayerController, MatchState);
}
2022-05-26 11:06:33 +00:00
void ABlasterPlayerController::SetDebugMsg1(FString Key, FString Value)
{
bool bHUDValid = BlasterHUD && BlasterHUD->DebugWidget && BlasterHUD->DebugWidget->DebugMsg1;
if (bHUDValid) BlasterHUD->DebugWidget->DebugMsg1->SetText(FText::FromString(Key.Append(Value)));
}
2022-05-12 13:37:49 +00:00
void ABlasterPlayerController::Tick(float DeltaTime)
2022-05-10 08:40:23 +00:00
{
2022-05-12 13:37:49 +00:00
Super::Tick(DeltaTime);
2022-05-10 13:29:00 +00:00
2022-05-10 08:40:23 +00:00
SetHUDTime();
2022-05-12 13:37:49 +00:00
CheckTimeSync(DeltaTime);
2022-05-10 12:23:23 +00:00
PollInit();
2022-05-26 11:06:33 +00:00
CheckPing(DeltaTime);
2022-05-12 15:05:30 +00:00
if (DebugWidget)
{
SetDebugMsg1(TEXT("GetWorld()->GetTimeSeconds(): "), FString::Printf(TEXT("%02f"), GetWorld()->GetTimeSeconds()));
SetDebugMsg2(TEXT("GetServerTime(): "), FString::Printf(TEXT("%02f"), GetServerTime()));
SetDebugMsg3(TEXT("ClientServerDelta: "), FString::Printf(TEXT("%f"), ClientServerDelta));
SetDebugMsg4(TEXT("LevelStartingTime: "), FString::Printf(TEXT("%f"), LevelStartingTime));
SetDebugMsg5(TEXT("CountdownInt: "), FString::Printf(TEXT("%d"), CountdownInt));
2022-05-12 15:05:30 +00:00
}
}
2022-05-26 11:06:33 +00:00
void ABlasterPlayerController::CheckPing(float DeltaTime)
2022-05-12 15:05:30 +00:00
{
2022-05-26 11:06:33 +00:00
HighPingRunningTime += DeltaTime;
if (HighPingRunningTime > CheckPingFrequency)
{
HighPingRunningTime = 0.f;
PlayerState = PlayerState == nullptr ? GetPlayerState<APlayerState>() : PlayerState;
if (PlayerState)
{
UE_LOG(LogTemp, Warning, TEXT("Ping: %f"), PlayerState->GetPingInMilliseconds());
if (PlayerState->GetPingInMilliseconds() > HighPingThreshold)
{
HighPingWarning();
PingAnimationRunningTime = 0.f;
}
}
}
bool bHighPingAnimationPlaying =
BlasterHUD &&
BlasterHUD->CharacterOverlay &&
BlasterHUD->CharacterOverlay->HighPingAnimation &&
BlasterHUD->CharacterOverlay->IsAnimationPlaying(BlasterHUD->CharacterOverlay->HighPingAnimation);
if (bHighPingAnimationPlaying)
{
PingAnimationRunningTime += DeltaTime;
if (PingAnimationRunningTime > HighPingDuration)
{
StopHighPingWarning();
}
}
2022-05-12 15:05:30 +00:00
}
2022-05-26 11:06:33 +00:00
2022-05-12 15:05:30 +00:00
void ABlasterPlayerController::SetDebugMsg2(FString Key, FString Value)
{
bool bHUDValid = BlasterHUD && BlasterHUD->DebugWidget && BlasterHUD->DebugWidget->DebugMsg2;
if (bHUDValid) BlasterHUD->DebugWidget->DebugMsg2->SetText(FText::FromString(Key.Append(Value)));
}
void ABlasterPlayerController::SetDebugMsg3(FString Key, FString Value)
{
bool bHUDValid = BlasterHUD && BlasterHUD->DebugWidget && BlasterHUD->DebugWidget->DebugMsg3;
if (bHUDValid) BlasterHUD->DebugWidget->DebugMsg3->SetText(FText::FromString(Key.Append(Value)));
}
void ABlasterPlayerController::SetDebugMsg4(FString Key, FString Value)
{
bool bHUDValid = BlasterHUD && BlasterHUD->DebugWidget && BlasterHUD->DebugWidget->DebugMsg4;
if (bHUDValid) BlasterHUD->DebugWidget->DebugMsg4->SetText(FText::FromString(Key.Append(Value)));
}
void ABlasterPlayerController::SetDebugMsg5(FString Key, FString Value)
{
bool bHUDValid = BlasterHUD && BlasterHUD->DebugWidget && BlasterHUD->DebugWidget->DebugMsg5;
if (bHUDValid) BlasterHUD->DebugWidget->DebugMsg5->SetText(FText::FromString(Key.Append(Value)));
}
void ABlasterPlayerController::SetDebugMsg6(FString Key, FString Value)
{
bool bHUDValid = BlasterHUD && BlasterHUD->DebugWidget && BlasterHUD->DebugWidget->DebugMsg6;
if (bHUDValid) BlasterHUD->DebugWidget->DebugMsg6->SetText(FText::FromString(Key.Append(Value)));
}
void ABlasterPlayerController::SetDebugMsg7(FString Key, FString Value)
{
bool bHUDValid = BlasterHUD && BlasterHUD->DebugWidget && BlasterHUD->DebugWidget->DebugMsg7;
if (bHUDValid) BlasterHUD->DebugWidget->DebugMsg7->SetText(FText::FromString(Key.Append(Value)));
2022-05-10 08:40:23 +00:00
}
2022-05-12 13:37:49 +00:00
void ABlasterPlayerController::CheckTimeSync(float DeltaTime)
2022-05-08 19:16:19 +00:00
{
2022-05-12 13:37:49 +00:00
TimeSyncRunningTime += DeltaTime;
if (IsLocalController() && TimeSyncRunningTime > TimeSyncFrequency)
2022-05-08 19:16:19 +00:00
{
2022-05-12 13:37:49 +00:00
ServerRequestServerTime(GetWorld()->GetTimeSeconds());
TimeSyncRunningTime = 0.f;
2022-05-08 19:16:19 +00:00
}
}
2022-05-12 13:37:49 +00:00
void ABlasterPlayerController::ServerCheckMatchState_Implementation()
2022-05-10 09:14:54 +00:00
{
2022-05-12 13:37:49 +00:00
ABlasterGameMode* GameMode = Cast<ABlasterGameMode>(UGameplayStatics::GetGameMode(this));
if (GameMode)
2022-05-10 09:14:54 +00:00
{
2022-05-12 13:37:49 +00:00
WarmupTime = GameMode->WarmupTime;
MatchTime = GameMode->MatchTime;
CooldownTime = GameMode->CooldownTime;
LevelStartingTime = GameMode->LevelStartingTime;
MatchState = GameMode->GetMatchState();
ClientJoinMidgame(MatchState, WarmupTime, MatchTime, CooldownTime, LevelStartingTime);
2022-05-10 09:14:54 +00:00
}
}
2022-05-12 13:37:49 +00:00
void ABlasterPlayerController::ClientJoinMidgame_Implementation(FName StateOfMatch, float Warmup, float Match, float Cooldown, float StartingTime)
2022-05-10 09:14:54 +00:00
{
2022-05-12 13:37:49 +00:00
WarmupTime = Warmup;
MatchTime = Match;
CooldownTime = Cooldown;
LevelStartingTime = StartingTime;
MatchState = StateOfMatch;
OnMatchStateSet(MatchState);
if (BlasterHUD && MatchState == MatchState::WaitingToStart)
2022-05-10 09:14:54 +00:00
{
2022-05-12 13:37:49 +00:00
BlasterHUD->AddAnnouncementOverlay();
2022-05-10 09:14:54 +00:00
}
}
2022-05-12 13:37:49 +00:00
void ABlasterPlayerController::OnPossess(APawn* InPawn)
2022-05-10 11:31:39 +00:00
{
2022-05-12 13:37:49 +00:00
Super::OnPossess(InPawn);
ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(InPawn);
if (BlasterCharacter)
2022-05-10 11:31:39 +00:00
{
2022-05-12 13:37:49 +00:00
SetHUDHealth(BlasterCharacter->GetHealth(), BlasterCharacter->GetMaxHealth());
2022-05-10 11:31:39 +00:00
}
}
2022-05-12 13:37:49 +00:00
void ABlasterPlayerController::SetHUDHealth(float Health, float MaxHealth)
2022-05-10 12:55:02 +00:00
{
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
2022-05-12 13:37:49 +00:00
bool bHUDValid = BlasterHUD &&
BlasterHUD->CharacterOverlay &&
BlasterHUD->CharacterOverlay->HealthBar &&
BlasterHUD->CharacterOverlay->HealthText;
if (bHUDValid)
2022-05-10 12:55:02 +00:00
{
2022-05-12 13:37:49 +00:00
const float HealthPercent = Health / MaxHealth;
BlasterHUD->CharacterOverlay->HealthBar->SetPercent(HealthPercent);
FString HealthText = FString::Printf(TEXT("%d/%d"), FMath::CeilToInt(Health), FMath::CeilToInt(MaxHealth));
BlasterHUD->CharacterOverlay->HealthText->SetText(FText::FromString(HealthText));
2022-05-10 12:55:02 +00:00
}
2022-05-12 13:37:49 +00:00
else
2022-05-10 14:03:35 +00:00
{
2022-05-23 09:47:49 +00:00
bInitializeHealth = true;
2022-05-12 13:37:49 +00:00
HUDHealth = Health;
HUDMaxHealth = MaxHealth;
2022-05-10 14:03:35 +00:00
}
2022-05-10 12:55:02 +00:00
}
2022-05-23 09:27:12 +00:00
void ABlasterPlayerController::SetHUDShield(float Shield, float MaxShield)
{
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
bool bHUDValid = BlasterHUD &&
BlasterHUD->CharacterOverlay &&
BlasterHUD->CharacterOverlay->ShieldBar &&
BlasterHUD->CharacterOverlay->ShieldText;
if (bHUDValid)
{
const float ShieldPercent = Shield / MaxShield;
BlasterHUD->CharacterOverlay->ShieldBar->SetPercent(ShieldPercent);
FString ShieldText = FString::Printf(TEXT("%d/%d"), FMath::CeilToInt(Shield), FMath::CeilToInt(MaxShield));
BlasterHUD->CharacterOverlay->ShieldText->SetText(FText::FromString(ShieldText));
}
else
{
2022-05-23 09:47:49 +00:00
bInitializeShield = true;
2022-05-23 09:27:12 +00:00
HUDShield = Shield;
HUDMaxShield = MaxShield;
}
}
2022-05-12 13:37:49 +00:00
void ABlasterPlayerController::SetHUDScore(float Score)
2022-05-10 10:42:09 +00:00
{
2022-05-12 13:37:49 +00:00
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
bool bHUDValid = BlasterHUD &&
BlasterHUD->CharacterOverlay &&
BlasterHUD->CharacterOverlay->ScoreValue;
2022-05-10 10:42:09 +00:00
2022-05-12 13:37:49 +00:00
if (bHUDValid)
2022-05-10 10:42:09 +00:00
{
2022-05-12 13:37:49 +00:00
FString ScoreText = FString::Printf(TEXT("%d"), FMath::FloorToInt(Score));
BlasterHUD->CharacterOverlay->ScoreValue->SetText(FText::FromString(ScoreText));
2022-05-10 10:42:09 +00:00
}
2022-05-12 13:37:49 +00:00
else
2022-05-10 12:55:02 +00:00
{
2022-05-23 09:47:49 +00:00
bInitializeScore = true;
2022-05-12 13:37:49 +00:00
HUDScore = Score;
2022-05-10 12:55:02 +00:00
}
2022-05-10 10:42:09 +00:00
}
2022-05-12 13:37:49 +00:00
void ABlasterPlayerController::SetHUDDefeats(int32 Defeats)
2022-05-10 10:42:09 +00:00
{
2022-05-12 13:37:49 +00:00
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
bool bHUDValid = BlasterHUD &&
BlasterHUD->CharacterOverlay &&
BlasterHUD->CharacterOverlay->DefeatsValue;
if (bHUDValid)
2022-05-10 10:42:09 +00:00
{
2022-05-12 13:37:49 +00:00
FString DefeatsText = FString::Printf(TEXT("%d"), Defeats);
BlasterHUD->CharacterOverlay->DefeatsValue->SetText(FText::FromString(DefeatsText));
2022-05-10 10:42:09 +00:00
}
2022-05-12 13:37:49 +00:00
else
2022-05-10 12:55:02 +00:00
{
2022-05-23 09:47:49 +00:00
bInitializeDefeats = true;
2022-05-12 13:37:49 +00:00
HUDDefeats = Defeats;
2022-05-10 12:55:02 +00:00
}
2022-05-10 10:42:09 +00:00
}
2022-05-12 13:37:49 +00:00
void ABlasterPlayerController::SetHUDWeaponAmmo(int32 Ammo)
2022-05-10 12:23:23 +00:00
{
2022-05-12 13:37:49 +00:00
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
bool bHUDValid = BlasterHUD &&
BlasterHUD->CharacterOverlay &&
BlasterHUD->CharacterOverlay->WeaponAmmoValue;
if (bHUDValid)
2022-05-10 12:23:23 +00:00
{
2022-05-12 13:37:49 +00:00
FString AmmoText = FString::Printf(TEXT("%d"), Ammo);
BlasterHUD->CharacterOverlay->WeaponAmmoValue->SetText(FText::FromString(AmmoText));
2022-05-10 12:23:23 +00:00
}
2022-05-23 23:16:06 +00:00
else
{
bInitializeHUDWeaponAmmo = true;
HUDWeaponAmmo = Ammo;
}
2022-05-10 12:23:23 +00:00
}
2022-05-12 13:37:49 +00:00
void ABlasterPlayerController::SetHUDCarriedAmmo(int32 Ammo)
2022-05-10 12:23:23 +00:00
{
2022-05-12 13:37:49 +00:00
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
bool bHUDValid = BlasterHUD &&
BlasterHUD->CharacterOverlay &&
BlasterHUD->CharacterOverlay->CarriedAmmoValue;
if (bHUDValid)
2022-05-10 12:23:23 +00:00
{
2022-05-12 13:37:49 +00:00
FString AmmoText = FString::Printf(TEXT("%d"), Ammo);
BlasterHUD->CharacterOverlay->CarriedAmmoValue->SetText(FText::FromString(AmmoText));
2022-05-10 12:23:23 +00:00
}
2022-05-23 23:16:06 +00:00
else
{
bInitializeCarriedAmmo = true;
HUDCarriedAmmo = Ammo;
}
2022-05-10 12:23:23 +00:00
}
2022-05-22 13:21:17 +00:00
void ABlasterPlayerController::SetHUDGrenades(int32 Grenades)
{
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
bool bHUDValid = BlasterHUD &&
BlasterHUD->CharacterOverlay &&
BlasterHUD->CharacterOverlay->GrenadesAmount;
if (bHUDValid)
{
FString GrenadesText = FString::Printf(TEXT("%d"), Grenades);
BlasterHUD->CharacterOverlay->GrenadesAmount->SetText(FText::FromString(GrenadesText));
2022-05-26 11:06:33 +00:00
}
else
2022-05-22 13:21:17 +00:00
{
2022-05-23 09:47:49 +00:00
bInitializeGrenades = true;
2022-05-22 13:21:17 +00:00
HUDGrenades = Grenades;
}
}
2022-05-12 13:37:49 +00:00
void ABlasterPlayerController::SetHUDMatchCountdown(float CountdownTime)
2022-05-10 09:14:54 +00:00
{
2022-05-12 13:37:49 +00:00
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
bool bHUDValid = BlasterHUD &&
BlasterHUD->CharacterOverlay &&
BlasterHUD->CharacterOverlay->MatchCountdownText;
if (bHUDValid)
{
if (CountdownTime < 0.f)
{
BlasterHUD->CharacterOverlay->MatchCountdownText->SetText(FText());
return;
}
int32 Minutes = FMath::FloorToInt(CountdownTime / 60.f);
int32 Seconds = CountdownTime - Minutes * 60;
FString CountdownText = FString::Printf(TEXT("%02d:%02d"), Minutes, Seconds);
BlasterHUD->CharacterOverlay->MatchCountdownText->SetText(FText::FromString(CountdownText));
}
2022-05-10 09:14:54 +00:00
}
2022-05-12 13:37:49 +00:00
void ABlasterPlayerController::SetHUDAnnouncementCountdown(float CountdownTime)
2022-05-10 09:14:54 +00:00
{
2022-05-12 13:37:49 +00:00
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
bool bHUDValid = BlasterHUD &&
BlasterHUD->Announcement &&
BlasterHUD->Announcement->CountdownText;
if (bHUDValid)
{
if (CountdownTime < 0.f)
{
BlasterHUD->Announcement->CountdownText->SetText(FText());
return;
}
2022-05-10 09:14:54 +00:00
2022-05-12 13:37:49 +00:00
int32 Minutes = FMath::FloorToInt(CountdownTime / 60.f);
int32 Seconds = CountdownTime - Minutes * 60;
FString CountdownText = FString::Printf(TEXT("%02d:%02d"), Minutes, Seconds);
BlasterHUD->Announcement->CountdownText->SetText(FText::FromString(CountdownText));
}
2022-05-10 09:14:54 +00:00
}
2022-05-10 08:40:23 +00:00
void ABlasterPlayerController::SetHUDTime()
{
2022-05-10 12:23:23 +00:00
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;
2022-05-26 11:06:33 +00:00
2022-05-10 13:29:00 +00:00
uint32 SecondsLeft = FMath::CeilToInt(TimeLeft);
2022-05-26 11:06:33 +00:00
2022-05-10 13:29:00 +00:00
if (HasAuthority())
{
BlasterGameMode = BlasterGameMode == nullptr ? Cast<ABlasterGameMode>(UGameplayStatics::GetGameMode(this)) : BlasterGameMode;
if (BlasterGameMode)
{
SecondsLeft = FMath::CeilToInt(BlasterGameMode->GetCountdownTime());
2022-05-10 13:29:00 +00:00
}
}
2022-05-26 11:06:33 +00:00
2022-05-10 08:40:23 +00:00
if (CountdownInt != SecondsLeft)
{
2022-05-12 13:37:49 +00:00
if (MatchState == MatchState::WaitingToStart || MatchState == MatchState::Cooldown)
{
SetHUDAnnouncementCountdown(TimeLeft);
}
if (MatchState == MatchState::InProgress)
{
SetHUDMatchCountdown(TimeLeft);
}
2022-05-10 08:40:23 +00:00
}
2022-05-10 09:14:54 +00:00
2022-05-10 08:40:23 +00:00
CountdownInt = SecondsLeft;
}
2022-05-10 10:42:09 +00:00
void ABlasterPlayerController::PollInit()
{
2022-05-17 22:41:31 +00:00
/*
if (BlasterHUD && BlasterHUD->DebugWidget == nullptr)
2022-05-12 15:05:30 +00:00
{
BlasterHUD->AddDebugWidget();
if (BlasterHUD->DebugWidget)
2022-05-12 15:05:30 +00:00
{
DebugWidget = BlasterHUD->DebugWidget;
}
}
2022-05-17 22:41:31 +00:00
*/
2022-05-10 10:42:09 +00:00
if (CharacterOverlay == nullptr)
{
if (BlasterHUD && BlasterHUD->CharacterOverlay)
{
CharacterOverlay = BlasterHUD->CharacterOverlay;
if (CharacterOverlay)
{
2022-05-23 09:47:49 +00:00
if (bInitializeHealth) SetHUDHealth(HUDHealth, HUDMaxHealth);
if (bInitializeShield) SetHUDShield(HUDShield, HUDMaxShield);
if (bInitializeScore) SetHUDScore(HUDScore);
if (bInitializeDefeats) SetHUDDefeats(HUDDefeats);
2022-05-23 23:16:06 +00:00
if (bInitializeCarriedAmmo) SetHUDCarriedAmmo(HUDCarriedAmmo);
if (bInitializeHUDWeaponAmmo) SetHUDWeaponAmmo(HUDWeaponAmmo);
2022-05-22 13:21:17 +00:00
ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(GetPawn());
if (BlasterCharacter && BlasterCharacter->GetCombat())
{
2022-05-23 09:47:49 +00:00
if (bInitializeGrenades) SetHUDGrenades(BlasterCharacter->GetCombat()->GetGrenades());
2022-05-22 13:21:17 +00:00
}
2022-05-10 10:42:09 +00:00
}
}
}
}
2022-05-26 11:06:33 +00:00
void ABlasterPlayerController::HighPingWarning()
{
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
bool bHUDValid = BlasterHUD &&
BlasterHUD->CharacterOverlay &&
BlasterHUD->CharacterOverlay->HighPingImage &&
BlasterHUD->CharacterOverlay->HighPingAnimation;
if (bHUDValid)
{
BlasterHUD->CharacterOverlay->HighPingImage->SetOpacity(1.f);
BlasterHUD->CharacterOverlay->PlayAnimation(BlasterHUD->CharacterOverlay->HighPingAnimation, 0.f, 5);
}
}
void ABlasterPlayerController::StopHighPingWarning()
{
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
bool bHUDValid = BlasterHUD &&
BlasterHUD->CharacterOverlay &&
BlasterHUD->CharacterOverlay->HighPingImage &&
BlasterHUD->CharacterOverlay->HighPingAnimation;
if (bHUDValid)
{
BlasterHUD->CharacterOverlay->HighPingImage->SetOpacity(0.f);
if (BlasterHUD->CharacterOverlay->IsAnimationPlaying(BlasterHUD->CharacterOverlay->HighPingAnimation))
{
BlasterHUD->CharacterOverlay->StopAnimation(BlasterHUD->CharacterOverlay->HighPingAnimation);
}
}
}
2022-05-12 13:37:49 +00:00
void ABlasterPlayerController::ServerRequestServerTime_Implementation(float TimeOfClientRequest)
2022-05-07 10:03:33 +00:00
{
2022-05-12 13:37:49 +00:00
float ServerTimeOfReceipt = GetWorld()->GetTimeSeconds();
ClientReportServerTime(TimeOfClientRequest, ServerTimeOfReceipt);
}
2022-05-10 09:14:54 +00:00
2022-05-12 13:37:49 +00:00
void ABlasterPlayerController::ClientReportServerTime_Implementation(float TimeOfClientRequest, float TimeServerReceivedClientRequest)
{
float RoundTripTime = GetWorld()->GetTimeSeconds() - TimeOfClientRequest;
float CurrentServerTime = TimeServerReceivedClientRequest + 0.5f * RoundTripTime;
ClientServerDelta = CurrentServerTime - GetWorld()->GetTimeSeconds();
2022-05-07 10:03:33 +00:00
}
2022-05-09 14:33:48 +00:00
2022-05-12 13:37:49 +00:00
float ABlasterPlayerController::GetServerTime()
2022-05-09 14:33:48 +00:00
{
2022-05-12 13:37:49 +00:00
if (HasAuthority()) return GetWorld()->GetTimeSeconds();
return GetWorld()->GetTimeSeconds() + ClientServerDelta;
}
2022-05-09 14:33:48 +00:00
2022-05-12 13:37:49 +00:00
void ABlasterPlayerController::ReceivedPlayer()
{
Super::ReceivedPlayer();
if (IsLocalController())
2022-05-10 10:42:09 +00:00
{
2022-05-12 13:37:49 +00:00
ServerRequestServerTime(GetWorld()->GetTimeSeconds());
2022-05-10 10:42:09 +00:00
}
2022-05-09 15:16:41 +00:00
}
2022-05-12 13:37:49 +00:00
void ABlasterPlayerController::OnMatchStateSet(FName State)
2022-05-09 15:16:41 +00:00
{
2022-05-12 13:37:49 +00:00
MatchState = State;
2022-05-09 15:16:41 +00:00
2022-05-12 13:37:49 +00:00
if (MatchState == MatchState::InProgress)
2022-05-09 15:16:41 +00:00
{
2022-05-12 13:37:49 +00:00
HandleMatchHasStarted();
2022-05-09 14:33:48 +00:00
}
2022-05-12 13:37:49 +00:00
else if (MatchState == MatchState::Cooldown)
2022-05-10 10:42:09 +00:00
{
2022-05-12 13:37:49 +00:00
HandleCooldown();
2022-05-10 10:42:09 +00:00
}
2022-05-09 14:33:48 +00:00
}
2022-05-09 16:39:41 +00:00
2022-05-12 13:37:49 +00:00
void ABlasterPlayerController::OnRep_MatchState()
2022-05-09 16:39:41 +00:00
{
2022-05-12 13:37:49 +00:00
if (MatchState == MatchState::InProgress)
2022-05-09 16:39:41 +00:00
{
2022-05-12 13:37:49 +00:00
HandleMatchHasStarted();
2022-05-09 16:39:41 +00:00
}
2022-05-12 13:37:49 +00:00
else if (MatchState == MatchState::Cooldown)
2022-05-09 17:35:28 +00:00
{
2022-05-12 13:37:49 +00:00
HandleCooldown();
2022-05-09 17:35:28 +00:00
}
}
2022-05-10 08:40:23 +00:00
2022-05-12 13:37:49 +00:00
void ABlasterPlayerController::HandleMatchHasStarted()
2022-05-10 08:40:23 +00:00
{
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
2022-05-12 13:37:49 +00:00
if (BlasterHUD)
2022-05-10 08:40:23 +00:00
{
2022-05-18 12:44:39 +00:00
if (BlasterHUD->CharacterOverlay == nullptr) BlasterHUD->AddCharacterOverlay();
2022-05-12 13:37:49 +00:00
if (BlasterHUD->Announcement)
2022-05-10 13:29:00 +00:00
{
2022-05-12 13:37:49 +00:00
BlasterHUD->Announcement->SetVisibility(ESlateVisibility::Hidden);
2022-05-10 13:29:00 +00:00
}
2022-05-10 08:40:23 +00:00
}
}
2022-05-10 12:23:23 +00:00
2022-05-12 13:37:49 +00:00
void ABlasterPlayerController::HandleCooldown()
2022-05-10 12:23:23 +00:00
{
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
2022-05-12 13:37:49 +00:00
if (BlasterHUD)
2022-05-10 12:23:23 +00:00
{
if (BlasterHUD->CharacterOverlay)
{
BlasterHUD->CharacterOverlay->RemoveFromParent();
}
2022-05-26 11:06:33 +00:00
bool bHUDValid = BlasterHUD->Announcement &&
2022-05-12 13:37:49 +00:00
BlasterHUD->Announcement->AnnouncementText &&
BlasterHUD->Announcement->AnnouncementMessage;
if (bHUDValid)
2022-05-10 13:29:00 +00:00
{
2022-05-12 13:37:49 +00:00
BlasterHUD->Announcement->SetVisibility(ESlateVisibility::Visible);
FString AnnouncementText("New match starts in:");
BlasterHUD->Announcement->AnnouncementText->SetText(FText::FromString(AnnouncementText));
2022-05-17 22:41:31 +00:00
ABlasterGameState* BlasterGameState = Cast<ABlasterGameState>(UGameplayStatics::GetGameState(this));
ABlasterPlayerState* BlasterPlayerState = GetPlayerState<ABlasterPlayerState>();
if (BlasterGameState && BlasterPlayerState)
{
TArray<ABlasterPlayerState*> TopPlayers = BlasterGameState->TopScoringPlayers;
FString InfoTextString;
if (TopPlayers.Num() == 0)
{
InfoTextString = FString("There is no winner.");
}
else if (TopPlayers.Num() == 1 && TopPlayers[0] == BlasterPlayerState)
{
InfoTextString = FString("You are the winner!");
}
else if (TopPlayers.Num() == 1)
{
InfoTextString = FString::Printf(TEXT("%s won!"), *TopPlayers[0]->GetPlayerName());
}
else if (TopPlayers.Num() > 1)
{
InfoTextString = FString("Players tied for the win: \n");
for (auto TiedPlayers : TopPlayers)
{
InfoTextString.Append(FString::Printf(TEXT("%s\n"), *TiedPlayers->GetPlayerName()));
}
}
BlasterHUD->Announcement->AnnouncementMessage->SetText(FText::FromString(InfoTextString));
}
2022-05-10 13:29:00 +00:00
}
2022-05-12 13:37:49 +00:00
}
ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(GetPawn());
if (BlasterCharacter && BlasterCharacter->GetCombat())
{
BlasterCharacter->bDisableGameplay = true;
BlasterCharacter->GetCombat()->FireButtonPressed(false);
2022-05-10 12:23:23 +00:00
}
}