blaster/Source/Blaster/GameState/BlasterGameState.cpp

71 lines
1.9 KiB
C++
Raw Normal View History

2022-05-17 22:41:31 +00:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "BlasterGameState.h"
2022-05-30 19:52:59 +00:00
#include "Blaster/PlayerController/BlasterPlayerController.h"
2022-05-17 22:41:31 +00:00
#include "Blaster/PlayerState/BlasterPlayerState.h"
#include "Net/UnrealNetwork.h"
void ABlasterGameState::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(ABlasterGameState, TopScoringPlayers);
2022-05-30 13:48:46 +00:00
DOREPLIFETIME(ABlasterGameState, RedTeamScore);
DOREPLIFETIME(ABlasterGameState, BlueTeamScore);
2022-05-17 22:41:31 +00:00
}
void ABlasterGameState::UpdateTopScore(ABlasterPlayerState* ScoringPlayer)
{
if (TopScoringPlayers.Num() == 0)
{
TopScoringPlayers.Add(ScoringPlayer);
TopScore = ScoringPlayer->GetScore();
}
else if (ScoringPlayer->GetScore() == TopScore)
{
TopScoringPlayers.AddUnique(ScoringPlayer);
}
2022-05-29 09:59:15 +00:00
else if (ScoringPlayer->GetScore() > TopScore)
2022-05-17 22:41:31 +00:00
{
TopScoringPlayers.Empty();
TopScoringPlayers.AddUnique(ScoringPlayer);
TopScore = ScoringPlayer->GetScore();
}
}
2022-05-30 13:48:46 +00:00
2022-05-30 19:18:34 +00:00
void ABlasterGameState::RedTeamScores()
{
++RedTeamScore;
2022-05-30 19:52:59 +00:00
if (ABlasterPlayerController* BController = Cast<ABlasterPlayerController>(GetWorld()->GetFirstPlayerController()))
{
BController->SetHUDRedTeamScore(RedTeamScore);
}
2022-05-30 19:18:34 +00:00
}
void ABlasterGameState::BlueTeamScores()
{
++BlueTeamScore;
2022-05-30 19:52:59 +00:00
if (ABlasterPlayerController* BController = Cast<ABlasterPlayerController>(GetWorld()->GetFirstPlayerController()))
{
BController->SetHUDBlueTeamScore(BlueTeamScore);
}
2022-05-30 19:18:34 +00:00
}
2022-05-30 13:48:46 +00:00
void ABlasterGameState::OnRep_RedTeamScore()
{
2022-05-30 19:52:59 +00:00
if (ABlasterPlayerController* BController = Cast<ABlasterPlayerController>(GetWorld()->GetFirstPlayerController()))
{
BController->SetHUDRedTeamScore(RedTeamScore);
}
2022-05-30 13:48:46 +00:00
}
void ABlasterGameState::OnRep_BlueTeamScore()
{
2022-05-30 19:52:59 +00:00
if (ABlasterPlayerController* BController = Cast<ABlasterPlayerController>(GetWorld()->GetFirstPlayerController()))
{
BController->SetHUDBlueTeamScore(BlueTeamScore);
}
2022-05-30 13:48:46 +00:00
}