220 - Updating Team Scores

This commit is contained in:
Kingsmedia 2022-05-30 21:52:59 +02:00
parent efbb1d9269
commit 5a34578647
5 changed files with 52 additions and 18 deletions

View File

@ -72,7 +72,6 @@ void ABlasterGameMode::OnMatchStateSet()
} }
} }
float ABlasterGameMode::CalculateDamage(AController* Attacker, AController* Victim, float BaseDamage) float ABlasterGameMode::CalculateDamage(AController* Attacker, AController* Victim, float BaseDamage)
{ {
return BaseDamage; return BaseDamage;

View File

@ -4,6 +4,7 @@
#include "TeamsGameMode.h" #include "TeamsGameMode.h"
#include "Blaster/GameState/BlasterGameState.h" #include "Blaster/GameState/BlasterGameState.h"
#include "Blaster/PlayerController/BlasterPlayerController.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
ATeamsGameMode::ATeamsGameMode() ATeamsGameMode::ATeamsGameMode()
@ -82,3 +83,23 @@ float ATeamsGameMode::CalculateDamage(AController* Attacker, AController* Victim
return BaseDamage; return BaseDamage;
} }
void ATeamsGameMode::PlayerEliminated(ABlasterCharacter* EliminatedCharacter, ABlasterPlayerController* VictimController,
ABlasterPlayerController* AttackerController)
{
Super::PlayerEliminated(EliminatedCharacter, VictimController, AttackerController);
BGameState = (BGameState == nullptr) ? Cast<ABlasterGameState>(UGameplayStatics::GetGameState(this)) : BGameState;
const ABlasterPlayerState* AttackerPlayerState = AttackerController ? AttackerController->GetPlayerState<ABlasterPlayerState>() : nullptr;
if (BGameState && AttackerPlayerState)
{
if (AttackerPlayerState->GetTeam() == ETeam::ET_BlueTeam)
{
BGameState->BlueTeamScores();
}
if (AttackerPlayerState->GetTeam() == ETeam::ET_RedTeam)
{
BGameState->RedTeamScores();
}
}
}

View File

@ -19,7 +19,8 @@ public:
virtual void PostLogin(APlayerController* NewPlayer) override; virtual void PostLogin(APlayerController* NewPlayer) override;
virtual void Logout(AController* Exiting) override; virtual void Logout(AController* Exiting) override;
virtual float CalculateDamage(AController* Attacker, AController* Victim, float BaseDamage) override; virtual float CalculateDamage(AController* Attacker, AController* Victim, float BaseDamage) override;
virtual void PlayerEliminated(class ABlasterCharacter* EliminatedCharacter, class ABlasterPlayerController* VictimController,
class ABlasterPlayerController* AttackerController) override;
protected: protected:
virtual void HandleMatchHasStarted() override; virtual void HandleMatchHasStarted() override;

View File

@ -3,6 +3,7 @@
#include "BlasterGameState.h" #include "BlasterGameState.h"
#include "Blaster/PlayerController/BlasterPlayerController.h"
#include "Blaster/PlayerState/BlasterPlayerState.h" #include "Blaster/PlayerState/BlasterPlayerState.h"
#include "Net/UnrealNetwork.h" #include "Net/UnrealNetwork.h"
@ -37,19 +38,33 @@ void ABlasterGameState::UpdateTopScore(ABlasterPlayerState* ScoringPlayer)
void ABlasterGameState::RedTeamScores() void ABlasterGameState::RedTeamScores()
{ {
++RedTeamScore; ++RedTeamScore;
if (ABlasterPlayerController* BController = Cast<ABlasterPlayerController>(GetWorld()->GetFirstPlayerController()))
{
BController->SetHUDRedTeamScore(RedTeamScore);
}
} }
void ABlasterGameState::BlueTeamScores() void ABlasterGameState::BlueTeamScores()
{ {
++BlueTeamScore; ++BlueTeamScore;
if (ABlasterPlayerController* BController = Cast<ABlasterPlayerController>(GetWorld()->GetFirstPlayerController()))
{
BController->SetHUDBlueTeamScore(BlueTeamScore);
}
} }
void ABlasterGameState::OnRep_RedTeamScore() void ABlasterGameState::OnRep_RedTeamScore()
{ {
if (ABlasterPlayerController* BController = Cast<ABlasterPlayerController>(GetWorld()->GetFirstPlayerController()))
{
BController->SetHUDRedTeamScore(RedTeamScore);
}
} }
void ABlasterGameState::OnRep_BlueTeamScore() void ABlasterGameState::OnRep_BlueTeamScore()
{ {
if (ABlasterPlayerController* BController = Cast<ABlasterPlayerController>(GetWorld()->GetFirstPlayerController()))
{
BController->SetHUDBlueTeamScore(BlueTeamScore);
}
} }

View File

@ -660,7 +660,6 @@ void ABlasterPlayerController::OnRep_MatchState()
void ABlasterPlayerController::HandleMatchHasStarted(bool bTeamsMatch) void ABlasterPlayerController::HandleMatchHasStarted(bool bTeamsMatch)
{ {
if (HasAuthority()) bShowTeamScores = bTeamsMatch; if (HasAuthority()) bShowTeamScores = bTeamsMatch;
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD; BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
if (BlasterHUD) if (BlasterHUD)
{ {
@ -668,7 +667,7 @@ void ABlasterPlayerController::HandleMatchHasStarted(bool bTeamsMatch)
if (BlasterHUD->Announcement) if (BlasterHUD->Announcement)
{ {
BlasterHUD->Announcement->SetVisibility(ESlateVisibility::Hidden); BlasterHUD->Announcement->SetVisibility(ESlateVisibility::Hidden);
}
if (!HasAuthority()) return; if (!HasAuthority()) return;
if (bTeamsMatch) if (bTeamsMatch)
{ {
@ -679,7 +678,6 @@ void ABlasterPlayerController::HandleMatchHasStarted(bool bTeamsMatch)
HideTeamScores(); HideTeamScores();
} }
} }
}
} }
void ABlasterPlayerController::HandleCooldown() void ABlasterPlayerController::HandleCooldown()
@ -722,10 +720,10 @@ void ABlasterPlayerController::HandleCooldown()
} }
else if (TopPlayers.Num() > 1) else if (TopPlayers.Num() > 1)
{ {
InfoTextString = FString("Players tied for the win: \n"); InfoTextString = FString("Players tied for the win:\n");
for (auto TiedPlayers : TopPlayers) for (auto TiedPlayer : TopPlayers)
{ {
InfoTextString.Append(FString::Printf(TEXT("%s\n"), *TiedPlayers->GetPlayerName())); InfoTextString.Append(FString::Printf(TEXT("%s\n"), *TiedPlayer->GetPlayerName()));
} }
} }